-
-
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
General discussion of using @deprecated()
(from PEP 702) to signal typing-only deprecations
#12092
Comments
@deprecated
usage to signal typing-only deprecations@deprecated()
(from PEP 702) to signal typing-only deprecations
There's an interesting pair of related questions here When should deprecated be used?In the linked PR for contextmanager, the deprecated overload is incorrect (but current) and the updated version is correct and would have caught real-world bugs. Treating this as a deprecation means that tools that treat deprecations as a lower severity won't see that this is an actual bug to pass the wrong type of function to the contextmanager decorator. Using deprecated here does allow providing a custom, and likely better error message, but deprecation errors are often seen as a lower severity error to most people, something they may view as "We can fix this years later when we upgrade supported Python versions" and not "this is surfacing a bug". Some people won't see this if they use a configuration that makes those kinds of assumptions about the purpose of deprecation warnings. This leads to a few possible questions of when we could use it or things that could change to allow it to have dual use without those problems: Does this mean we shouldn't use deprecated for this? (likely means worse error messages for users) Then some overloads accurately reflect something intended as allowed by runtime, but which will be changed in the future. An example of this might be the change in How do we handle cases where making the type more accurately descriptive finds issues?Sorry if this feels like I'm picking on your contextmanager issue, especially since I think providing a useful error message here for users is the better option. It also seems like we could benefit from a clearer policy on when we can fix issues in types, as the prior attempts at this left an incorrect type in place, and the deprecated use appears to be attempting to appease people concerned about this causing churn. I'm very unwilling to call this "breaks people" unless it's truly a false positive and not a problem in their types interacting with a pre-existing problem in types or a situation where there's a special case that is specified and therefore something people should be able to rely upon. The contextmanager case is not a false positive for those getting an error. I see more value in types in the typeshed being descriptive, where the runtime behavior of the libraries and standard lib described within to be what is prescriptive, and that so long as a change is being made to put an accurate type (including |
To add my own two cents regarding the questions (mostly written before mikeshardmind's response above), here are some ideas, though I'm not solid on all of them:
EDIT: Note that these were written with typing-only deprecations in mind, not ones based on runtime deprecations. |
We have 3 options:
And at least 5 use cases:
I think this is difficult to discuss, because there's so many possible "does this option fit this use case" combinations. That said, here's how I've decided this in the past:
If we go with this approach, here's how I would answer Alex's 7 questions:
|
In an early draft of PEP 702 (which introduced If people would like a way to get custom error messages without arguably abusing |
That decorator sounds like it would be useful here and in other cases. Any chance you could point me to this version of the pep with |
I may have actually removed it before the first version of the PEP. I presented this at a typing Zoom meetup at some point: https://docs.google.com/presentation/d/1yzAh1Tok_wIk3lYo3rq1ieQp8MciVzO7pWI_m_LY30Y/edit?usp=sharing. I think the response for |
Regarding "deprecations", not general type warnings, I'll repeat my points from the other discussion with one addition: There are multiple reasons why deprecations are better than just removing functions:
The advantage of using Another advantage over runtime warnings is that For other kinds of type errors, Jelle's |
From reading the discussion, I think the consensus is to be fairly liberal when using One open question that wasn't discussed is the handling of Python versions in the stdlib. I.e. the documentation often says something like "Deprecated since Python 3.12, will be removed in Python 3.14." Do we use Here is a stab at a policy: Use
There will always be corner cases, but I think these are good first guidelines. |
We've sometimes added |
See above, I've amended the suggestion. |
Your suggested guidelines LGTM overall. I have a couple of wording nitpicks, but probably better left as PR comments; I don't object to any of the overall substance! |
Very much in favour of time travelling deprecations, as long as the replacement is available in that Python version. One other corner case: I think I wouldn't currently want type checkers to currently issue deprecation warnings by default on |
This is an attempt to centralize discussion about using
@(warnings/typing_extensions).deprecated()
in typeshed to convey "typing-only" deprecations, not just runtime-related ones. I'm currently trying to use the decorator that way in #12087, and only just now saw it brought up in another PR as well. @AlexWaygood made some good points (imo) about things to consider when using@deprecated()
with an (artificial or natural) overload this way, so I figured moving such discussion to its own dedicated thread was well warranted.I linked messages with points in favor of using
@deprecated()
this way below (because I'm too lazy right now to rephrase them into clean bullets, but it'll happen at some point):@(async)contextmanager
#12087, under "Additional Rationale", and in a later comment.Then, a few starting questions and concerns quoted from Alex (hope you don't mind):
@deprecated()
yet, so nothing will show up in mypy_primer.Hope this is useful and not just me being overzealous.
EDIT: Also including a link to a message by @Akuli in one of the comment chains mentioned earlier, which gives an example for making the choice between using
deprecated
vs. removing a function stub entirely, and what consideration can go into that.The text was updated successfully, but these errors were encountered: