Implement Final[...] in a way so it doesn't completely fail

This commit is contained in:
Dave Halter
2026-04-28 15:49:21 +02:00
parent b27a7dde18
commit 6473ddc28c
2 changed files with 16 additions and 3 deletions
+3 -2
View File
@@ -33,7 +33,8 @@ _TYPE_ALIAS_TYPES = {
'DefaultDict': 'collections.defaultdict', 'DefaultDict': 'collections.defaultdict',
'Deque': 'collections.deque', '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): class TypingModuleName(NameWrapper):
@@ -114,7 +115,7 @@ class ProxyWithGenerics(BaseTypingClassWithGenerics):
elif string_name == 'Type': elif string_name == 'Type':
# The type is actually already given in the index_value # The type is actually already given in the index_value
return self._generics_manager[0] 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. # For now don't do anything here, ClassVars are always used.
return self._generics_manager[0].execute_annotation() return self._generics_manager[0].execute_annotation()
+13 -1
View File
@@ -3,7 +3,7 @@ Test the typing library, with docstrings and annotations
""" """
import typing import typing
from typing import Sequence, MutableSequence, List, Iterable, Iterator, \ from typing import Sequence, MutableSequence, List, Iterable, Iterator, \
AbstractSet, Tuple, Mapping, Dict, Union, Optional AbstractSet, Tuple, Mapping, Dict, Union, Optional, Final
class B: class B:
pass pass
@@ -555,3 +555,15 @@ def typed_dict_test_foo(arg: Bar):
arg['an_int'] arg['an_int']
#? int() #? int()
arg['another_variable'] arg['another_variable']
# -------------------------
# Final
# -------------------------
x: Final[str] = 1
y: Final = 1
#? str()
x
# TODO
#?
y