-
-
Notifications
You must be signed in to change notification settings - Fork 143
TYP: future annotations #151
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
I will try to separate it in two commits: automatic (sed+pre-commit) and then manual changes to make it easier to review |
Thanks. I'll review when you do that. Did you just do |
The new PR will:
This will not satisfy flake8-pyi as pre-commit will not rewrite Union/... outside of annotations (TypeAliases), I had many ugly sed's in this PR but I think I will skip this and try to address that later. |
pyi files do not need the future import but without it pre-commit while not re-write the annotations. |
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.
2, 3, and 4 all look good. 1 is harder to check, but probably can be trusted.
pandas-stubs/core/arrays/boolean.pyi
Outdated
@@ -19,7 +19,7 @@ class BooleanDtype(ExtensionDtype): | |||
@property | |||
def kind(self) -> str: ... | |||
@classmethod | |||
def construct_array_type(cls) -> type[BooleanArray]: ... | |||
def construct_array_type(cls) -> _type_BooleanArray: ... |
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.
Same
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 somehow stared at all of these. Not sure I caught everything. General comments:
- In
pandas
we havetype_t
inpandas/_typing.py
, so we can then do things liketype_t[Dtype]
, etc. So I think we should use that convention here rather thantype[Dtype]
- There are places where a parameter has one line of its type, but parentheses got inserted and are unnecessary. I caught many of them, but may have missed a few
- There are places where we have
None | str | int
(or similar pattern), where we should use the convention ofstr | int | None
There was one place where a type was dropped. Otherwise OK.
But neither Dict nor List is at those lines? (locally
|
Is there a bug in the git checkout? The CI has:
But locally I have:
I'll squash the commits when it started falling (maybe the commit message triggers some weird bug - probably something different is wrong but I cannot see it) |
Since I cannot reproduce the error locally, I will revert until the latest working commit and then add slowly make changes to see what is going on. |
This reverts commit 188c4d9.
You can retrigger the CI from github. I had a failure due to network connectivity, and just went it and told it to rerun the jobs. |
Thanks! It seems that github requires that the branch has no conflict with main (that might also explain why Dict and List appeared out of nowhere): I resolved all conflicts. |
Let me know when I should look at this again. |
This reverts commit edb4539.
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.
So I think there is a better workaround for the type
issue, where we define type_t
once, export it from _typing.pyi
and then import type_t
instead of always creating _type
Otherwise, a few small things.
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 we should keep using _str
in frame.pyi
so that the methods that overlap with series.pyi
have similar signatures, since we have to use _str
in series.pyi
This reverts commit 40739c2.
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 @twoertwein . I now have to get used to not using Union
, Dict
, List
, etc. !
assert_type()
to assert the type of any return value