mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +08:00
Finally use the string_names attribute to identify module names instead of some fucked up path calculation.
This commit is contained in:
@@ -118,20 +118,7 @@ class ModuleMixin(SubModuleDictMixin):
|
|||||||
@property
|
@property
|
||||||
@inference_state_method_cache()
|
@inference_state_method_cache()
|
||||||
def name(self):
|
def name(self):
|
||||||
return self._module_name_class(self, self._string_name)
|
return self._module_name_class(self, self.string_names[-1])
|
||||||
|
|
||||||
@property
|
|
||||||
def _string_name(self):
|
|
||||||
""" This is used for the goto functions. """
|
|
||||||
# TODO It's ugly that we even use this, the name is usually well known
|
|
||||||
# ahead so just pass it when create a ModuleValue.
|
|
||||||
if self._path is None:
|
|
||||||
return '' # no path -> empty name
|
|
||||||
else:
|
|
||||||
sep = (re.escape(os.path.sep),) * 2
|
|
||||||
r = re.search(r'([^%s]*?)(%s__init__)?(\.pyi?|\.so)?$' % sep, self._path)
|
|
||||||
# Remove PEP 3149 names
|
|
||||||
return re.sub(r'\.[a-z]+-\d{2}[mud]{0,3}$', '', r.group(1))
|
|
||||||
|
|
||||||
@inference_state_method_cache()
|
@inference_state_method_cache()
|
||||||
def _module_attributes_dict(self):
|
def _module_attributes_dict(self):
|
||||||
@@ -267,7 +254,7 @@ class ModuleValue(ModuleMixin, TreeValue):
|
|||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s: %s@%s-%s is_stub=%s>" % (
|
return "<%s: %s@%s-%s is_stub=%s>" % (
|
||||||
self.__class__.__name__, self._string_name,
|
self.__class__.__name__, self.py__name__(),
|
||||||
self.tree_node.start_pos[0], self.tree_node.end_pos[0],
|
self.tree_node.start_pos[0], self.tree_node.end_pos[0],
|
||||||
self.is_stub()
|
self.is_stub()
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -278,7 +278,7 @@ def test_parent_on_function(Script):
|
|||||||
code = 'def spam():\n pass'
|
code = 'def spam():\n pass'
|
||||||
def_, = Script(code).goto(line=1, column=len('def spam'))
|
def_, = Script(code).goto(line=1, column=len('def spam'))
|
||||||
parent = def_.parent()
|
parent = def_.parent()
|
||||||
assert parent.name == ''
|
assert parent.name == '__main__'
|
||||||
assert parent.type == 'module'
|
assert parent.type == 'module'
|
||||||
|
|
||||||
|
|
||||||
@@ -328,7 +328,7 @@ def test_parent_on_closure(Script):
|
|||||||
assert foo.parent().name == 'inner'
|
assert foo.parent().name == 'inner'
|
||||||
assert foo.parent().parent().name == 'bar'
|
assert foo.parent().parent().name == 'bar'
|
||||||
assert foo.parent().parent().parent().name == 'Foo'
|
assert foo.parent().parent().parent().name == 'Foo'
|
||||||
assert foo.parent().parent().parent().parent().name == ''
|
assert foo.parent().parent().parent().parent().name == '__main__'
|
||||||
|
|
||||||
assert inner_func.parent().name == 'bar'
|
assert inner_func.parent().name == 'bar'
|
||||||
assert inner_func.parent().parent().name == 'Foo'
|
assert inner_func.parent().parent().name == 'Foo'
|
||||||
@@ -344,7 +344,7 @@ def test_parent_on_comprehension(Script):
|
|||||||
|
|
||||||
assert [name.name for name in ns] == ['spam', 'i']
|
assert [name.name for name in ns] == ['spam', 'i']
|
||||||
|
|
||||||
assert ns[0].parent().name == ''
|
assert ns[0].parent().name == '__main__'
|
||||||
assert ns[0].parent().type == 'module'
|
assert ns[0].parent().type == 'module'
|
||||||
assert ns[1].parent().name == 'spam'
|
assert ns[1].parent().name == 'spam'
|
||||||
assert ns[1].parent().type == 'function'
|
assert ns[1].parent().type == 'function'
|
||||||
|
|||||||
Reference in New Issue
Block a user