Skip to content

Commit fb0940e

Browse files
donBarbosAlexWaygoodpre-commit-ci[bot]
authored
[stdlib] Deprecate old functions (#14553)
* [stdlib] Deprecate many functions * Fix typo * Imporove message for asyncio/trsock * Apply suggestions from code review Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> * Add Python before version * [pre-commit.ci] auto fixes from pre-commit.com hooks * Wrap comment lines * fix the rest --------- Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 91ba0da commit fb0940e

27 files changed

+163
-34
lines changed

stdlib/_frozen_importlib.pyi

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ from _typeshed.importlib import LoaderProtocol
66
from collections.abc import Mapping, Sequence
77
from types import ModuleType
88
from typing import Any, ClassVar
9+
from typing_extensions import deprecated
910

1011
# Signature of `builtins.__import__` should be kept identical to `importlib.__import__`
1112
def __import__(
@@ -49,6 +50,7 @@ class BuiltinImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader)
4950
# MetaPathFinder
5051
if sys.version_info < (3, 12):
5152
@classmethod
53+
@deprecated("Deprecated since Python 3.4; removed in Python 3.12. Use `find_spec()` instead.")
5254
def find_module(cls, fullname: str, path: Sequence[str] | None = None) -> importlib.abc.Loader | None: ...
5355

5456
@classmethod
@@ -67,6 +69,10 @@ class BuiltinImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader)
6769
# Loader
6870
if sys.version_info < (3, 12):
6971
@staticmethod
72+
@deprecated(
73+
"Deprecated since Python 3.4; removed in Python 3.12. "
74+
"The module spec is now used by the import machinery to generate a module repr."
75+
)
7076
def module_repr(module: types.ModuleType) -> str: ...
7177
if sys.version_info >= (3, 10):
7278
@staticmethod
@@ -83,6 +89,7 @@ class FrozenImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader):
8389
# MetaPathFinder
8490
if sys.version_info < (3, 12):
8591
@classmethod
92+
@deprecated("Deprecated since Python 3.4; removed in Python 3.12. Use `find_spec()` instead.")
8693
def find_module(cls, fullname: str, path: Sequence[str] | None = None) -> importlib.abc.Loader | None: ...
8794

8895
@classmethod
@@ -101,6 +108,10 @@ class FrozenImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader):
101108
# Loader
102109
if sys.version_info < (3, 12):
103110
@staticmethod
111+
@deprecated(
112+
"Deprecated since Python 3.4; removed in Python 3.12. "
113+
"The module spec is now used by the import machinery to generate a module repr."
114+
)
104115
def module_repr(m: types.ModuleType) -> str: ...
105116
if sys.version_info >= (3, 10):
106117
@staticmethod

stdlib/_frozen_importlib_external.pyi

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def spec_from_file_location(
4343
class WindowsRegistryFinder(importlib.abc.MetaPathFinder):
4444
if sys.version_info < (3, 12):
4545
@classmethod
46+
@deprecated("Deprecated since Python 3.4; removed in Python 3.12. Use `find_spec()` instead.")
4647
def find_module(cls, fullname: str, path: Sequence[str] | None = None) -> importlib.abc.Loader | None: ...
4748

4849
@classmethod
@@ -70,6 +71,7 @@ class PathFinder(importlib.abc.MetaPathFinder):
7071
) -> ModuleSpec | None: ...
7172
if sys.version_info < (3, 12):
7273
@classmethod
74+
@deprecated("Deprecated since Python 3.4; removed in Python 3.12. Use `find_spec()` instead.")
7375
def find_module(cls, fullname: str, path: Sequence[str] | None = None) -> importlib.abc.Loader | None: ...
7476

7577
SOURCE_SUFFIXES: list[str]
@@ -158,7 +160,10 @@ if sys.version_info >= (3, 11):
158160
def get_resource_reader(self, module: types.ModuleType) -> importlib.readers.NamespaceReader: ...
159161
if sys.version_info < (3, 12):
160162
@staticmethod
161-
@deprecated("module_repr() is deprecated, and has been removed in Python 3.12")
163+
@deprecated(
164+
"Deprecated since Python 3.4; removed in Python 3.12. "
165+
"The module spec is now used by the import machinery to generate a module repr."
166+
)
162167
def module_repr(module: types.ModuleType) -> str: ...
163168

164169
_NamespaceLoader = NamespaceLoader
@@ -176,12 +181,18 @@ else:
176181
def load_module(self, fullname: str) -> types.ModuleType: ...
177182
if sys.version_info >= (3, 10):
178183
@staticmethod
179-
@deprecated("module_repr() is deprecated, and has been removed in Python 3.12")
184+
@deprecated(
185+
"Deprecated since Python 3.4; removed in Python 3.12. "
186+
"The module spec is now used by the import machinery to generate a module repr."
187+
)
180188
def module_repr(module: types.ModuleType) -> str: ...
181189
def get_resource_reader(self, module: types.ModuleType) -> importlib.readers.NamespaceReader: ...
182190
else:
183191
@classmethod
184-
@deprecated("module_repr() is deprecated, and has been removed in Python 3.12")
192+
@deprecated(
193+
"Deprecated since Python 3.4; removed in Python 3.12. "
194+
"The module spec is now used by the import machinery to generate a module repr."
195+
)
185196
def module_repr(cls, module: types.ModuleType) -> str: ...
186197

187198
if sys.version_info >= (3, 13):

stdlib/_ssl.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ from ssl import (
1313
SSLZeroReturnError as SSLZeroReturnError,
1414
)
1515
from typing import Any, ClassVar, Final, Literal, TypedDict, final, overload, type_check_only
16-
from typing_extensions import NotRequired, Self, TypeAlias
16+
from typing_extensions import NotRequired, Self, TypeAlias, deprecated
1717

1818
_PasswordType: TypeAlias = Callable[[], str | bytes | bytearray] | str | bytes | bytearray
1919
_PCTRTT: TypeAlias = tuple[tuple[str, str], ...]
@@ -51,6 +51,7 @@ def RAND_add(string: str | ReadableBuffer, entropy: float, /) -> None: ...
5151
def RAND_bytes(n: int, /) -> bytes: ...
5252

5353
if sys.version_info < (3, 12):
54+
@deprecated("Deprecated since Python 3.6; removed in Python 3.12. Use `ssl.RAND_bytes()` instead.")
5455
def RAND_pseudo_bytes(n: int, /) -> tuple[bytes, bool]: ...
5556

5657
if sys.version_info < (3, 10):

stdlib/_tkinter.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
from collections.abc import Callable
33
from typing import Any, ClassVar, Final, final
4-
from typing_extensions import TypeAlias
4+
from typing_extensions import TypeAlias, deprecated
55

66
# _tkinter is meant to be only used internally by tkinter, but some tkinter
77
# functions e.g. return _tkinter.Tcl_Obj objects. Tcl_Obj represents a Tcl
@@ -84,6 +84,7 @@ class TkappType:
8484
def record(self, script, /): ...
8585
def setvar(self, *ags, **kwargs): ...
8686
if sys.version_info < (3, 11):
87+
@deprecated("Deprecated since Python 3.9; removed in Python 3.11. Use `splitlist()` instead.")
8788
def split(self, arg, /): ...
8889

8990
def splitlist(self, arg, /): ...

stdlib/ast.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,15 +1097,17 @@ class Constant(expr):
10971097
kind: str | None
10981098
if sys.version_info < (3, 14):
10991099
# Aliases for value, for backwards compatibility
1100-
@deprecated("Will be removed in Python 3.14; use value instead")
11011100
@property
1101+
@deprecated("Will be removed in Python 3.14. Use `value` instead.")
11021102
def n(self) -> _ConstantValue: ...
11031103
@n.setter
1104+
@deprecated("Will be removed in Python 3.14. Use `value` instead.")
11041105
def n(self, value: _ConstantValue) -> None: ...
1105-
@deprecated("Will be removed in Python 3.14; use value instead")
11061106
@property
1107+
@deprecated("Will be removed in Python 3.14. Use `value` instead.")
11071108
def s(self) -> _ConstantValue: ...
11081109
@s.setter
1110+
@deprecated("Will be removed in Python 3.14. Use `value` instead.")
11091111
def s(self, value: _ConstantValue) -> None: ...
11101112

11111113
def __init__(self, value: _ConstantValue, kind: str | None = None, **kwargs: Unpack[_Attributes]) -> None: ...

stdlib/asyncio/coroutines.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
from collections.abc import Awaitable, Callable, Coroutine
33
from typing import Any, TypeVar, overload
4-
from typing_extensions import ParamSpec, TypeGuard, TypeIs
4+
from typing_extensions import ParamSpec, TypeGuard, TypeIs, deprecated
55

66
# Keep asyncio.__all__ updated with any changes to __all__ here
77
if sys.version_info >= (3, 11):
@@ -14,6 +14,7 @@ _FunctionT = TypeVar("_FunctionT", bound=Callable[..., Any])
1414
_P = ParamSpec("_P")
1515

1616
if sys.version_info < (3, 11):
17+
@deprecated("Deprecated since Python 3.8; removed in Python 3.11. Use `async def` instead.")
1718
def coroutine(func: _FunctionT) -> _FunctionT: ...
1819

1920
@overload

stdlib/asyncio/trsock.pyi

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from builtins import type as Type # alias to avoid name clashes with property n
55
from collections.abc import Iterable
66
from types import TracebackType
77
from typing import Any, BinaryIO, NoReturn, overload
8-
from typing_extensions import TypeAlias
8+
from typing_extensions import TypeAlias, deprecated
99

1010
# These are based in socket, maybe move them out into _typeshed.pyi or such
1111
_Address: TypeAlias = socket._Address
@@ -42,53 +42,82 @@ class TransportSocket:
4242
def setblocking(self, flag: bool) -> None: ...
4343
if sys.version_info < (3, 11):
4444
def _na(self, what: str) -> None: ...
45+
@deprecated("Removed in Python 3.11")
4546
def accept(self) -> tuple[socket.socket, _RetAddress]: ...
47+
@deprecated("Removed in Python 3.11")
4648
def connect(self, address: _Address) -> None: ...
49+
@deprecated("Removed in Python 3.11")
4750
def connect_ex(self, address: _Address) -> int: ...
51+
@deprecated("Removed in Python 3.11")
4852
def bind(self, address: _Address) -> None: ...
4953
if sys.platform == "win32":
54+
@deprecated("Removed in Python 3.11")
5055
def ioctl(self, control: int, option: int | tuple[int, int, int] | bool) -> None: ...
5156
else:
57+
@deprecated("Removed in Python 3.11")
5258
def ioctl(self, control: int, option: int | tuple[int, int, int] | bool) -> NoReturn: ...
5359

60+
@deprecated("Removed in Python 3.11")
5461
def listen(self, backlog: int = ..., /) -> None: ...
62+
@deprecated("Removed in Python 3.11")
5563
def makefile(self) -> BinaryIO: ...
64+
@deprecated("Rmoved in Python 3.11")
5665
def sendfile(self, file: BinaryIO, offset: int = ..., count: int | None = ...) -> int: ...
66+
@deprecated("Removed in Python 3.11")
5767
def close(self) -> None: ...
68+
@deprecated("Removed in Python 3.11")
5869
def detach(self) -> int: ...
5970
if sys.platform == "linux":
71+
@deprecated("Removed in Python 3.11")
6072
def sendmsg_afalg(
6173
self, msg: Iterable[ReadableBuffer] = ..., *, op: int, iv: Any = ..., assoclen: int = ..., flags: int = ...
6274
) -> int: ...
6375
else:
76+
@deprecated("Removed in Python 3.11.")
6477
def sendmsg_afalg(
6578
self, msg: Iterable[ReadableBuffer] = ..., *, op: int, iv: Any = ..., assoclen: int = ..., flags: int = ...
6679
) -> NoReturn: ...
6780

81+
@deprecated("Removed in Python 3.11.")
6882
def sendmsg(
6983
self, buffers: Iterable[ReadableBuffer], ancdata: Iterable[_CMSG] = ..., flags: int = ..., address: _Address = ..., /
7084
) -> int: ...
7185
@overload
86+
@deprecated("Removed in Python 3.11.")
7287
def sendto(self, data: ReadableBuffer, address: _Address) -> int: ...
7388
@overload
89+
@deprecated("Removed in Python 3.11.")
7490
def sendto(self, data: ReadableBuffer, flags: int, address: _Address) -> int: ...
91+
@deprecated("Removed in Python 3.11.")
7592
def send(self, data: ReadableBuffer, flags: int = ...) -> int: ...
93+
@deprecated("Removed in Python 3.11.")
7694
def sendall(self, data: ReadableBuffer, flags: int = ...) -> None: ...
95+
@deprecated("Removed in Python 3.11.")
7796
def set_inheritable(self, inheritable: bool) -> None: ...
7897
if sys.platform == "win32":
98+
@deprecated("Removed in Python 3.11.")
7999
def share(self, process_id: int) -> bytes: ...
80100
else:
101+
@deprecated("Removed in Python 3.11.")
81102
def share(self, process_id: int) -> NoReturn: ...
82103

104+
@deprecated("Removed in Python 3.11.")
83105
def recv_into(self, buffer: _WriteBuffer, nbytes: int = ..., flags: int = ...) -> int: ...
106+
@deprecated("Removed in Python 3.11.")
84107
def recvfrom_into(self, buffer: _WriteBuffer, nbytes: int = ..., flags: int = ...) -> tuple[int, _RetAddress]: ...
108+
@deprecated("Removed in Python 3.11.")
85109
def recvmsg_into(
86110
self, buffers: Iterable[_WriteBuffer], ancbufsize: int = ..., flags: int = ..., /
87111
) -> tuple[int, list[_CMSG], int, Any]: ...
112+
@deprecated("Removed in Python 3.11.")
88113
def recvmsg(self, bufsize: int, ancbufsize: int = ..., flags: int = ..., /) -> tuple[bytes, list[_CMSG], int, Any]: ...
114+
@deprecated("Removed in Python 3.11.")
89115
def recvfrom(self, bufsize: int, flags: int = ...) -> tuple[bytes, _RetAddress]: ...
116+
@deprecated("Removed in Python 3.11.")
90117
def recv(self, bufsize: int, flags: int = ...) -> bytes: ...
118+
@deprecated("Removed in Python 3.11.")
91119
def __enter__(self) -> socket.socket: ...
120+
@deprecated("Removed in Python 3.11.")
92121
def __exit__(
93122
self, exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
94123
) -> None: ...

stdlib/binascii.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
from _typeshed import ReadableBuffer
3-
from typing_extensions import TypeAlias
3+
from typing_extensions import TypeAlias, deprecated
44

55
# Many functions in binascii accept buffer objects
66
# or ASCII-only strings.
@@ -20,9 +20,13 @@ def a2b_qp(data: _AsciiBuffer, header: bool = False) -> bytes: ...
2020
def b2a_qp(data: ReadableBuffer, quotetabs: bool = False, istext: bool = True, header: bool = False) -> bytes: ...
2121

2222
if sys.version_info < (3, 11):
23+
@deprecated("Deprecated since Python 3.9; removed in Python 3.11.")
2324
def a2b_hqx(data: _AsciiBuffer, /) -> bytes: ...
25+
@deprecated("Deprecated since Python 3.9; removed in Python 3.11.")
2426
def rledecode_hqx(data: ReadableBuffer, /) -> bytes: ...
27+
@deprecated("Deprecated since Python 3.9; removed in Python 3.11.")
2528
def rlecode_hqx(data: ReadableBuffer, /) -> bytes: ...
29+
@deprecated("Deprecated since Python 3.9; removed in Python 3.11.")
2630
def b2a_hqx(data: ReadableBuffer, /) -> bytes: ...
2731

2832
def crc_hqx(data: ReadableBuffer, crc: int, /) -> int: ...

stdlib/configparser.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ class BasicInterpolation(Interpolation): ...
137137
class ExtendedInterpolation(Interpolation): ...
138138

139139
if sys.version_info < (3, 13):
140+
@deprecated(
141+
"Deprecated since Python 3.2; removed in Python 3.13. Use `BasicInterpolation` or `ExtendedInterpolation` instead."
142+
)
140143
class LegacyInterpolation(Interpolation):
141144
def before_get(self, parser: _Parser, section: _SectionName, option: str, value: str, vars: _Section) -> str: ...
142145

stdlib/gettext.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,13 @@ class NullTranslations:
4444
def info(self) -> dict[str, str]: ...
4545
def charset(self) -> str | None: ...
4646
if sys.version_info < (3, 11):
47+
@deprecated("Deprecated since Python 3.8; removed in Python 3.11.")
4748
def output_charset(self) -> str | None: ...
49+
@deprecated("Deprecated since Python 3.8; removed in Python 3.11.")
4850
def set_output_charset(self, charset: str) -> None: ...
51+
@deprecated("Deprecated since Python 3.8; removed in Python 3.11. Use `gettext()` instead.")
4952
def lgettext(self, message: str) -> str: ...
53+
@deprecated("Deprecated since Python 3.8; removed in Python 3.11. Use `ngettext()` instead.")
5054
def lngettext(self, msgid1: str, msgid2: str, n: int) -> str: ...
5155

5256
def install(self, names: Container[str] | None = None) -> None: ...

0 commit comments

Comments
 (0)