From a6d9b8326335f8d7ba208af7be6aaa53165163b9 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Mon, 14 Feb 2022 15:12:40 -0800 Subject: [PATCH] Add `@final` to several more stdlib classes (#7215) Co-authored-by: hauntsaninja <> --- stdlib/_curses.pyi | 2 ++ stdlib/parser.pyi | 2 ++ stdlib/select.pyi | 3 +++ stdlib/typing.pyi | 3 +++ stdlib/typing_extensions.pyi | 1 + stdlib/xxlimited.pyi | 2 ++ 6 files changed, 13 insertions(+) diff --git a/stdlib/_curses.pyi b/stdlib/_curses.pyi index 33dee1ac1..702209762 100644 --- a/stdlib/_curses.pyi +++ b/stdlib/_curses.pyi @@ -1,6 +1,7 @@ import sys from _typeshed import SupportsRead from typing import IO, Any, NamedTuple, Union, overload +from typing_extensions import final if sys.platform != "win32": _chtype = Union[str, bytes, int] @@ -374,6 +375,7 @@ if sys.platform != "win32": class error(Exception): ... + @final class _CursesWindow: encoding: str @overload diff --git a/stdlib/parser.pyi b/stdlib/parser.pyi index ab819a71a..95e770b57 100644 --- a/stdlib/parser.pyi +++ b/stdlib/parser.pyi @@ -1,6 +1,7 @@ from _typeshed import StrOrBytesPath from types import CodeType from typing import Any, Sequence +from typing_extensions import final def expr(source: str) -> STType: ... def suite(source: str) -> STType: ... @@ -14,6 +15,7 @@ def issuite(st: STType) -> bool: ... class ParserError(Exception): ... +@final class STType: def compile(self, filename: StrOrBytesPath = ...) -> CodeType: ... def isexpr(self) -> bool: ... diff --git a/stdlib/select.pyi b/stdlib/select.pyi index 3e5aec69f..51e70b04d 100644 --- a/stdlib/select.pyi +++ b/stdlib/select.pyi @@ -2,6 +2,7 @@ import sys from _typeshed import FileDescriptorLike, Self from types import TracebackType from typing import Any, Iterable +from typing_extensions import final if sys.platform != "win32": PIPE_BUF: int @@ -33,6 +34,7 @@ error = OSError if sys.platform != "linux" and sys.platform != "win32": # BSD only + @final class kevent: data: Any fflags: int @@ -50,6 +52,7 @@ if sys.platform != "linux" and sys.platform != "win32": udata: Any = ..., ) -> None: ... # BSD only + @final class kqueue: closed: bool def __init__(self) -> None: ... diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index d384da71b..9a6bd37ea 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -13,6 +13,7 @@ if sys.version_info >= (3, 9): Any = object() +@_final class TypeVar: __name__: str __bound__: Any | None @@ -30,6 +31,7 @@ class TypeVar: _promote = object() # N.B. Keep this definition in sync with typing_extensions._SpecialForm +@_final class _SpecialForm: def __getitem__(self, typeargs: Any) -> object: ... if sys.version_info >= (3, 10): @@ -748,6 +750,7 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta): def type_check_only(func_or_cls: _F) -> _F: ... if sys.version_info >= (3, 7): + @_final class ForwardRef: __forward_arg__: str __forward_code__: CodeType diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index c5f5cfcdd..3ec9bc004 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -150,6 +150,7 @@ NotRequired: _SpecialForm LiteralString: _SpecialForm Unpack: _SpecialForm +@final class TypeVarTuple: __name__: str def __init__(self, name: str) -> None: ... diff --git a/stdlib/xxlimited.pyi b/stdlib/xxlimited.pyi index 56a4fac4c..b2fb72ad2 100644 --- a/stdlib/xxlimited.pyi +++ b/stdlib/xxlimited.pyi @@ -1,8 +1,10 @@ import sys from typing import Any +from typing_extensions import final class Str: ... +@final class Xxo: def demo(self) -> None: ...