8000 Fix error message for dataclasses.field with positional argument by hi-ogawa · Pull Request #11180 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Fix error message for dataclasses.field with positional argument #11180

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

hi-ogawa
Copy link
Contributor
@hi-ogawa hi-ogawa commented Sep 23, 2021

Description

Fixes #10248

The crash due to dataclasses.field was fixed in the recent PR #11137, but the error message was wrong when positional arguments are used.
I update the error message based on the #10248 (comment) (Thanks @JelleZijlstra!)

In _collect_field_args, I used CallExpr.arg_kinds to filter only "named" keyword argument, which hopefully is not the wrong usage of ArgKind.
I appreciate any feedback and thanks for the review!

Test Plan

Please see testDataclassFieldWithPositionalArguments in test-data/unit/check-dataclasses.test.

Copy link
Member
@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 👍

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

ignite (https://github.com/pytorch/ignite)
- ignite/engine/deterministic.py:255: error: unused "type: ignore[arg-type, attr-defined]" comment
+ ignite/engine/deterministic.py:255: error: unused "type: ignore" comment
- ignite/engine/deterministic.py:260: error: unused "type: ignore[attr-defined, union-attr]" comment
+ ignite/engine/deterministic.py:260: error: unused "type: ignore" comment

core (https://github.com/home-assistant/core.git)
- homeassistant/components/http/__init__.py:299: error: unused "type: ignore[arg-type, misc]" comment
+ homeassistant/components/http/__init__.py:299: error: unused "type: ignore" comment

aiohttp (https://github.com/aio-libs/aiohttp.git)
- aiohttp/client.py:1063: error: unused "type: ignore[arg-type]" comment

pandas (https://github.com/pandas-dev/pandas.git)
- pandas/core/arrays/_mixins.py:238: error: unused "type: ignore[assignment, type-var]" comment
+ pandas/core/arrays/_mixins.py:238: error: unused "type: ignore" comment
- pandas/core/arrays/datetimelike.py:497: error: unused "type: ignore[arg-type, return-value]" comment
+ pandas/core/arrays/datetimelike.py:497: error: unused "type: ignore" comment
- pandas/core/arrays/string_arrow.py:739: error: unused "type: ignore[arg-type, type-var]" comment
+ pandas/core/arrays/string_arrow.py:739: error: unused "type: ignore" comment
- pandas/core/arrays/string_.py:551: error: unused "type: ignore[arg-type, type-var]" comment
+ pandas/core/arrays/string_.py:551: error: unused "type: ignore" comment
- pandas/io/parsers/base_parser.py:988: error: unused "type: ignore[arg-type, return-value]" comment
+ pandas/io/parsers/base_parser.py:988: error: unused "type: ignore" comment
- pandas/core/reshape/merge.py:2153: error: unused "type: ignore[assignment, union-attr]" comment
+ pandas/core/reshape/merge.py:2153: error: unused "type: ignore" comment

Copy link
Collaborator
@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks good.

@JukkaL JukkaL merged commit 3ec0284 into python:master Sep 24, 2021
@hi-ogawa hi-ogawa deleted the 10248-dataclass-field-positional-argument-error-message branch September 24, 2021 12:45
@jumble
Copy link
jumble commented Sep 24, 2021

nice, think I just ran into this. good catch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Passing dataclass default_factory as positional argument causes internal error.
4 participants
0