From 6473ddc28c0733f808213f6194df6f1ab84f835c Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Tue, 28 Apr 2026 15:49:21 +0200 Subject: [PATCH] Implement Final[...] in a way so it doesn't completely fail --- jedi/inference/gradual/typing.py | 5 +++-- test/completion/pep0484_typing.py | 14 +++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/jedi/inference/gradual/typing.py b/jedi/inference/gradual/typing.py index f33c908f..0f5b74ad 100644 --- a/jedi/inference/gradual/typing.py +++ b/jedi/inference/gradual/typing.py @@ -33,7 +33,8 @@ _TYPE_ALIAS_TYPES = { 'DefaultDict': 'collections.defaultdict', 'Deque': 'collections.deque', } -_PROXY_TYPES = 'Optional Union ClassVar Annotated'.split() +_PROXY_TYPES = ['Optional', 'Union', 'ClassVar', 'Annotated', 'Final'] +_IGNORE_ANNOTATION_PARTS = ['ClassVar', 'Annotated', 'Final'] class TypingModuleName(NameWrapper): @@ -114,7 +115,7 @@ class ProxyWithGenerics(BaseTypingClassWithGenerics): elif string_name == 'Type': # The type is actually already given in the index_value return self._generics_manager[0] - elif string_name in ['ClassVar', 'Annotated']: + elif string_name in _IGNORE_ANNOTATION_PARTS: # For now don't do anything here, ClassVars are always used. return self._generics_manager[0].execute_annotation() diff --git a/test/completion/pep0484_typing.py b/test/completion/pep0484_typing.py index 1eaadbc7..db111bda 100644 --- a/test/completion/pep0484_typing.py +++ b/test/completion/pep0484_typing.py @@ -3,7 +3,7 @@ Test the typing library, with docstrings and annotations """ import typing from typing import Sequence, MutableSequence, List, Iterable, Iterator, \ - AbstractSet, Tuple, Mapping, Dict, Union, Optional + AbstractSet, Tuple, Mapping, Dict, Union, Optional, Final class B: pass @@ -555,3 +555,15 @@ def typed_dict_test_foo(arg: Bar): arg['an_int'] #? int() arg['another_variable'] + +# ------------------------- +# Final +# ------------------------- + +x: Final[str] = 1 +y: Final = 1 +#? str() +x +# TODO +#? +y