Skip to content

Commit 7c7629d

Browse files
authored
add typing._Final (#13015)
This is the subset of typing module internal base classes that are stable over all supported versions of python.
1 parent dfbbf16 commit 7c7629d

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

stdlib/@tests/stubtest_allowlists/common.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,8 @@ typing_extensions\.ParamSpec.*
462462
typing(_extensions)?\.Generic
463463
typing\.Protocol
464464
typing(_extensions)?\._TypedDict
465+
typing._Final
466+
typing._Final.__init_subclass__
465467

466468
# Special primitives
467469
typing_extensions\.Final

stdlib/typing.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ if sys.version_info >= (3, 13):
133133

134134
Any = object()
135135

136+
class _Final: ...
137+
136138
def final(f: _T) -> _T: ...
137139
@final
138140
class TypeVar:
@@ -191,7 +193,7 @@ _promote = object()
191193

192194
# N.B. Keep this definition in sync with typing_extensions._SpecialForm
193195
@final
194-
class _SpecialForm:
196+
class _SpecialForm(_Final):
195197
def __getitem__(self, parameters: Any) -> object: ...
196198
if sys.version_info >= (3, 10):
197199
def __or__(self, other: Any) -> _SpecialForm: ...
@@ -973,7 +975,7 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta):
973975
def __ior__(self, value: typing_extensions.Self, /) -> typing_extensions.Self: ... # type: ignore[misc]
974976

975977
@final
976-
class ForwardRef:
978+
class ForwardRef(_Final):
977979
__forward_arg__: str
978980
__forward_code__: CodeType
979981
__forward_evaluated__: bool

stdlib/typing_extensions.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,10 @@ _T = typing.TypeVar("_T")
190190
_F = typing.TypeVar("_F", bound=Callable[..., Any])
191191
_TC = typing.TypeVar("_TC", bound=type[object])
192192

193+
class _Final: ... # This should be imported from typing but that breaks pytype
194+
193195
# unfortunately we have to duplicate this class definition from typing.pyi or we break pytype
194-
class _SpecialForm:
196+
class _SpecialForm(_Final):
195197
def __getitem__(self, parameters: Any) -> object: ...
196198
if sys.version_info >= (3, 10):
197199
def __or__(self, other: Any) -> _SpecialForm: ...

0 commit comments

Comments
 (0)