Trait factory method in traits.py caches by Id
- Dominant language
- Python
- Stars
- 462
- Forks
- 90
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
trait_factory method in traits.py caches using id of trait, instead of trait itself. Downside here is that if no one stores reference to trait, this traits gets garbage collection and another object can have potentially same id, which leads to strange bugs.
Thanks,
Gaurav Nanda
==== Code ====
Returns a trait created from a TraitFactory instance:
```
_trait_factory_instances = {}
def trait_factory ( trait ):
global _trait_factory_instances
tid = id( trait )
if tid not in _trait_factory_instances:
_trait_factory_instances[ tid ] = trait()
return _trait_factory_instances[ tid ]
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.