Skip to content

Add @final to several stdlib classes that cannot be subclassed at runtime #7213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions stdlib/_json.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Any, Callable
from typing_extensions import final

@final
class make_encoder:
sort_keys: Any
skipkeys: Any
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions stdlib/_tkinter.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ WRITABLE: Literal[4]
TCL_VERSION: str
TK_VERSION: str

@final
class TkttType:
def deletetimerhandler(self): ...

Expand Down
3 changes: 2 additions & 1 deletion stdlib/hashlib.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
from _typeshed import ReadableBuffer, Self
from typing import AbstractSet
from typing_extensions import final

class _Hash:
@property
Expand Down Expand Up @@ -76,7 +77,7 @@ def scrypt(
maxmem: int = ...,
dklen: int = ...,
) -> bytes: ...

@final
class _BlakeHash(_Hash):
MAX_DIGEST_SIZE: int
MAX_KEY_SIZE: int
Expand Down
2 changes: 2 additions & 0 deletions stdlib/sqlite3/dbapi2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -223,6 +224,7 @@ class OperationalError(DatabaseError): ...

OptimizedUnicode = str

@final
class PrepareProtocol:
def __init__(self, *args: Any, **kwargs: Any) -> None: ...

Expand Down
4 changes: 3 additions & 1 deletion stdlib/ssl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...]
Expand Down Expand Up @@ -471,13 +471,15 @@ class SSLObject:
if sys.version_info >= (3, 8):
def verify_client_post_handshake(self) -> None: ...

@final
class MemoryBIO:
pending: int
eof: bool
def read(self, __size: int = ...) -> bytes: ...
def write(self, __buf: bytes) -> int: ...
def write_eof(self) -> None: ...

@final
class SSLSession:
id: bytes
time: int
Expand Down
3 changes: 2 additions & 1 deletion stdlib/unicodedata.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
from typing import Any, TypeVar
from typing_extensions import final

ucd_3_2_0: UCD
ucnhash_CAPI: Any
Expand All @@ -23,7 +24,7 @@ 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
# (unicodedata_functions) and hence identical to the methods above.
Expand Down