-
-
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
Conversation
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 comment
The 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 | str | None = None, | ||
default: bool | None = None, |
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.
stdlib/asyncio/events.pyi
Outdated
@@ -599,8 +599,10 @@ class AbstractEventLoopPolicy: | |||
def new_event_loop(self) -> AbstractEventLoop: ... | |||
# Child processes handling (Unix only). | |||
@abstractmethod | |||
@deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14") |
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.
Wasn't sure about these child watchers as it's not clear to me what if anything they should be replaced with. Possibly we should emit the warning on 3.12+ only.
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.
I haven't looked at this in detail, but in situations like this where we're not sure, I feel like we should probably err on the side of caution and only emit warnings on py312+. For this one, it would be good to ping an asyncio expert and see what they think, though.
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.
Changed this to warn only on 3.12+
stdlib/builtins.pyi
Outdated
@@ -937,6 +938,8 @@ class bool(int): | |||
@overload | |||
def __rxor__(self, __value: int) -> int: ... | |||
def __getnewargs__(self) -> tuple[int]: ... | |||
@deprecated("Will throw an error in Python 3.14. Use `not` for logical negation of bools instead.") |
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.
This is ~True
. It always behaved confusingly, so it seems fine to warn about it on all versions.
@@ -265,6 +265,7 @@ 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 comment
The 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.
stdlib/pkgutil.pyi
Outdated
@@ -35,8 +36,10 @@ if sys.version_info < (3, 12): | |||
class ImpLoader: | |||
def __init__(self, fullname: str, file: IO[str], filename: str, etc: tuple[str, str, int]) -> None: ... | |||
|
|||
@deprecated("Use importlib.util.find_spec() instead. Will be removed in Python 3.14.") |
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.
find_spec()
is apparently available on all supported versions.
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 comment
The 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.
stdlib/tarfile.pyi
Outdated
@@ -292,22 +292,45 @@ class TarFile: | |||
def list(self, verbose: bool = True, *, members: _list[TarInfo] | None = None) -> None: ... | |||
def next(self) -> TarInfo | None: ... | |||
if sys.version_info >= (3, 8): | |||
@overload | |||
@deprecated("Extracting tar archives without specifying `filter` is deprecated until Python 3.14, when 'data' filter will become the default.") |
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.
This was backported all the way back, so seems fair to also emit the warning.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
co_lines() is only in 3.10+.
@@ -124,6 +124,8 @@ class Element: | |||
def __setitem__(self, __key: SupportsIndex, __value: Element) -> None: ... | |||
@overload | |||
def __setitem__(self, __key: slice, __value: Iterable[Element]) -> None: ... | |||
@deprecated("Testing an element's truth value is deprecated.") |
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.
This always behaved confusingly (and raised a FutureWarning under some circumstances), so seems fine to always warn.
Seems like I managed to crash stubtest, I'll have to debug |
This comment has been minimized.
This comment has been minimized.
stubtest doesn't have great decorator support, it just hardcodes a few decorators. And looks like because it hardcoded overload, it expects to know how overload works |
Same traceback as python/mypy#14950 |
Looks like deprecating a property also breaks pytype :/ |
@@ -278,6 +279,7 @@ class datetime(date): | |||
def now(cls, tz: _TzInfo) -> datetime: ... | |||
|
|||
@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 comment
The 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 comment
The 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
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.
The substantive changes look pretty good to me; just have some qualms about datetime
and asyncio
We should probably lean into the type checker harder here Fixes python#14950 Fixes python/typeshed#11009 (comment)
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
LGTM. The ones that combine @overload
with @deprecated
will probably have to wait until mypy 1.8 is released, though, due to the stubtest crashes
Ah right, forgot we already fixed that. There is also at least one other pytype crash. I might open another PR with the simpler ones and keep this one open to merge later. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This is no longer deferred; stubtest no longer crashes on this with the latest mypy. There are still a few "regular" stubtest failures, however |
This comment has been minimized.
This comment has been minimized.
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
I went through the list in https://docs.python.org/3.12/whatsnew/3.12.html#deprecated and added
@deprecated
in all cases where it seemed practical. I hope this will give more useful input for #11002.I'll comment below on the individual deprecations.