-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TYP: Add return types to some top-level func #30565
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
Merged
simonjayhawkins
merged 6 commits into
pandas-dev:master
from
topper-123:type_top_level_funcs
Dec 31, 2019
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
34bcaa8
Add types to some top-level funcs
topper-123 4ef2528
Remove NoReturn
topper-123 635d945
mypy casting
topper-123 0807828
mypy part II
topper-123 648c113
mypy add type: ignore[assignment]
topper-123 5a85a32
Revert "mypy add type: ignore[assignment]"
topper-123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
I think the preference is for assert instead of cast @jbrockmendel
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 error is
error: Incompatible types in assignment (expression has type "Optional[DataFrame]", variable has type "DataFrame")
. I cant reassigntable
to a broader type. So that pattern won't work.Could do
but that's also ugly. But I agree that asserts are better, so I'll do that one above (unless you got something less ugly :-))
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.
we probably should be overloading all methods that have an inplace parameter, but that would require the use of Literal.
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.
Literals won’t come until 3.8 is the minimum version, so will be a while. Should we allow assignment to incompatible type in mypy, until 3.8? Seems like a lesser evil?
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, should probably use ignore commands in the first line: https://mypy.readthedocs.io/en/latest/error_codes.html#silencing-errors-based-on-error-codes. Then ‘’table =...’’ can be used in the first line and the third line can be dropped.
I’ll update later to use this pattern.
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.
we are using the default for allow_redefinition. It does result in lots of variable renaming and some messy code, but the additional strictness is probably worth it.
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.
Is there any way we could get mypy to understand that without
inplace=True
isna
returns non-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.
Not until 3.8 and Literal, AFAIK.
There has been an idea floating around that the
inplace
parameter should be deprecated everywhere (unless there is a performance benefit to it). That would simplify the return types.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've changed this section to use
# type: ignore
directive.EDIT: didn't work, got a Flake8 F821 error (undefined name). I've reverted the commit back to the 3-line version.
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 a good idea, we need to move the adoption of error codes forward. see #29197 could add # noqa for now.