-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add typing for internal helpers #26367
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
Conversation
defee83
to
648bd55
Compare
Thus I don't really think its worth fretting over trying to get it to do so. The end effect is that you just do: .py file: class Foo:
attr = deprecate_privatize_attribute("3.8")
_attr = "bar" .pyi file: class Foo:
attr: str
_attr: str (You can also opt to not type hint the private version, and potentially to omit the public version as well and add it to the ci/mypy_stubtest_allowlist.txt) Essentially you just take the effect of the decorator and represent it in the pyi This is one of the things that would make inlining more type hints more difficult (if we ever do want to go down that route), but also not necessarily a blocker as I'm not too offended by type checking flagging deprecated things. |
The main issue is the assignment; if you type the left-hand side, the right-hand side is the |
969c653
to
ba2da1c
Compare
Hmm, I'm confused why |
lib/matplotlib/_api/deprecation.pyi
Outdated
|
||
@overload | ||
def rename_parameter( | ||
since: str, old: str, new: str, func: Literal[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.
since: str, old: str, new: str, func: Literal[None] = None | |
since: str, old: str, new: str, func: None=... |
None, being a singleton, has no need to be called out as Literal[None]
.
Additionally, pyi files call for the actual value of defaults to be omitted (which admittedly makes little difference when the type hint is None
...)
Same applies to all other uses of Literal
in this file.
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's not wrong just a bit out of place/using tools that are not needed for the task at hand
While we don't normally type private API, these are used all over Matplotlib, and it makes sense to type them for internal checking purposes.
PR summary
While we don't normally type private API, these are used all over Matplotlib, and it makes sense to type them for internal checking purposes.
I'm uncertain how to actually type hint
deprecate_privatize_attribute
because it takes on the type of the thing it's wrapping. I tried to do this intest_api.py
, but I'm not sure I was successful.PR checklist