`AdaptsTo` and `Supports` don't store default values correctly
- Dominant language
- Python
- Stars
- 462
- Forks
- 90
- PR merge metrics
- No merged PRs in 30d
Description
When running the following code:
``` python
from traits.api import AdaptsTo, HasTraits, Instance, Interface, Supports, register_factory
class ITestInterface(Interface):
pass
class MyClass(HasTraits):
pass
class MyClassTestInterfaceAdapter(HasTraits):
object = Instance(MyClass)
def __init__(self, object):
super().__init__(self, object=object)
class MyClassTestInterfaceAdapter(HasTraits):
object = Instance(MyClass)
def __init__(self, object):
super().__init__(object=object)
register_factory(MyClassTestInterfaceAdapter, MyClass, ITestInterface)
class TestAdaptTraits(HasTraits):
supports = Supports(ITestInterface, MyClass, (), {})
adapts_to = AdaptsTo(ITestInterface, MyClass, (), {})
t = TestAdaptTraits()
print('default t.supports:', t.supports)
print('default t.supports_:', t.supports_)
t.supports = MyClass()
print('set t.supports:', t.supports)
print('set t.supports_:', t.supports_)
print('default t.adapts_to:', t.adapts_to)
print('default t.adapts_to_:', t.adapts_to_)
t.adapts_to = MyClass()
print('set t.adapts_to:', t.adapts_to)
print('set t.adapts_to_:', t.adapts_to_)
```
we get output
```
default t.supports: <__main__.MyClass object at 0x7fd61a97e620>
default t.supports_: <__main__.MyClass object at 0x7fd61a97e620>
set t.supports: <__main__.MyClassTestInterfaceAdapter object at 0x7fd61a97e6d0>
set t.supports_: <__main__.MyClass object at 0x7fd61a97e678>
default t.adapts_to: <__main__.MyClass object at 0x7fd61a97e620>
default t.adapts_to_: <__main__.MyClass object at 0x7fd61a97e620>
set t.adapts_to: <__main__.MyClass object at 0x7fd61a97e728>
set t.adapts_to_: <__main__.MyClassTestInterfaceAdapter object at 0x7fd61a97e780
```
Notice that the default values of `supports` and `adapts_to` are not of the expected types - they have not had adaptation applied to them.
This can probably be fixed by refactoring them to be simpler mapped traits.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.