From dd7d4a92f433bebc414c360b7a81772e87b3ab99 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Mon, 12 Oct 2026 22:33:31 +0200 Subject: [PATCH] Avoid a crash, fixes #1990 --- jedi/inference/compiled/value.py | 5 ++--- test/test_api/test_interpreter.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/jedi/inference/compiled/value.py b/jedi/inference/compiled/value.py index aeeb12fd..5593d3e5 100644 --- a/jedi/inference/compiled/value.py +++ b/jedi/inference/compiled/value.py @@ -256,12 +256,11 @@ class CompiledValue(Value): arg.execute_annotation(context) for arg in arguments) elif name: - # While with_generics only exists on very specific objects, we - # should probably be fine, because we control all the typing - # objects. + # These are typically typing module objects. Try to use that to create generics. return ValueSet([ v.with_generics(arguments) for v in self.inference_state.typing_module.py__getattribute__(name) + if hasattr(v, "with_generics") ]).execute_annotation(context) return super().execute_annotation(context) diff --git a/test/test_api/test_interpreter.py b/test/test_api/test_interpreter.py index eb00b044..e156f555 100644 --- a/test/test_api/test_interpreter.py +++ b/test/test_api/test_interpreter.py @@ -873,3 +873,20 @@ def test_whitespace_after_dot_completion(Script): # From #1954 completions = jedi.Interpreter("object. \n", []).complete(1, 8) assert "mro" in [c.name for c in completions] + + +def test_interpreter_with_literals_no_crash(): + # From #1990 + class A: + @property + def value(self) -> typing.Literal["a"]: + return "a" + + a = A() + + interpreter = jedi.Interpreter("a.", [{"a": a}]) + value = next(filter(lambda c: c.name == "value", interpreter.complete())) + assert value.name == "value" + + interpreter = jedi.Interpreter("a.value.", [{"a": a}]) + assert "upper" in [c.name for c in interpreter.complete()]