Skip to content

Commit 9a77f60

Browse files
authored
Use Final for undocumented constants (#12450)
1 parent 1f4d0a8 commit 9a77f60

File tree

10 files changed

+60
-61
lines changed

10 files changed

+60
-61
lines changed

stdlib/_osx_support.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
from collections.abc import Iterable, Sequence
2-
from typing import TypeVar
2+
from typing import Final, TypeVar
33

44
_T = TypeVar("_T")
55
_K = TypeVar("_K")
66
_V = TypeVar("_V")
77

88
__all__ = ["compiler_fixup", "customize_config_vars", "customize_compiler", "get_platform_osx"]
99

10-
_UNIVERSAL_CONFIG_VARS: tuple[str, ...] # undocumented
11-
_COMPILER_CONFIG_VARS: tuple[str, ...] # undocumented
12-
_INITPRE: str # undocumented
10+
_UNIVERSAL_CONFIG_VARS: Final[tuple[str, ...]] # undocumented
11+
_COMPILER_CONFIG_VARS: Final[tuple[str, ...]] # undocumented
12+
_INITPRE: Final[str] # undocumented
1313

1414
def _find_executable(executable: str, path: str | None = None) -> str | None: ... # undocumented
1515
def _read_output(commandstring: str, capture_stderr: bool = False) -> str | None: ... # undocumented
1616
def _find_build_tool(toolname: str) -> str: ... # undocumented
1717

18-
_SYSTEM_VERSION: str | None # undocumented
18+
_SYSTEM_VERSION: Final[str | None] # undocumented
1919

2020
def _get_system_version() -> str: ... # undocumented
2121
def _remove_original_values(_config_vars: dict[str, str]) -> None: ... # undocumented

stdlib/argparse.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ _SUPPRESS_T = NewType("_SUPPRESS_T", str)
5151
SUPPRESS: _SUPPRESS_T | str # not using Literal because argparse sometimes compares SUPPRESS with is
5252
# the | str is there so that foo = argparse.SUPPRESS; foo = "test" checks out in mypy
5353
ZERO_OR_MORE: Final = "*"
54-
_UNRECOGNIZED_ARGS_ATTR: str # undocumented
54+
_UNRECOGNIZED_ARGS_ATTR: Final[str] # undocumented
5555

5656
class ArgumentError(Exception):
5757
argument_name: str | None

stdlib/email/charset.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from collections.abc import Callable, Iterator
22
from email.message import Message
3-
from typing import overload
3+
from typing import Final, overload
44

55
__all__ = ["Charset", "add_alias", "add_charset", "add_codec"]
66

7-
QP: int # undocumented
8-
BASE64: int # undocumented
9-
SHORTEST: int # undocumented
7+
QP: Final[int] # undocumented
8+
BASE64: Final[int] # undocumented
9+
SHORTEST: Final[int] # undocumented
1010

1111
class Charset:
1212
input_charset: str

stdlib/gzip.pyi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import sys
33
import zlib
44
from _typeshed import ReadableBuffer, SizedBuffer, StrOrBytesPath
55
from io import FileIO
6-
from typing import Literal, Protocol, TextIO, overload
6+
from typing import Final, Literal, Protocol, TextIO, overload
77
from typing_extensions import TypeAlias
88

99
__all__ = ["BadGzipFile", "GzipFile", "open", "compress", "decompress"]
@@ -12,14 +12,14 @@ _ReadBinaryMode: TypeAlias = Literal["r", "rb"]
1212
_WriteBinaryMode: TypeAlias = Literal["a", "ab", "w", "wb", "x", "xb"]
1313
_OpenTextMode: TypeAlias = Literal["rt", "at", "wt", "xt"]
1414

15-
READ: object # undocumented
16-
WRITE: object # undocumented
15+
READ: Final[object] # undocumented
16+
WRITE: Final[object] # undocumented
1717

18-
FTEXT: int # actually Literal[1] # undocumented
19-
FHCRC: int # actually Literal[2] # undocumented
20-
FEXTRA: int # actually Literal[4] # undocumented
21-
FNAME: int # actually Literal[8] # undocumented
22-
FCOMMENT: int # actually Literal[16] # undocumented
18+
FTEXT: Final[int] # actually Literal[1] # undocumented
19+
FHCRC: Final[int] # actually Literal[2] # undocumented
20+
FEXTRA: Final[int] # actually Literal[4] # undocumented
21+
FNAME: Final[int] # actually Literal[8] # undocumented
22+
FCOMMENT: Final[int] # actually Literal[16] # undocumented
2323

2424
class _ReadableFileobj(Protocol):
2525
def read(self, n: int, /) -> bytes: ...

stdlib/logging/config.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ from collections.abc import Callable, Hashable, Iterable, Sequence
44
from configparser import RawConfigParser
55
from re import Pattern
66
from threading import Thread
7-
from typing import IO, Any, Literal, SupportsIndex, TypedDict, overload
7+
from typing import IO, Any, Final, Literal, SupportsIndex, TypedDict, overload
88
from typing_extensions import Required, TypeAlias
99

1010
from . import Filter, Filterer, Formatter, Handler, Logger, _FilterType, _FormatStyle, _Level
1111

1212
DEFAULT_LOGGING_CONFIG_PORT: int
13-
RESET_ERROR: int # undocumented
14-
IDENTIFIER: Pattern[str] # undocumented
13+
RESET_ERROR: Final[int] # undocumented
14+
IDENTIFIER: Final[Pattern[str]] # undocumented
1515

1616
if sys.version_info >= (3, 11):
1717
class _RootLoggerConfiguration(TypedDict, total=False):

stdlib/modulefinder.pyi

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import sys
22
from collections.abc import Container, Iterable, Iterator, Sequence
33
from types import CodeType
4-
from typing import IO, Any
4+
from typing import IO, Any, Final
55

66
if sys.version_info < (3, 11):
7-
LOAD_CONST: int # undocumented
8-
IMPORT_NAME: int # undocumented
9-
STORE_NAME: int # undocumented
10-
STORE_GLOBAL: int # undocumented
11-
STORE_OPS: tuple[int, int] # undocumented
12-
EXTENDED_ARG: int # undocumented
7+
LOAD_CONST: Final[int] # undocumented
8+
IMPORT_NAME: Final[int] # undocumented
9+
STORE_NAME: Final[int] # undocumented
10+
STORE_GLOBAL: Final[int] # undocumented
11+
STORE_OPS: Final[tuple[int, int]] # undocumented
12+
EXTENDED_ARG: Final[int] # undocumented
1313

1414
packagePathMap: dict[str, list[str]] # undocumented
1515

stdlib/pyexpat/__init__.pyi

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from _typeshed import ReadableBuffer, SupportsRead
22
from collections.abc import Callable
33
from pyexpat import errors as errors, model as model
4-
from typing import Any, final
4+
from typing import Any, Final, final
55
from typing_extensions import TypeAlias
66

7-
EXPAT_VERSION: str # undocumented
7+
EXPAT_VERSION: Final[str] # undocumented
88
version_info: tuple[int, int, int] # undocumented
99
native_encoding: str # undocumented
1010
features: list[tuple[str, int]] # undocumented
@@ -15,7 +15,6 @@ class ExpatError(Exception):
1515
offset: int
1616

1717
error = ExpatError
18-
1918
XML_PARAM_ENTITY_PARSING_NEVER: int
2019
XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE: int
2120
XML_PARAM_ENTITY_PARSING_ALWAYS: int

stdlib/subprocess.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import sys
22
from _typeshed import ReadableBuffer, StrOrBytesPath
33
from collections.abc import Callable, Collection, Iterable, Mapping, Sequence
44
from types import TracebackType
5-
from typing import IO, Any, AnyStr, Generic, Literal, TypeVar, overload
5+
from typing import IO, Any, AnyStr, Final, Generic, Literal, TypeVar, overload
66
from typing_extensions import Self, TypeAlias
77

88
if sys.version_info >= (3, 9):
@@ -74,8 +74,8 @@ _T = TypeVar("_T")
7474

7575
# These two are private but documented
7676
if sys.version_info >= (3, 11):
77-
_USE_VFORK: bool
78-
_USE_POSIX_SPAWN: bool
77+
_USE_VFORK: Final[bool]
78+
_USE_POSIX_SPAWN: Final[bool]
7979

8080
class CompletedProcess(Generic[_T]):
8181
# morally: _CMD
@@ -1810,9 +1810,9 @@ else:
18101810
text: bool | None = None,
18111811
) -> Any: ... # morally: -> str | bytes
18121812

1813-
PIPE: int
1814-
STDOUT: int
1815-
DEVNULL: int
1813+
PIPE: Final[int]
1814+
STDOUT: Final[int]
1815+
DEVNULL: Final[int]
18161816

18171817
class SubprocessError(Exception): ...
18181818

stdlib/tty.pyi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
import termios
3-
from typing import IO
3+
from typing import IO, Final
44
from typing_extensions import TypeAlias
55

66
if sys.platform != "win32":
@@ -15,13 +15,13 @@ if sys.platform != "win32":
1515
_FD: TypeAlias = int | IO[str]
1616

1717
# XXX: Undocumented integer constants
18-
IFLAG: int
19-
OFLAG: int
20-
CFLAG: int
21-
LFLAG: int
22-
ISPEED: int
23-
OSPEED: int
24-
CC: int
18+
IFLAG: Final[int]
19+
OFLAG: Final[int]
20+
CFLAG: Final[int]
21+
LFLAG: Final[int]
22+
ISPEED: Final[int]
23+
OSPEED: Final[int]
24+
CC: Final[int]
2525
def setraw(fd: _FD, when: int = 2) -> _ModeSetterReturn: ...
2626
def setcbreak(fd: _FD, when: int = 2) -> _ModeSetterReturn: ...
2727

stdlib/xmlrpc/client.pyi

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ from collections.abc import Callable, Iterable, Mapping
66
from datetime import datetime
77
from io import BytesIO
88
from types import TracebackType
9-
from typing import Any, Literal, Protocol, overload
9+
from typing import Any, Final, Literal, Protocol, overload
1010
from typing_extensions import Self, TypeAlias
1111

1212
class _SupportsTimeTuple(Protocol):
@@ -34,22 +34,22 @@ _HostType: TypeAlias = tuple[str, dict[str, str]] | str
3434

3535
def escape(s: str) -> str: ... # undocumented
3636

37-
MAXINT: int # undocumented
38-
MININT: int # undocumented
37+
MAXINT: Final[int] # undocumented
38+
MININT: Final[int] # undocumented
3939

40-
PARSE_ERROR: int # undocumented
41-
SERVER_ERROR: int # undocumented
42-
APPLICATION_ERROR: int # undocumented
43-
SYSTEM_ERROR: int # undocumented
44-
TRANSPORT_ERROR: int # undocumented
40+
PARSE_ERROR: Final[int] # undocumented
41+
SERVER_ERROR: Final[int] # undocumented
42+
APPLICATION_ERROR: Final[int] # undocumented
43+
SYSTEM_ERROR: Final[int] # undocumented
44+
TRANSPORT_ERROR: Final[int] # undocumented
4545

46-
NOT_WELLFORMED_ERROR: int # undocumented
47-
UNSUPPORTED_ENCODING: int # undocumented
48-
INVALID_ENCODING_CHAR: int # undocumented
49-
INVALID_XMLRPC: int # undocumented
50-
METHOD_NOT_FOUND: int # undocumented
51-
INVALID_METHOD_PARAMS: int # undocumented
52-
INTERNAL_ERROR: int # undocumented
46+
NOT_WELLFORMED_ERROR: Final[int] # undocumented
47+
UNSUPPORTED_ENCODING: Final[int] # undocumented
48+
INVALID_ENCODING_CHAR: Final[int] # undocumented
49+
INVALID_XMLRPC: Final[int] # undocumented
50+
METHOD_NOT_FOUND: Final[int] # undocumented
51+
INVALID_METHOD_PARAMS: Final[int] # undocumented
52+
INTERNAL_ERROR: Final[int] # undocumented
5353

5454
class Error(Exception): ...
5555

@@ -98,7 +98,7 @@ class Binary:
9898

9999
def _binary(data: ReadableBuffer) -> Binary: ... # undocumented
100100

101-
WRAPPERS: tuple[type[DateTime], type[Binary]] # undocumented
101+
WRAPPERS: Final[tuple[type[DateTime], type[Binary]]] # undocumented
102102

103103
class ExpatParser: # undocumented
104104
def __init__(self, target: Unmarshaller) -> None: ...

0 commit comments

Comments
 (0)