diff options
author | Philippe Pepiot <philippe.pepiot@logilab.fr> | 2017-01-20 16:02:24 +0100 |
---|---|---|
committer | Philippe Pepiot <philippe.pepiot@logilab.fr> | 2017-01-20 16:02:24 +0100 |
commit | 846950d49aca16fb3d848bf7e5851985377a3f73 (patch) | |
tree | a957a71de4bb9077e0913b617d5313178a3f337f /logilab/common | |
parent | 742fe7dda53fc4fbe5ccf8e1827ab6bbe5af95f0 (diff) | |
download | logilab-common-846950d49aca16fb3d848bf7e5851985377a3f73.tar.gz |
[registry] RegistrableInstance should be instantiated with __module__=__name__
To detect in whih module the instance was created we previously detect the
filename in python stack and then use modpath_from_file(). Since the later is
now deprecated, we should force passing the module at instantiation with
__module__=__name__.
Deprecate old usage
Diffstat (limited to 'logilab/common')
-rw-r--r-- | logilab/common/registry.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/logilab/common/registry.py b/logilab/common/registry.py index 476bef8..83f467b 100644 --- a/logilab/common/registry.py +++ b/logilab/common/registry.py @@ -212,12 +212,22 @@ class RegistrableInstance(RegistrableObject): """Add a __module__ attribute telling the module where the instance was created, for automatic registration. """ + module = kwargs.pop('__module__', None) obj = super(RegistrableInstance, cls).__new__(cls) - # XXX subclass must no override __new__ - filepath = tb.extract_stack(limit=2)[0][0] - obj.__module__ = _modname_from_path(filepath) + if module is None: + warn('instantiate {0} with ' + '__module__=__name__'.format(cls.__name__), + DeprecationWarning) + # XXX subclass must no override __new__ + filepath = tb.extract_stack(limit=2)[0][0] + obj.__module__ = _modname_from_path(filepath) + else: + obj.__module__ = module return obj + def __init__(self, __module__=None): + super(RegistrableInstance, self).__init__() + class Registry(dict): """The registry store a set of implementations associated to identifier: |