From f01efc85a299bc65f3be6a03c610441166bf8e88 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 14 Feb 2022 22:13:28 +0000 Subject: [PATCH 1/2] Add `@final` to several stdlib classes that cannot be subclassed at runtime --- stdlib/_json.pyi | 3 +++ stdlib/_tkinter.pyi | 1 + stdlib/hashlib.pyi | 2 ++ stdlib/sqlite3/dbapi2.pyi | 2 ++ stdlib/ssl.pyi | 4 +++- stdlib/unicodedata.pyi | 2 ++ 6 files changed, 13 insertions(+), 1 deletion(-) diff --git a/stdlib/_json.pyi b/stdlib/_json.pyi index 7395288afdbc..36b0ed679502 100644 --- a/stdlib/_json.pyi +++ b/stdlib/_json.pyi @@ -1,5 +1,7 @@ from typing import Any, Callable +from typing_extensions import final +@final class make_encoder: sort_keys: Any skipkeys: Any @@ -23,6 +25,7 @@ class make_encoder: ) -> None: ... def __call__(self, obj: object, _current_indent_level: int) -> Any: ... +@final class make_scanner: object_hook: Any object_pairs_hook: Any diff --git a/stdlib/_tkinter.pyi b/stdlib/_tkinter.pyi index 7c0ccec1d7de..382b7f52f382 100644 --- a/stdlib/_tkinter.pyi +++ b/stdlib/_tkinter.pyi @@ -101,6 +101,7 @@ WRITABLE: Literal[4] TCL_VERSION: str TK_VERSION: str +@final class TkttType: def deletetimerhandler(self): ... diff --git a/stdlib/hashlib.pyi b/stdlib/hashlib.pyi index fad3c5aad457..246a7fed7afe 100644 --- a/stdlib/hashlib.pyi +++ b/stdlib/hashlib.pyi @@ -1,6 +1,7 @@ import sys from _typeshed import ReadableBuffer, Self from typing import AbstractSet +from typing_extensions import final class _Hash: @property @@ -77,6 +78,7 @@ def scrypt( dklen: int = ..., ) -> bytes: ... +@final class _BlakeHash(_Hash): MAX_DIGEST_SIZE: int MAX_KEY_SIZE: int diff --git a/stdlib/sqlite3/dbapi2.pyi b/stdlib/sqlite3/dbapi2.pyi index 820b40baa47b..7e0d2e6a0d33 100644 --- a/stdlib/sqlite3/dbapi2.pyi +++ b/stdlib/sqlite3/dbapi2.pyi @@ -2,6 +2,7 @@ import sys from _typeshed import Self, StrOrBytesPath from datetime import date, datetime, time from typing import Any, Callable, Generator, Iterable, Iterator, Protocol, TypeVar +from typing_extensions import final _T = TypeVar("_T") @@ -223,6 +224,7 @@ class OperationalError(DatabaseError): ... OptimizedUnicode = str +@final class PrepareProtocol: def __init__(self, *args: Any, **kwargs: Any) -> None: ... diff --git a/stdlib/ssl.pyi b/stdlib/ssl.pyi index 28f616eceabf..fb9acb011e4c 100644 --- a/stdlib/ssl.pyi +++ b/stdlib/ssl.pyi @@ -3,7 +3,7 @@ import socket import sys from _typeshed import ReadableBuffer, Self, StrOrBytesPath, WriteableBuffer from typing import Any, Callable, ClassVar, Iterable, NamedTuple, Optional, Union, overload -from typing_extensions import Literal, TypedDict +from typing_extensions import Literal, TypedDict, final _PCTRTT = tuple[tuple[str, str], ...] _PCTRTTT = tuple[_PCTRTT, ...] @@ -471,6 +471,7 @@ class SSLObject: if sys.version_info >= (3, 8): def verify_client_post_handshake(self) -> None: ... +@final class MemoryBIO: pending: int eof: bool @@ -478,6 +479,7 @@ class MemoryBIO: def write(self, __buf: bytes) -> int: ... def write_eof(self) -> None: ... +@final class SSLSession: id: bytes time: int diff --git a/stdlib/unicodedata.pyi b/stdlib/unicodedata.pyi index ead25ba4062c..ba9f3bda27b5 100644 --- a/stdlib/unicodedata.pyi +++ b/stdlib/unicodedata.pyi @@ -1,5 +1,6 @@ import sys from typing import Any, TypeVar +from typing_extensions import final ucd_3_2_0: UCD ucnhash_CAPI: Any @@ -24,6 +25,7 @@ def name(__chr: str, __default: _T = ...) -> str | _T: ... def normalize(__form: str, __unistr: str) -> str: ... def numeric(__chr: str, __default: _T = ...) -> float | _T: ... +@final class UCD: # The methods below are constructed from the same array in C # (unicodedata_functions) and hence identical to the methods above. From b216f5258865a55efa0714c28a13fa2d68c33b5c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 14 Feb 2022 22:19:00 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/hashlib.pyi | 1 - stdlib/unicodedata.pyi | 1 - 2 files changed, 2 deletions(-) diff --git a/stdlib/hashlib.pyi b/stdlib/hashlib.pyi index 246a7fed7afe..3b8fbeb0bf3e 100644 --- a/stdlib/hashlib.pyi +++ b/stdlib/hashlib.pyi @@ -77,7 +77,6 @@ def scrypt( maxmem: int = ..., dklen: int = ..., ) -> bytes: ... - @final class _BlakeHash(_Hash): MAX_DIGEST_SIZE: int diff --git a/stdlib/unicodedata.pyi b/stdlib/unicodedata.pyi index ba9f3bda27b5..dca88caa7c1f 100644 --- a/stdlib/unicodedata.pyi +++ b/stdlib/unicodedata.pyi @@ -24,7 +24,6 @@ def mirrored(__chr: str) -> int: ... def name(__chr: str, __default: _T = ...) -> str | _T: ... def normalize(__form: str, __unistr: str) -> str: ... def numeric(__chr: str, __default: _T = ...) -> float | _T: ... - @final class UCD: # The methods below are constructed from the same array in C