Skip to content

Instantly share code, notes, and snippets.

@effigies
Last active April 27, 2017 16:32
Show Gist options
  • Save effigies/84df98fd5df78600ad1335923cbf35fa to your computer and use it in GitHub Desktop.
Save effigies/84df98fd5df78600ad1335923cbf35fa to your computer and use it in GitHub Desktop.
Traitlet extension draft
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