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
Fix usage of @deprecated
#8294
Merged
sydney-runkle
merged 13 commits into
pydantic:main
from
Viicos:fix-deprecated-decorators
Jan 9, 2024
Merged
Fix usage of @deprecated
#8294
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4d905ce
Fix usage of `@deprecated`
Viicos 4d4f35a
Remove missed calls
Viicos a266b9c
Some fixes
Viicos 4f59a92
more fixes
Viicos 0fad7d0
Final fixes
Viicos c52a122
Missed one
Viicos f708504
Fix filter match
Viicos 77ba925
Use `overload` from `typing_extensions`
Viicos c300dba
Revert change on overload
Viicos f2670bd
Remove assert
Viicos b791cc0
lint and update typing-extensions
Viicos a7b9620
Restore runtime warnings, set decorator category to None
Viicos 215e8b7
last fixes
Viicos File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 reason we have this warning is actually because this is how PyCharm decides how to show the strikethrough for deprecated attributes:
If this line is removed, PyCharm stops showing the strikethrough on usage, even after updating
typing_extensions
.If there are downsides to having both I'm happy to try to resolve it but I think showing the deprecated stuff as deprecated in PyCharm is a significant benefit, considering we are trying to advise people against using deprecated stuff anyway (so I don't mind terribly if it emits two warnings, unless there is some significant downside to that).
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.
Sure thing I can add back the warning for properties, and as a workaround set
category=None
in the decorator to avoid having the warning emitted twice.However, this is most likely an issue with PyCharm. Do you happen to know if there's an already existing issue tracking this?
The recently defined typing spec states properties should also be marked as deprecated by type checkers (see provided example).
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.
Yeah it's definitely a PyCharm issue — I found this in their issue tracker https://youtrack.jetbrains.com/issue/PY-61651/Deprecation-highlighting-with-PEP-702-deprecated-decorator and added a comment on it about our usage within Pydantic.
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.
@dmontagu, is this also the case for standard methods/functions, or is it only the not working for properties?
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 for everything not just properties
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.
Ok, then I will add back the actual
warn
calls, and usecategory=None
on the decorator. I can also create an issue to remind us to remove them again once PyCharm will have implemented support for the decorator.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.
@Viicos,
That would be fantastic if you could create an issue as a reminder for us to remove the
warn
callsThere 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.
Sure thing: #8524