mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 14:54:47 +08:00
Use a LazyName for module attributes, they should only be generated if needed.
This commit is contained in:
@@ -220,6 +220,20 @@ class FakeName(pr.Name):
|
||||
super(FakeName, self).__init__(FakeSubModule, names, p, p, parent)
|
||||
|
||||
|
||||
class LazyName(FakeName):
|
||||
def __init__(self, name, parent_callback):
|
||||
super(LazyName, self).__init__(name)
|
||||
self._parent_callback = parent_callback
|
||||
|
||||
@property
|
||||
def parent(self):
|
||||
return self._parent_callback()
|
||||
|
||||
@parent.setter
|
||||
def parent(self, value):
|
||||
pass # Do nothing, lower level can try to set the parent.
|
||||
|
||||
|
||||
def stmts_to_stmt(statements):
|
||||
"""
|
||||
Sometimes we want to have something like a result_set and unite some
|
||||
|
||||
@@ -617,10 +617,12 @@ class ModuleWrapper(use_metaclass(CachedMetaClass, pr.Module)):
|
||||
|
||||
@memoize_default()
|
||||
def _module_attributes(self):
|
||||
def parent_callback():
|
||||
return Instance(self._evaluator, compiled.create(self._evaluator, str))
|
||||
|
||||
names = ['__file__', '__package__', '__doc__', '__name__', '__version__']
|
||||
# All the additional module attributes are strings.
|
||||
parent = Instance(self._evaluator, compiled.create(self._evaluator, str))
|
||||
return [helpers.FakeName(n, parent) for n in names]
|
||||
return [helpers.LazyName(n, parent_callback) for n in names]
|
||||
|
||||
@memoize_default()
|
||||
def _sub_modules(self):
|
||||
|
||||
Reference in New Issue
Block a user