Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions traitlets/tests/test_traitlets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2598,7 +2598,7 @@ class C(HasTraits):
a = Unicode('hard default')
def _a_default(self):
return 'default method'

C._a_default = lambda self: 'overridden'
c = C()
assert c.a == 'overridden'
Expand All @@ -2609,7 +2609,7 @@ class C(HasTraits):
@default('a')
def _a_default(self):
return 'default method'

C._a_default = lambda self: 'overridden'
c = C()
assert c.a == 'overridden'
Expand All @@ -2620,8 +2620,21 @@ class C(HasTraits):
@default('a')
def _a_default(self):
return 'default method'

c = C()
c._a_default = lambda self: 'overridden'
assert c.a == 'overridden'

def test_copy_HasTraits():
from copy import copy

class C(HasTraits):
a = Int()

c = C(a=1)
assert c.a == 1

cc = copy(c)
cc.a = 2
assert cc.a == 2
assert c.a == 1
3 changes: 3 additions & 0 deletions traitlets/traitlets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,9 @@ def __getstate__(self):
# recall of instance_init during __setstate__
d['_trait_notifiers'] = {}
d['_trait_validators'] = {}
d['_trait_values'] = self._trait_values.copy()
d['_cross_validation_lock'] = False # FIXME: raise if cloning locked!

return d

def __setstate__(self, state):
Expand Down
9 changes: 7 additions & 2 deletions traitlets/utils/sentinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.


class Sentinel(object):

def __init__(self, name, module, docstring=None):
Expand All @@ -11,7 +12,11 @@ def __init__(self, name, module, docstring=None):
if docstring:
self.__doc__ = docstring


def __repr__(self):
return str(self.module)+'.'+self.name
return str(self.module) + '.' + self.name

def __copy__(self):
return self

def __deepcopy__(self, memo):
return self