From c8caa8f4ac3f1ed2c95da6740321c9adc1269d3d Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Wed, 1 Aug 2018 10:47:46 +0200 Subject: [PATCH] Use a class stub class --- jedi/plugins/typeshed.py | 9 +++++++-- test/test_plugin/test_stub.py | 12 +++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/jedi/plugins/typeshed.py b/jedi/plugins/typeshed.py index 64cc7913..eccd0370 100644 --- a/jedi/plugins/typeshed.py +++ b/jedi/plugins/typeshed.py @@ -165,10 +165,16 @@ class StubName(TreeNameDefinition): c.parent_context, c.tree_node, ) + elif isinstance(c, ClassContext): + yield ClassStubContext( + c.evaluator, + c.parent_context, + c.tree_node + ) else: yield c - contexts = tree_name_to_contexts( + contexts = tree_name_to_contexts( self.parent_context.evaluator, self._stub_parent_context, self._stub_tree_name @@ -176,7 +182,6 @@ class StubName(TreeNameDefinition): return ContextSet.from_iterable(iterate(contexts)) - class StubParserTreeFilter(ParserTreeFilter): name_class = StubName diff --git a/test/test_plugin/test_stub.py b/test/test_plugin/test_stub.py index cf365176..067bda6b 100644 --- a/test/test_plugin/test_stub.py +++ b/test/test_plugin/test_stub.py @@ -37,14 +37,20 @@ def test_get_stub_files(): def test_function(Script): - s = Script('import threading; threading.current_thread') - def_, = s.goto_definitions() + code = 'import threading; threading.current_thread' + def_, = Script(code).goto_definitions() context = def_._name._context assert isinstance(context, typeshed.FunctionStubContext), context + def_, = Script(code + '()').goto_definitions() + context = def_._name._context + assert isinstance(context, typeshed.ClassStubContext), context + def test_class(Script): - s = Script('import threading; threading.Lock') + def_, = Script('import threading; threading.Lock').goto_definitions() + context = def_._name._context + assert isinstance(context, typeshed.ClassStubContext), context def test_instance(Script):