Last active
April 27, 2017 16:32
Traitlet extension draft
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import traitlets | |
class _Undefined(object): | |
obj = None | |
def __new__(cls): | |
if cls.obj is None: | |
cls.obj = object.__new__(cls) | |
return cls.obj | |
class _UseDefault(_Undefined): | |
obj = None | |
Undefined = _Undefined() | |
UseDefault = _UseDefault() | |
class Disallow(traitlets.TraitType): | |
def validate(self, obj, val): | |
self.error(obj, val) | |
class UndefMixin(object): | |
def __init__(self, default_value=Undefined, *args, **kwargs): | |
return super(UndefMixin, self).__init__(default_value, *args, **kwargs) | |
def _validate(self, obj, val): | |
if isinstance(val, _Undefined): | |
return val | |
return super(UndefMixin, self)._validate(obj, val) | |
class Float(UndefMixin, traitlets.Float): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment