enthought / enthought/traits

Trait factory method in traits.py caches by Id

Open
#201 0 comments 0 reactions 0 assignees View on GitHub
type: bug
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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.