mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 23:34:45 +08:00
Fix generator issues for typing
This commit is contained in:
@@ -76,7 +76,7 @@ class GeneratorBase(LazyAttributeOverwrite, IterableMixin):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
return compiled.CompiledContextName(self, 'generator')
|
return compiled.CompiledContextName(self, 'Generator')
|
||||||
|
|
||||||
|
|
||||||
class Generator(GeneratorBase):
|
class Generator(GeneratorBase):
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from jedi import debug
|
||||||
from jedi.evaluate.base_context import ContextSet, \
|
from jedi.evaluate.base_context import ContextSet, \
|
||||||
NO_CONTEXTS
|
NO_CONTEXTS
|
||||||
from jedi.evaluate.utils import to_list
|
from jedi.evaluate.utils import to_list
|
||||||
@@ -49,11 +50,13 @@ def _infer_from_stub(stub_module, qualified_names, ignore_compiled):
|
|||||||
|
|
||||||
|
|
||||||
def try_stubs_to_actual_context_set(stub_contexts, prefer_stub_to_compiled=False):
|
def try_stubs_to_actual_context_set(stub_contexts, prefer_stub_to_compiled=False):
|
||||||
return ContextSet.from_sets(
|
contexts = ContextSet.from_sets(
|
||||||
stub_to_actual_context_set(stub_context, ignore_compiled=prefer_stub_to_compiled)
|
stub_to_actual_context_set(stub_context, ignore_compiled=prefer_stub_to_compiled)
|
||||||
or ContextSet([stub_context])
|
or ContextSet([stub_context])
|
||||||
for stub_context in stub_contexts
|
for stub_context in stub_contexts
|
||||||
)
|
)
|
||||||
|
debug.dbg('Stubs to actual: %s to %s', stub_contexts, contexts)
|
||||||
|
return contexts
|
||||||
|
|
||||||
|
|
||||||
@to_list
|
@to_list
|
||||||
|
|||||||
@@ -575,5 +575,11 @@ _implemented = {
|
|||||||
# Not sure if this is necessary, but it's used a lot in typeshed and
|
# Not sure if this is necessary, but it's used a lot in typeshed and
|
||||||
# it's for now easier to just pass the function.
|
# it's for now easier to just pass the function.
|
||||||
'abstractmethod': _return_first_param,
|
'abstractmethod': _return_first_param,
|
||||||
}
|
},
|
||||||
|
'typing': {
|
||||||
|
# The _alias function just leads to some annoying type inference.
|
||||||
|
# Therefore, just make it return nothing, which leads to the stubs
|
||||||
|
# being used instead. This only matters for 3.7+.
|
||||||
|
'_alias': lambda obj, arguments: NO_CONTEXTS,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ def test_goto_definitions_on_non_name(Script):
|
|||||||
|
|
||||||
def test_goto_definitions_on_generator(Script):
|
def test_goto_definitions_on_generator(Script):
|
||||||
def_, = Script('def x(): yield 1\ny=x()\ny').goto_definitions()
|
def_, = Script('def x(): yield 1\ny=x()\ny').goto_definitions()
|
||||||
assert def_.name == 'generator'
|
assert def_.name == 'Generator'
|
||||||
|
|
||||||
|
|
||||||
def test_goto_definition_not_multiple(Script):
|
def test_goto_definition_not_multiple(Script):
|
||||||
|
|||||||
Reference in New Issue
Block a user