Skip to content
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

Merged
merged 12 commits into from
Feb 18, 2024
Merged

Conversation

JelleZijlstra
Copy link
Member

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.

help: str | None = None,
) -> None: ...
@overload
@deprecated("The `type`, `choices`, and `metavar` parameters are ignored and will be removed in Python 3.14.")
Copy link
Member Author

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,
Copy link
Member Author

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.

@@ -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")
Copy link
Member Author

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.

Copy link
Member

@AlexWaygood AlexWaygood Nov 10, 2023

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.

Copy link
Member Author

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+

@@ -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.")
Copy link
Member Author

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)")
Copy link
Member Author

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.

@@ -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.")
Copy link
Member Author

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.")
Copy link
Member Author

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.

@@ -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.")
Copy link
Member Author

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.")
Copy link
Member Author

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.")
Copy link
Member Author

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.

@JelleZijlstra
Copy link
Member Author

Seems like I managed to crash stubtest, I'll have to debug

This comment has been minimized.

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Nov 10, 2023

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

@AlexWaygood
Copy link
Member

Seems like I managed to crash stubtest, I'll have to debug

Same traceback as python/mypy#14950

@AlexWaygood
Copy link
Member

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)")
Copy link
Member

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...)

Copy link
Collaborator

@hauntsaninja hauntsaninja Nov 10, 2023

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

Copy link
Member

@AlexWaygood AlexWaygood left a 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

hauntsaninja added a commit to hauntsaninja/mypy that referenced this pull request Nov 11, 2023
We should probably lean into the type checker harder here

Fixes python#14950
Fixes python/typeshed#11009 (comment)
@hauntsaninja hauntsaninja reopened this Nov 11, 2023

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link
Member

@AlexWaygood AlexWaygood left a 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

@JelleZijlstra
Copy link
Member Author

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.

@JelleZijlstra JelleZijlstra added the status: deferred Issue or PR deferred until some precondition is fixed label Nov 18, 2023

This comment has been minimized.

This comment has been minimized.

@AlexWaygood AlexWaygood removed the status: deferred Issue or PR deferred until some precondition is fixed label Dec 22, 2023

This comment has been minimized.

@AlexWaygood
Copy link
Member

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.

Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra JelleZijlstra merged commit bba8cbd into python:main Feb 18, 2024
65 checks passed
@JelleZijlstra JelleZijlstra deleted the deprecations branch February 18, 2024 14:50
@JelleZijlstra JelleZijlstra restored the deprecations branch September 10, 2024 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants