From 4f7dfd14b3877da70a2969e681da72dc67a6c074 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Wed, 29 Apr 2026 23:38:07 +0200 Subject: [PATCH] Small improvements to generator/async completions --- jedi/inference/__init__.py | 6 ++++++ jedi/inference/value/function.py | 4 ++-- jedi/inference/value/iterable.py | 2 +- test/completion/completion.py | 4 ++-- test/completion/fstring.py | 2 +- test/completion/keywords.py | 2 +- test/completion/pep0484_typing.py | 6 +----- test/completion/precedence.py | 2 +- test/completion/usages.py | 2 +- 9 files changed, 16 insertions(+), 14 deletions(-) diff --git a/jedi/inference/__init__.py b/jedi/inference/__init__.py index 74402ad7..842c4710 100644 --- a/jedi/inference/__init__.py +++ b/jedi/inference/__init__.py @@ -139,6 +139,12 @@ class InferenceState: typing_module, = self.import_module(('typing',)) return typing_module + @property + @inference_state_function_cache() + def types_module(self): + typing_module, = self.import_module(('types',)) + return typing_module + def reset_recursion_limitations(self): self.recursion_detector = recursion.RecursionDetector() self.execution_recursion_detector = recursion.ExecutionRecursionDetector(self) diff --git a/jedi/inference/value/function.py b/jedi/inference/value/function.py index e9aa2c68..12f23106 100644 --- a/jedi/inference/value/function.py +++ b/jedi/inference/value/function.py @@ -340,10 +340,10 @@ class BaseFunctionExecutionContext(ValueContext, TreeContextMixin): for c in async_generator_classes ).execute_annotation(None) else: - async_classes = inference_state.typing_module.py__getattribute__('Coroutine') + async_classes = inference_state.types_module.py__getattribute__('CoroutineType') return_values = self.get_return_values() # Only the first generic is relevant. - generics = (return_values.py__class__(), NO_VALUES, NO_VALUES) + generics = (NO_VALUES, NO_VALUES, return_values.py__class__()) return ValueSet( GenericClass(c, TupleGenericManager(generics)) for c in async_classes ).execute_annotation(None) diff --git a/jedi/inference/value/iterable.py b/jedi/inference/value/iterable.py index 7d76b4bf..0bcda9d2 100644 --- a/jedi/inference/value/iterable.py +++ b/jedi/inference/value/iterable.py @@ -48,7 +48,7 @@ class GeneratorBase(LazyAttributeOverwrite, IterableMixin): return instance def _get_cls(self): - generator, = self.inference_state.typing_module.py__getattribute__('Generator') + generator, = self.inference_state.types_module.py__getattribute__('GeneratorType') return generator def py__bool__(self): diff --git a/test/completion/completion.py b/test/completion/completion.py index f509a19c..f0dcb18a 100644 --- a/test/completion/completion.py +++ b/test/completion/completion.py @@ -33,12 +33,12 @@ else try: pass -#? ['except', 'Exception'] +#? ['except', 'Exception', 'ExceptionGroup'] except try: pass -#? 6 ['except', 'Exception'] +#? 6 ['except', 'Exception', 'ExceptionGroup'] except AttributeError: pass #? ['finally'] diff --git a/test/completion/fstring.py b/test/completion/fstring.py index 6e27dc2a..59fe5f6e 100644 --- a/test/completion/fstring.py +++ b/test/completion/fstring.py @@ -13,7 +13,7 @@ Fr'{Foo.bar' Fr'{Foo.bar #? ['bar'] Fr'{Foo.bar -#? ['Exception'] +#? ['Exception', 'ExceptionGroup'] F"{Excepti #? 8 Foo diff --git a/test/completion/keywords.py b/test/completion/keywords.py index fa9bf52d..1c885e7e 100644 --- a/test/completion/keywords.py +++ b/test/completion/keywords.py @@ -2,7 +2,7 @@ #? ['raise'] raise -#? ['Exception'] +#? ['Exception', 'ExceptionGroup'] except #? [] diff --git a/test/completion/pep0484_typing.py b/test/completion/pep0484_typing.py index e0004cd6..48a4434d 100644 --- a/test/completion/pep0484_typing.py +++ b/test/completion/pep0484_typing.py @@ -49,11 +49,7 @@ def iterators(ps: Iterable[int], qs: Iterator[str], rs: a, b = ps #? int() a - ##? int() --- TODO fix support for tuple assignment - # https://github.com/davidhalter/jedi/pull/663#issuecomment-172317854 - # test below is just to make sure that in case it gets fixed by accident - # these tests will be fixed as well the way they should be - #? + #? int() b for q in qs: diff --git a/test/completion/precedence.py b/test/completion/precedence.py index 71c66e1f..958b1805 100644 --- a/test/completion/precedence.py +++ b/test/completion/precedence.py @@ -167,7 +167,7 @@ from datetime import datetime, timedelta (datetime - timedelta) #? datetime() (datetime() - timedelta()) -#? timedelta() +#? timedelta() datetime() (datetime() - datetime()) #? timedelta() (timedelta() - datetime()) diff --git a/test/completion/usages.py b/test/completion/usages.py index 8afffb40..6ed2f875 100644 --- a/test/completion/usages.py +++ b/test/completion/usages.py @@ -389,6 +389,6 @@ if False: # ----------------- import socket -#< (1, 21), (0, 7), ('socket', ..., 6), ('stub:socket', ..., 4), ('imports', ..., 7) +#< (1, 21), (0, 7), ('socket', ..., 6), ('stub:socket', ..., 6), ('imports', ..., 7) socket.SocketIO some_socket = socket.SocketIO()