Skip to content

Commit a768744

Browse files
authored
Type and mark as final module-level dunders not meant to be overwritten in stdlib/ (#9709)
1 parent 35871f4 commit a768744

File tree

8 files changed

+25
-22
lines changed

8 files changed

+25
-22
lines changed

stdlib/_csv.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from _typeshed import SupportsWrite
22
from collections.abc import Iterable, Iterator
33
from typing import Any
4-
from typing_extensions import Literal, TypeAlias
4+
from typing_extensions import Final, Literal, TypeAlias
55

6-
__version__: str
6+
__version__: Final[str]
77

88
QUOTE_ALL: Literal[1]
99
QUOTE_MINIMAL: Literal[0]

stdlib/_decimal.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import sys
33
from collections.abc import Container, Sequence
44
from types import TracebackType
55
from typing import Any, ClassVar, NamedTuple, overload
6-
from typing_extensions import Literal, Self, TypeAlias
6+
from typing_extensions import Final, Literal, Self, TypeAlias
77

88
_Decimal: TypeAlias = Decimal | int
99
_DecimalNew: TypeAlias = Decimal | float | str | tuple[int, Sequence[int], int]
1010
_ComparableNum: TypeAlias = Decimal | float | numbers.Rational
1111

12-
__version__: str
13-
__libmpdec_version__: str
12+
__version__: Final[str]
13+
__libmpdec_version__: Final[str]
1414

1515
class DecimalTuple(NamedTuple):
1616
sign: int

stdlib/_heapq.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from typing import Any, TypeVar
2+
from typing_extensions import Final
23

34
_T = TypeVar("_T")
45

5-
__about__: str
6+
__about__: Final[str]
67

78
def heapify(__heap: list[Any]) -> None: ...
89
def heappop(__heap: list[_T]) -> _T: ...

stdlib/cgitb.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ from _typeshed import OptExcInfo, StrOrBytesPath
22
from collections.abc import Callable
33
from types import FrameType, TracebackType
44
from typing import IO, Any
5+
from typing_extensions import Final
56

6-
__UNDEF__: object # undocumented sentinel
7+
__UNDEF__: Final[object] # undocumented sentinel
78

89
def reset() -> str: ... # undocumented
910
def small(text: str) -> str: ... # undocumented

stdlib/heapq.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ from _heapq import *
22
from _typeshed import SupportsRichComparison
33
from collections.abc import Callable, Iterable
44
from typing import Any, TypeVar
5+
from typing_extensions import Final
56

67
__all__ = ["heappush", "heappop", "heapify", "heapreplace", "merge", "nlargest", "nsmallest", "heappushpop"]
78

89
_S = TypeVar("_S")
910

10-
__about__: str
11+
__about__: Final[str]
1112

1213
def merge(
1314
*iterables: Iterable[_S], key: Callable[[_S], SupportsRichComparison] | None = None, reverse: bool = False

stdlib/pydoc.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ from collections.abc import Callable, Container, Mapping, MutableMapping
66
from reprlib import Repr
77
from types import MethodType, ModuleType, TracebackType
88
from typing import IO, Any, AnyStr, NoReturn, TypeVar
9-
from typing_extensions import TypeGuard
9+
from typing_extensions import Final, TypeGuard
1010

1111
__all__ = ["help"]
1212

1313
_T = TypeVar("_T")
1414

15-
__author__: str
16-
__date__: str
17-
__version__: str
18-
__credits__: str
15+
__author__: Final[str]
16+
__date__: Final[str]
17+
__version__: Final[str]
18+
__credits__: Final[str]
1919

2020
def pathdirs() -> list[str]: ...
2121
def getdoc(object: object) -> str: ...

stdlib/sys.pyi

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ from importlib.machinery import ModuleSpec
77
from io import TextIOWrapper
88
from types import FrameType, ModuleType, TracebackType
99
from typing import Any, NoReturn, Protocol, TextIO, TypeVar, overload
10-
from typing_extensions import Literal, TypeAlias, final
10+
from typing_extensions import Final, Literal, TypeAlias, final
1111

1212
_T = TypeVar("_T")
1313

@@ -62,9 +62,10 @@ stdout: TextIO
6262
stderr: TextIO
6363
if sys.version_info >= (3, 10):
6464
stdlib_module_names: frozenset[str]
65-
__stdin__: TextIOWrapper
66-
__stdout__: TextIOWrapper
67-
__stderr__: TextIOWrapper
65+
66+
__stdin__: Final[TextIOWrapper] # Contains the original value of stdin
67+
__stdout__: Final[TextIOWrapper] # Contains the original value of stdout
68+
__stderr__: Final[TextIOWrapper] # Contains the original value of stderr
6869
tracebacklimit: int
6970
version: str
7071
api_version: int
@@ -277,11 +278,10 @@ if sys.platform == "win32":
277278

278279
def intern(__string: str) -> str: ...
279280
def is_finalizing() -> bool: ...
280-
281-
__breakpointhook__: Any # contains the original value of breakpointhook
282-
283281
def breakpointhook(*args: Any, **kwargs: Any) -> Any: ...
284282

283+
__breakpointhook__ = breakpointhook # Contains the original value of breakpointhook
284+
285285
if sys.platform != "win32":
286286
def setdlopenflags(__flags: int) -> None: ...
287287

stdlib/unittest/mock.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ from collections.abc import Awaitable, Callable, Coroutine, Iterable, Mapping, S
33
from contextlib import _GeneratorContextManager
44
from types import TracebackType
55
from typing import Any, Generic, TypeVar, overload
6-
from typing_extensions import Literal, Self, TypeAlias
6+
from typing_extensions import Final, Literal, Self, TypeAlias
77

88
_T = TypeVar("_T")
99
_TT = TypeVar("_TT", bound=type[Any])
@@ -47,7 +47,7 @@ else:
4747
"seal",
4848
)
4949

50-
__version__: str
50+
__version__: Final[str]
5151

5252
FILTER_DIR: Any
5353

0 commit comments

Comments
 (0)