diff options
author | Torsten Marek <shlomme@gmail.com> | 2014-04-26 20:47:42 +0200 |
---|---|---|
committer | Torsten Marek <shlomme@gmail.com> | 2014-04-26 20:47:42 +0200 |
commit | ee970b32970ce02e7a1ebd719a5513939db7256f (patch) | |
tree | a9a1e65f55c1f8d7bf7950b35004fba1c3cc7368 | |
parent | 4aeefb49df1bd1b52e40e1e0064ef5d91938a42e (diff) | |
download | astroid-ee970b32970ce02e7a1ebd719a5513939db7256f.tar.gz |
Only cache modules if no other module with the same name is known yet, and
only return cached modules if name and filepath match.
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | builder.py | 2 | ||||
-rw-r--r-- | manager.py | 5 | ||||
-rw-r--r-- | raw_building.py | 3 |
4 files changed, 12 insertions, 3 deletions
@@ -1,6 +1,11 @@ Change log for the astroid package (used to be astng) ===================================================== + * Do not cache modules if a module with the same qname is already + known, and only return cached modules if both name and filepath + match. Fixes pylint Bitbucket issue #136. + + 2014-04-18 -- 1.1.0 * All class nodes are marked as new style classes for Py3k. @@ -145,7 +145,7 @@ class AstroidBuilder(InspectBuilder): after a module has been built """ module.file_encoding = encoding - self._manager.astroid_cache[module.name] = module + self._manager.cache_module(module) # post tree building steps after we stored the module in the cache: for from_node in module._from_nodes: if from_node.modname == '__future__': @@ -97,7 +97,7 @@ class AstroidManager(OptionsProviderMixIn): modname = '.'.join(modpath_from_file(filepath)) except ImportError: modname = filepath - if modname in self.astroid_cache: + if modname in self.astroid_cache and self.astroid_cache[modname].file == filepath: return self.astroid_cache[modname] if source: from astroid.builder import AstroidBuilder @@ -301,6 +301,9 @@ class AstroidManager(OptionsProviderMixIn): node = ret return node + def cache_module(self, module): + """Cache a module if no module with the same name is known yet.""" + self.astroid_cache.setdefault(module.name, module) class Project(object): diff --git a/raw_building.py b/raw_building.py index 720cdce..bb685a9 100644 --- a/raw_building.py +++ b/raw_building.py @@ -225,7 +225,8 @@ class InspectBuilder(object): # in jython, java modules have no __doc__ (see #109562) node = build_module(modname) node.file = node.path = path and abspath(path) or path - MANAGER.astroid_cache[modname] = node + node.name = modname + MANAGER.cache_module(node) node.package = hasattr(module, '__path__') self._done = {} self.object_build(node, module) |