Skip to content

Commit 0a3d8d2

Browse files
authored
Drop Python 3.8 support in os and sys (#13764)
1 parent b266f3e commit 0a3d8d2

File tree

2 files changed

+33
-69
lines changed

2 files changed

+33
-69
lines changed

stdlib/os/__init__.pyi

Lines changed: 32 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ from builtins import OSError
2424
from collections.abc import Callable, Iterable, Iterator, Mapping, MutableMapping, Sequence
2525
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper
2626
from subprocess import Popen
27-
from types import TracebackType
27+
from types import GenericAlias, TracebackType
2828
from typing import (
2929
IO,
3030
Any,
@@ -44,9 +44,6 @@ from typing_extensions import Self, TypeAlias, Unpack, deprecated
4444

4545
from . import path as _path
4646

47-
if sys.version_info >= (3, 9):
48-
from types import GenericAlias
49-
5047
__all__ = [
5148
"F_OK",
5249
"O_APPEND",
@@ -155,14 +152,14 @@ __all__ = [
155152
"umask",
156153
"uname_result",
157154
"unlink",
155+
"unsetenv",
158156
"urandom",
159157
"utime",
160158
"waitpid",
159+
"waitstatus_to_exitcode",
161160
"walk",
162161
"write",
163162
]
164-
if sys.version_info >= (3, 9):
165-
__all__ += ["waitstatus_to_exitcode"]
166163
if sys.platform == "darwin" and sys.version_info >= (3, 12):
167164
__all__ += ["PRIO_DARWIN_BG", "PRIO_DARWIN_NONUI", "PRIO_DARWIN_PROCESS", "PRIO_DARWIN_THREAD"]
168165
if sys.platform == "darwin" and sys.version_info >= (3, 10):
@@ -194,6 +191,7 @@ if sys.platform == "linux":
194191
"O_PATH",
195192
"O_RSYNC",
196193
"O_TMPFILE",
194+
"P_PIDFD",
197195
"RTLD_DEEPBIND",
198196
"SCHED_BATCH",
199197
"SCHED_IDLE",
@@ -206,6 +204,7 @@ if sys.platform == "linux":
206204
"getxattr",
207205
"listxattr",
208206
"memfd_create",
207+
"pidfd_open",
209208
"removexattr",
210209
"setxattr",
211210
]
@@ -256,8 +255,6 @@ if sys.platform == "linux" and sys.version_info >= (3, 10):
256255
"eventfd_write",
257256
"splice",
258257
]
259-
if sys.platform == "linux" and sys.version_info >= (3, 9):
260-
__all__ += ["P_PIDFD", "pidfd_open"]
261258
if sys.platform == "win32":
262259
__all__ += [
263260
"O_BINARY",
@@ -280,6 +277,8 @@ if sys.platform != "win32":
280277
"CLD_CONTINUED",
281278
"CLD_DUMPED",
282279
"CLD_EXITED",
280+
"CLD_KILLED",
281+
"CLD_STOPPED",
283282
"CLD_TRAPPED",
284283
"EX_CANTCREAT",
285284
"EX_CONFIG",
@@ -431,8 +430,6 @@ if sys.platform != "win32" and sys.version_info >= (3, 11):
431430
__all__ += ["login_tty"]
432431
if sys.platform != "win32" and sys.version_info >= (3, 10):
433432
__all__ += ["O_FSYNC"]
434-
if sys.platform != "win32" and sys.version_info >= (3, 9):
435-
__all__ += ["CLD_KILLED", "CLD_STOPPED"]
436433
if sys.platform != "darwin" and sys.platform != "win32":
437434
__all__ += [
438435
"POSIX_FADV_DONTNEED",
@@ -486,8 +483,6 @@ if sys.platform != "win32" or sys.version_info >= (3, 12):
486483
__all__ += ["get_blocking", "set_blocking"]
487484
if sys.platform != "win32" or sys.version_info >= (3, 11):
488485
__all__ += ["EX_OK"]
489-
if sys.platform != "win32" or sys.version_info >= (3, 9):
490-
__all__ += ["unsetenv"]
491486

492487
# This unnecessary alias is to work around various errors
493488
path = _path
@@ -550,7 +545,7 @@ if sys.platform != "win32":
550545
P_PGID: int
551546
P_ALL: int
552547

553-
if sys.platform == "linux" and sys.version_info >= (3, 9):
548+
if sys.platform == "linux":
554549
P_PIDFD: int
555550

556551
WEXITED: int
@@ -561,10 +556,8 @@ if sys.platform != "win32":
561556
CLD_DUMPED: int
562557
CLD_TRAPPED: int
563558
CLD_CONTINUED: int
564-
565-
if sys.version_info >= (3, 9):
566-
CLD_KILLED: int
567-
CLD_STOPPED: int
559+
CLD_KILLED: int
560+
CLD_STOPPED: int
568561

569562
SCHED_OTHER: int
570563
SCHED_FIFO: int
@@ -698,46 +691,30 @@ class _Environ(MutableMapping[AnyStr, AnyStr], Generic[AnyStr]):
698691
decodekey: _EnvironCodeFunc[AnyStr]
699692
encodevalue: _EnvironCodeFunc[AnyStr]
700693
decodevalue: _EnvironCodeFunc[AnyStr]
701-
if sys.version_info >= (3, 9):
702-
def __init__(
703-
self,
704-
data: MutableMapping[AnyStr, AnyStr],
705-
encodekey: _EnvironCodeFunc[AnyStr],
706-
decodekey: _EnvironCodeFunc[AnyStr],
707-
encodevalue: _EnvironCodeFunc[AnyStr],
708-
decodevalue: _EnvironCodeFunc[AnyStr],
709-
) -> None: ...
710-
else:
711-
putenv: Callable[[AnyStr, AnyStr], object]
712-
unsetenv: Callable[[AnyStr, AnyStr], object]
713-
def __init__(
714-
self,
715-
data: MutableMapping[AnyStr, AnyStr],
716-
encodekey: _EnvironCodeFunc[AnyStr],
717-
decodekey: _EnvironCodeFunc[AnyStr],
718-
encodevalue: _EnvironCodeFunc[AnyStr],
719-
decodevalue: _EnvironCodeFunc[AnyStr],
720-
putenv: Callable[[AnyStr, AnyStr], object],
721-
unsetenv: Callable[[AnyStr, AnyStr], object],
722-
) -> None: ...
723-
694+
def __init__(
695+
self,
696+
data: MutableMapping[AnyStr, AnyStr],
697+
encodekey: _EnvironCodeFunc[AnyStr],
698+
decodekey: _EnvironCodeFunc[AnyStr],
699+
encodevalue: _EnvironCodeFunc[AnyStr],
700+
decodevalue: _EnvironCodeFunc[AnyStr],
701+
) -> None: ...
724702
def setdefault(self, key: AnyStr, value: AnyStr) -> AnyStr: ...
725703
def copy(self) -> dict[AnyStr, AnyStr]: ...
726704
def __delitem__(self, key: AnyStr) -> None: ...
727705
def __getitem__(self, key: AnyStr) -> AnyStr: ...
728706
def __setitem__(self, key: AnyStr, value: AnyStr) -> None: ...
729707
def __iter__(self) -> Iterator[AnyStr]: ...
730708
def __len__(self) -> int: ...
731-
if sys.version_info >= (3, 9):
732-
def __or__(self, other: Mapping[_T1, _T2]) -> dict[AnyStr | _T1, AnyStr | _T2]: ...
733-
def __ror__(self, other: Mapping[_T1, _T2]) -> dict[AnyStr | _T1, AnyStr | _T2]: ...
734-
# We use @overload instead of a Union for reasons similar to those given for
735-
# overloading MutableMapping.update in stdlib/typing.pyi
736-
# The type: ignore is needed due to incompatible __or__/__ior__ signatures
737-
@overload # type: ignore[misc]
738-
def __ior__(self, other: Mapping[AnyStr, AnyStr]) -> Self: ...
739-
@overload
740-
def __ior__(self, other: Iterable[tuple[AnyStr, AnyStr]]) -> Self: ...
709+
def __or__(self, other: Mapping[_T1, _T2]) -> dict[AnyStr | _T1, AnyStr | _T2]: ...
710+
def __ror__(self, other: Mapping[_T1, _T2]) -> dict[AnyStr | _T1, AnyStr | _T2]: ...
711+
# We use @overload instead of a Union for reasons similar to those given for
712+
# overloading MutableMapping.update in stdlib/typing.pyi
713+
# The type: ignore is needed due to incompatible __or__/__ior__ signatures
714+
@overload # type: ignore[misc]
715+
def __ior__(self, other: Mapping[AnyStr, AnyStr]) -> Self: ...
716+
@overload
717+
def __ior__(self, other: Iterable[tuple[AnyStr, AnyStr]]) -> Self: ...
741718

742719
environ: _Environ[str]
743720
if sys.platform != "win32":
@@ -900,8 +877,7 @@ class DirEntry(Generic[AnyStr]):
900877
def is_symlink(self) -> bool: ...
901878
def stat(self, *, follow_symlinks: bool = True) -> stat_result: ...
902879
def __fspath__(self) -> AnyStr: ...
903-
if sys.version_info >= (3, 9):
904-
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
880+
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
905881
if sys.version_info >= (3, 12):
906882
def is_junction(self) -> bool: ...
907883

@@ -1024,9 +1000,7 @@ if sys.platform != "win32":
10241000

10251001
else:
10261002
def putenv(name: str, value: str, /) -> None: ...
1027-
1028-
if sys.version_info >= (3, 9):
1029-
def unsetenv(name: str, /) -> None: ...
1003+
def unsetenv(name: str, /) -> None: ...
10301004

10311005
_Opener: TypeAlias = Callable[[str, int], int]
10321006

@@ -1598,11 +1572,10 @@ if sys.platform == "linux":
15981572
def memfd_create(name: str, flags: int = ...) -> int: ...
15991573
def copy_file_range(src: int, dst: int, count: int, offset_src: int | None = ..., offset_dst: int | None = ...) -> int: ...
16001574

1601-
if sys.version_info >= (3, 9):
1602-
def waitstatus_to_exitcode(status: int) -> int: ...
1575+
def waitstatus_to_exitcode(status: int) -> int: ...
16031576

1604-
if sys.platform == "linux":
1605-
def pidfd_open(pid: int, flags: int = ...) -> int: ...
1577+
if sys.platform == "linux":
1578+
def pidfd_open(pid: int, flags: int = ...) -> int: ...
16061579

16071580
if sys.version_info >= (3, 12) and sys.platform == "linux":
16081581
PIDFD_NONBLOCK: Final = 2048

stdlib/sys/__init__.pyi

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ path: list[str]
4646
path_hooks: list[Callable[[str], PathEntryFinderProtocol]]
4747
path_importer_cache: dict[str, PathEntryFinderProtocol | None]
4848
platform: LiteralString
49-
if sys.version_info >= (3, 9):
50-
platlibdir: str
49+
platlibdir: str
5150
prefix: str
5251
pycache_prefix: str | None
5352
ps1: object
@@ -410,14 +409,6 @@ def setrecursionlimit(limit: int, /) -> None: ...
410409
def setswitchinterval(interval: float, /) -> None: ...
411410
def gettotalrefcount() -> int: ... # Debug builds only
412411

413-
if sys.version_info < (3, 9):
414-
def getcheckinterval() -> int: ... # deprecated
415-
def setcheckinterval(n: int, /) -> None: ... # deprecated
416-
417-
if sys.version_info < (3, 9):
418-
# An 11-tuple or None
419-
def callstats() -> tuple[int, int, int, int, int, int, int, int, int, int, int] | None: ...
420-
421412
# Doesn't exist at runtime, but exported in the stubs so pytest etc. can annotate their code more easily.
422413
@type_check_only
423414
class UnraisableHookArgs(Protocol):

0 commit comments

Comments
 (0)