-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
stdlib: more deprecations #11009
stdlib: more deprecations #11009
Changes from all commits
620109c
60119d6
c23c876
367104a
372fa73
c313169
25cf5a7
c338052
158773e
592a5f3
e451001
62853a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ from _typeshed import sentinel | |
from collections.abc import Callable, Generator, Iterable, Sequence | ||
from re import Pattern | ||
from typing import IO, Any, Generic, Literal, NewType, NoReturn, Protocol, TypeVar, overload | ||
from typing_extensions import Self, TypeAlias | ||
from typing_extensions import Self, TypeAlias, deprecated | ||
|
||
__all__ = [ | ||
"ArgumentParser", | ||
|
@@ -339,11 +339,23 @@ class Action(_AttributeHolder): | |
|
||
if sys.version_info >= (3, 12): | ||
class BooleanOptionalAction(Action): | ||
@overload | ||
def __init__( | ||
self, | ||
option_strings: Sequence[str], | ||
dest: str, | ||
default: _T | str | None = None, | ||
default: bool | None = None, | ||
*, | ||
required: bool = False, | ||
help: str | None = None, | ||
) -> None: ... | ||
@overload | ||
@deprecated("The `type`, `choices`, and `metavar` parameters are ignored and will be removed in Python 3.14.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These apparently never did anything useful, so it seems fair to emit the warning on all versions. |
||
def __init__( | ||
self, | ||
option_strings: Sequence[str], | ||
dest: str, | ||
default: _T | bool | None = None, | ||
type: Callable[[str], _T] | FileType | None = sentinel, | ||
choices: Iterable[_T] | None = sentinel, | ||
required: bool = False, | ||
|
@@ -353,11 +365,23 @@ if sys.version_info >= (3, 12): | |
|
||
elif sys.version_info >= (3, 9): | ||
class BooleanOptionalAction(Action): | ||
@overload | ||
def __init__( | ||
self, | ||
option_strings: Sequence[str], | ||
dest: str, | ||
default: bool | None = None, | ||
*, | ||
required: bool = False, | ||
help: str | None = None, | ||
) -> None: ... | ||
@overload | ||
@deprecated("The `type`, `choices`, and `metavar` parameters are ignored and will be removed in Python 3.14.") | ||
def __init__( | ||
self, | ||
option_strings: Sequence[str], | ||
dest: str, | ||
default: _T | str | None = None, | ||
default: _T | bool | None = None, | ||
type: Callable[[str], _T] | FileType | None = None, | ||
choices: Iterable[_T] | None = None, | ||
required: bool = False, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import sys | |
from abc import abstractmethod | ||
from time import struct_time | ||
from typing import ClassVar, Literal, NamedTuple, NoReturn, SupportsIndex, TypeVar, final, overload | ||
from typing_extensions import Self, TypeAlias | ||
from typing_extensions import Self, TypeAlias, deprecated | ||
|
||
if sys.version_info >= (3, 11): | ||
__all__ = ("date", "datetime", "time", "timedelta", "timezone", "tzinfo", "MINYEAR", "MAXYEAR", "UTC") | ||
|
@@ -251,10 +251,12 @@ class datetime(date): | |
def fromtimestamp(cls, __timestamp: float, tz: _TzInfo | None = ...) -> Self: ... | ||
|
||
@classmethod | ||
@deprecated("Use timezone-aware objects to represent datetimes in UTC; e.g. by calling .fromtimestamp(datetime.UTC)") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This and utcnow() were always mildly discouraged and the replacement has always been available, so chose to deprecate across versions. |
||
def utcfromtimestamp(cls, __t: float) -> Self: ... | ||
@classmethod | ||
def now(cls, tz: _TzInfo | None = None) -> Self: ... | ||
@classmethod | ||
@deprecated("Use timezone-aware objects to represent datetimes in UTC; e.g. by calling .now(datetime.UTC)") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about this one. It may have always been discouraged to use this method, but I think the deprecation has been pretty disruptive — see https://discuss.python.org/t/deprecating-utcnow-and-utcfromtimestamp/26221/12?u=alexwaygood. For Python 3.8 users, the method is still going to be around for a while; do we need to bother them with this warning just yet? (On the other hand: if the method is widely used, perhaps it's all the more important to make sure the word gets out that it's deprecated...) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's worth it. Work had a bug just this week because someone was using these (and spoiler, we're not on 3.12). Also I think it will be like eight years before CPython removes it, I'd definitely oppose removing it in 3.14 |
||
def utcnow(cls) -> Self: ... | ||
@classmethod | ||
def combine(cls, date: _Date, time: _Time, tzinfo: _TzInfo | None = ...) -> Self: ... | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ from _typeshed import Unused | |
from email import _ParamType | ||
from email.charset import Charset | ||
from typing import overload | ||
from typing_extensions import TypeAlias | ||
from typing_extensions import TypeAlias, deprecated | ||
|
||
__all__ = [ | ||
"collapse_rfc2231_value", | ||
|
@@ -54,6 +54,10 @@ def formatdate(timeval: float | None = None, localtime: bool = False, usegmt: bo | |
def format_datetime(dt: datetime.datetime, usegmt: bool = False) -> str: ... | ||
|
||
if sys.version_info >= (3, 12): | ||
@overload | ||
def localtime(dt: datetime.datetime | None = None) -> datetime.datetime: ... | ||
@overload | ||
@deprecated("The `isdst` parameter does nothing and will be removed in Python 3.14.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
def localtime(dt: datetime.datetime | None = None, isdst: Unused = None) -> datetime.datetime: ... | ||
|
||
else: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ from typing import ( | |
overload, | ||
runtime_checkable, | ||
) | ||
from typing_extensions import Self, TypeAlias, Unpack | ||
from typing_extensions import Self, TypeAlias, Unpack, deprecated | ||
|
||
from . import path as _path | ||
|
||
|
@@ -361,8 +361,16 @@ class stat_result(structseq[float], tuple[int, int, int, int, int, int, int, flo | |
@property | ||
def st_mtime(self) -> float: ... # time of most recent content modification, | ||
# platform dependent (time of most recent metadata change on Unix, or the time of creation on Windows) | ||
@property | ||
def st_ctime(self) -> float: ... | ||
if sys.version_info >= (3, 12) and sys.platform == "win32": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The replacement |
||
@property | ||
@deprecated( | ||
"Use st_birthtime instead to retrieve the file creation time. In the future, this property will contain the last metadata change time." | ||
) | ||
def st_ctime(self) -> float: ... | ||
else: | ||
@property | ||
def st_ctime(self) -> float: ... | ||
|
||
@property | ||
def st_atime_ns(self) -> int: ... # time of most recent access, in nanoseconds | ||
@property | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ from _typeshed import BytesPath, FileDescriptorOrPath, StrOrBytesPath, StrPath, | |
from collections.abc import Callable, Iterable, Sequence | ||
from tarfile import _TarfileFilter | ||
from typing import Any, AnyStr, NamedTuple, Protocol, TypeVar, overload | ||
from typing_extensions import TypeAlias | ||
from typing_extensions import TypeAlias, deprecated | ||
|
||
__all__ = [ | ||
"copyfileobj", | ||
|
@@ -78,24 +78,20 @@ class _RmtreeType(Protocol): | |
avoids_symlink_attacks: bool | ||
if sys.version_info >= (3, 12): | ||
@overload | ||
def __call__(self, path: StrOrBytesPath, ignore_errors: bool = False, *, dir_fd: int | None = None) -> None: ... | ||
@overload | ||
@deprecated("The `onerror` parameter is deprecated and will be removed in Python 3.14. Use `onexc` instead.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the new parameter is only available on 3.12+, applied the warning on 3.12+ only. |
||
def __call__( | ||
self, | ||
path: StrOrBytesPath, | ||
ignore_errors: bool = False, | ||
onerror: _OnErrorCallback | None = None, | ||
*, | ||
onexc: None = None, | ||
dir_fd: int | None = None, | ||
) -> None: ... | ||
@overload | ||
def __call__( | ||
self, | ||
path: StrOrBytesPath, | ||
ignore_errors: bool = False, | ||
onerror: None = None, | ||
*, | ||
onexc: _OnExcCallback, | ||
dir_fd: int | None = None, | ||
self, path: StrOrBytesPath, ignore_errors: bool = False, *, onexc: _OnExcCallback, dir_fd: int | None = None | ||
) -> None: ... | ||
elif sys.version_info >= (3, 11): | ||
def __call__( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ from importlib.machinery import ModuleSpec | |
|
||
# pytype crashes if types.MappingProxyType inherits from collections.abc.Mapping instead of typing.Mapping | ||
from typing import Any, ClassVar, Literal, Mapping, Protocol, TypeVar, final, overload # noqa: Y022 | ||
from typing_extensions import ParamSpec, Self, TypeVarTuple | ||
from typing_extensions import ParamSpec, Self, TypeVarTuple, deprecated | ||
|
||
__all__ = [ | ||
"FunctionType", | ||
|
@@ -138,8 +138,14 @@ class CodeType: | |
def co_name(self) -> str: ... | ||
@property | ||
def co_firstlineno(self) -> int: ... | ||
@property | ||
def co_lnotab(self) -> bytes: ... | ||
if sys.version_info >= (3, 10): | ||
@property | ||
@deprecated("Will be removed in Python 3.14. Use the co_lines() method instead.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. co_lines() is only in 3.10+. |
||
def co_lnotab(self) -> bytes: ... | ||
else: | ||
@property | ||
def co_lnotab(self) -> bytes: ... | ||
|
||
@property | ||
def co_freevars(self) -> tuple[str, ...]: ... | ||
@property | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ from _collections_abc import dict_keys | |
from _typeshed import FileDescriptorOrPath, ReadableBuffer, SupportsRead, SupportsWrite | ||
from collections.abc import Callable, Generator, ItemsView, Iterable, Iterator, Mapping, Sequence | ||
from typing import Any, Literal, SupportsIndex, TypeVar, overload | ||
from typing_extensions import TypeAlias, TypeGuard | ||
from typing_extensions import TypeAlias, TypeGuard, deprecated | ||
|
||
__all__ = [ | ||
"C14NWriterTarget", | ||
|
@@ -121,6 +121,10 @@ class Element: | |
def __setitem__(self, __key: SupportsIndex, __value: Element) -> None: ... | ||
@overload | ||
def __setitem__(self, __key: slice, __value: Iterable[Element]) -> None: ... | ||
|
||
# Doesn't really exist in earlier versions, where __len__ is called implicitly instead | ||
@deprecated("Testing an element's truth value is deprecated.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This always behaved confusingly (and raised a FutureWarning under some circumstances), so seems fine to always warn. |
||
def __bool__(self) -> bool: ... | ||
if sys.version_info < (3, 9): | ||
def getchildren(self) -> list[Element]: ... | ||
def getiterator(self, tag: str | None = None) -> list[Element]: ... | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears that a non-bool default doesn't really make sense on this action.