-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TYP: Return annotations for io/{formats,json} #47516
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
Looks good. It'd be good to have an issue about this for more context, and to somehow group the different issues in this effort. Also to add to the CI the validation you're using to find those. Does this make sense to you? |
I will create an issue later today about it (many of these annotations could be easy first contributions). Inspired by @MarcoGorelli's #47497 I'm using pyright to find missing return annotations that it can infer. While this doesn't help pyright much (it infers them already), it helps mypy, and in some cases it also helps pyright (when pyright infers a Union (might be an overload) or infers Any/Unknown (might be able to find a narrower type).
At the moment I'm just doing: pyright --createstub pandas
grep -R "# -> " typings/pandas/ and then see which cases I feel comfortable annotating. In terms of integrating something like that into the CI:
|
pandas/core/frame.py
Outdated
@@ -1036,7 +1036,8 @@ def _repr_fits_horizontal_(self, ignore_width: bool = False) -> bool: | |||
value = buf.getvalue() | |||
repr_width = max(len(line) for line in value.split("\n")) | |||
|
|||
return repr_width < width | |||
# error: Unsupported operand types for < ("int" and "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.
Probably to be safe, this typing infraction should be address with an if width is not None
or similar.
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.
As far as I understand (not sure), width
can only be None
, when pandas is running in a non-interactive way (and I think it also requires that the user put None
to set_options()
for the default width). The function _repr_fits_horizontal_
exits early if console.in_interactive_session()
is true which should ensure that the above line will never be reached with None
. Probably makes sense to or
this if
condition with width is None
:
Line 1011 in a5ac19a
if ignore_width or not console.in_interactive_session(): |
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.
Thanks, makes sense to me
Nice! Does this obliviate the need for #47497 and associated tool, or does pyright not find some obvious |
Pyright is really good at inferring types :) but |
Thanks @twoertwein As @datapythonista mentioned, would be good to have a general issue about this pyright specific check. |
Opened #47521 |
* TYP: Return annotations for io/{formats,json} * flake8 * explicitly check whether width is None
No description provided.