mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Make sure that the definition order in stubs are ignored
This commit is contained in:
@@ -51,6 +51,16 @@ class StubModuleValue(ModuleValue):
|
||||
for f in filters:
|
||||
yield f
|
||||
|
||||
def _as_context(self):
|
||||
return StubModuleContext(self)
|
||||
|
||||
|
||||
class StubModuleContext(ModuleContext):
|
||||
def get_filters(self, until_position=None, origin_scope=None):
|
||||
# Make sure to ignore the position, because positions are not relevant
|
||||
# for stubs.
|
||||
return super(StubModuleContext, self).get_filters(origin_scope=origin_scope)
|
||||
|
||||
|
||||
class TypingModuleWrapper(StubModuleValue):
|
||||
def get_filters(self, *args, **kwargs):
|
||||
|
||||
@@ -1 +1,9 @@
|
||||
in_stub_only: int
|
||||
|
||||
|
||||
class Foo(Bar):
|
||||
pass
|
||||
|
||||
|
||||
class Bar:
|
||||
pass
|
||||
|
||||
@@ -38,3 +38,19 @@ def test_conversion_of_stub_only(Script):
|
||||
assert d2.line == d1.line
|
||||
assert d2.column == d1.column
|
||||
assert d2.name == 'in_stub_only'
|
||||
|
||||
|
||||
def test_goto_on_file(Script):
|
||||
project = Project(os.path.join(root_dir, 'test', 'completion', 'stub_folder'))
|
||||
script = Script('import stub_only; stub_only.Foo', _project=project)
|
||||
d1, = script.goto_assignments()
|
||||
v, = d1._name.infer()
|
||||
foo, bar, obj = v.py__mro__()
|
||||
assert foo.py__name__() == 'Foo'
|
||||
assert bar.py__name__() == 'Bar'
|
||||
assert obj.py__name__() == 'object'
|
||||
|
||||
# Make sure we go to Bar, because Foo is a bit before: `class Foo(Bar):`
|
||||
script = Script(path=d1.module_path, line=d1.line, column=d1.column + 4, _project=project)
|
||||
d2, = script.goto_assignments()
|
||||
assert d2.name == 'Bar'
|
||||
|
||||
Reference in New Issue
Block a user