mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Get the context of a class name right, fixes #1396
This commit is contained in:
@@ -56,8 +56,7 @@ from jedi.plugins import plugin_manager
|
|||||||
|
|
||||||
class ClassName(TreeNameDefinition):
|
class ClassName(TreeNameDefinition):
|
||||||
def __init__(self, class_value, tree_name, name_context, apply_decorators):
|
def __init__(self, class_value, tree_name, name_context, apply_decorators):
|
||||||
super(ClassName, self).__init__(class_value.as_context(), tree_name)
|
super(ClassName, self).__init__(name_context, tree_name)
|
||||||
self._name_context = name_context
|
|
||||||
self._apply_decorators = apply_decorators
|
self._apply_decorators = apply_decorators
|
||||||
self._class_value = class_value
|
self._class_value = class_value
|
||||||
|
|
||||||
@@ -66,7 +65,7 @@ class ClassName(TreeNameDefinition):
|
|||||||
# We're using a different value to infer, so we cannot call super().
|
# We're using a different value to infer, so we cannot call super().
|
||||||
from jedi.inference.syntax_tree import tree_name_to_values
|
from jedi.inference.syntax_tree import tree_name_to_values
|
||||||
inferred = tree_name_to_values(
|
inferred = tree_name_to_values(
|
||||||
self.parent_context.inference_state, self._name_context, self.tree_name)
|
self.parent_context.inference_state, self.parent_context, self.tree_name)
|
||||||
|
|
||||||
for result_value in inferred:
|
for result_value in inferred:
|
||||||
if self._apply_decorators:
|
if self._apply_decorators:
|
||||||
|
|||||||
@@ -3,12 +3,14 @@
|
|||||||
|
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
from inspect import cleandoc
|
from inspect import cleandoc
|
||||||
|
import os
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import jedi
|
import jedi
|
||||||
from jedi import __doc__ as jedi_doc
|
from jedi import __doc__ as jedi_doc
|
||||||
from jedi.inference.compiled import CompiledValueName
|
from jedi.inference.compiled import CompiledValueName
|
||||||
|
from ..helpers import get_example_dir
|
||||||
|
|
||||||
|
|
||||||
def test_is_keyword(Script):
|
def test_is_keyword(Script):
|
||||||
@@ -473,3 +475,25 @@ def test_execute(Script, code, description):
|
|||||||
else:
|
else:
|
||||||
d, = definitions
|
d, = definitions
|
||||||
assert d.description == description
|
assert d.description == description
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('goto_assignment', [False, True, None])
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
'code, name, file_name', [
|
||||||
|
('from pkg import Foo; Foo.foo', 'foo', '__init__.py'),
|
||||||
|
('from pkg import Foo; Foo().foo', 'foo', '__init__.py'),
|
||||||
|
('from pkg import Foo; Foo.bar', 'bar', 'module.py'),
|
||||||
|
('from pkg import Foo; Foo().bar', 'bar', 'module.py'),
|
||||||
|
])
|
||||||
|
def test_inheritance_module_path(Script, goto_assignment, code, name, file_name):
|
||||||
|
base_path = os.path.join(get_example_dir('inheritance'), 'pkg')
|
||||||
|
whatever_path = os.path.join(base_path, 'NOT_EXISTING.py')
|
||||||
|
|
||||||
|
script = Script(code, path=whatever_path)
|
||||||
|
if goto_assignment is None:
|
||||||
|
func, = script.goto_definitions()
|
||||||
|
else:
|
||||||
|
func, = script.goto_assignments(follow_imports=goto_assignment)
|
||||||
|
assert func.type == 'function'
|
||||||
|
assert func.name == name
|
||||||
|
assert func.module_path == os.path.join(base_path, file_name)
|
||||||
|
|||||||
Reference in New Issue
Block a user