-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Fix typing errors #29114
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
topper-123
merged 1 commit into
pandas-dev:master
from
AbhijeetKrishnan:typing-errors-3
Oct 20, 2019
Merged
Fix typing errors #29114
Changes from all commits
Commits
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
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.
Out of curiosity is there any issue you saw that suggested doing this? I don't think its evident why this would need to exist without knowing the context of this PR.
If it is an issue with mypy or typeshed would sometimes prefer to wait for a fix upstream; generally not in a rush with these
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.
mypy does not infer that the
collections.namedtuple()
call returns a class of user-defined type. It, for some reason, assumes that it returns a tuple.tuple()
expects an argument of Iterable[Any], which is why we see the errorpandas\tests\dtypes\test_inference.py:291: error: Argument 1 to "tuple" has incompatible type "int"; expected "Iterable[Any]"
.mypy also does not seem to infer that
list('abc')
is a literal of type List[str]. The error doesn't show up if the above one isn't corrected, but if you change['a', 'b', 'c']
tolist('abc')
in the committed code, then you get the errorpandas/tests/dtypes/test_inference.py:291: error: List or tuple literal expected as the second argument to namedtuple()
. mypy does infer that['a', 'b', 'c']
is of type List[str].IMO these do seem to be limitations in mypy.
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 thanks for confirming. It would be good for future edits in this project and the entire python eco-system as a whole if those were raised as issues with MyPy, if not already
Not saying this was a problem merging, but especially for internal-only annotations like this there is no rush. If something like that is raised with MyPy and looks like it would be available in a few releases would rather wait than making code edits here
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.
Opened two issues with typeshed -
namedtuple()
inferred as type tuple: collections.namedtuple inferred as type tuple and not the (user-defined) class python/typeshed#3394list('abc')
not inferred as type List[str]: list('abc') not inferred to be of type List[str] python/typeshed#3395