-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
Fix typing errors #29114
Fix typing errors #29114
Conversation
Thanks, @AbhijeetKrishnan ! |
@@ -288,7 +288,10 @@ class MockFile: | |||
assert not is_file(data) | |||
|
|||
|
|||
@pytest.mark.parametrize("ll", [collections.namedtuple("Test", list("abc"))(1, 2, 3)]) | |||
test_tuple = collections.namedtuple("Test", ["a", "b", "c"]) |
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 error pandas\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']
to list('abc')
in the committed code, then you get the error pandas/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
Thanks!
On Oct 21, 2019, at 11:04 AM, Abhijeet Krishnan ***@***.***> wrote:
@AbhijeetKrishnan commented on this pull request.
In pandas/tests/dtypes/test_inference.py <#29114 (comment)>:
> @@ -288,7 +288,10 @@ class MockFile:
assert not is_file(data)
***@***.***("ll", [collections.namedtuple("Test", list("abc"))(1, 2, 3)])
+test_tuple = collections.namedtuple("Test", ["a", "b", "c"])
Opened two issues with typeshed for
incorrect type inference on collections.namedtuple(): python/typeshed#3394 (comment) <python/typeshed#3394 (comment)>
incorrect type inference for literal list('abc'): python/typeshed#3395 (comment) <python/typeshed#3395 (comment)>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#29114?email_source=notifications&email_token=AAEU4UKKXJ64HNKSN5V6R7TQPXVLHA5CNFSM4JCVC5I2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCIVBHYY#discussion_r337160476>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAEU4UNRM5W5BBAR6QLPX6TQPXVLHANCNFSM4JCVC5IQ>.
William Ayd
william.ayd@icloud.com
|
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff