Skip to content

Pickling or copying dynamic traits makes them loose their type and metadata. #2

@chrisgorgo

Description

@chrisgorgo

pickling

a = HasTraits()
a.add_trait('foo', File(exists=True))
a.foo = Undefined

print a.traits()
print a.traits()['foo'].trait_type

inp = pickle.dumps(a, -1)
b = pickle.loads(inp)


print b.traits()
print b.traits()['foo'].trait_type

b.foo = 'idonotexist'
a.foo = 'idonotexist'

copying

In [68]: a = HasTraits()

In [69]: a.add_trait('foo', File(exists=True))

In [70]: a.foo = Undefined

In [71]: a.traits()['foo'].trait_type
Out[71]: <enthought.traits.trait_types.File object at 0x104809650>

In [72]: b = deepcopy(a)

In [73]: b.traits()['foo'].trait_type
Out[73]: <enthought.traits.trait_types.Python object at 0x10272b950>

In [74]: b.foo = 'idonotexist'

In [75]: a.foo = 'idonotexist'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions