Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
JukkaL merged 2 commits into
python:masterfrom
hi-ogawa:10248-dataclass-field-positional-argument-error-message
Sep 24, 2021
Merged

Fix error message for dataclasses.field with positional argument#11180
JukkaL merged 2 commits into
python:masterfrom
hi-ogawa:10248-dataclass-field-positional-argument-error-message

Conversation

@hi-ogawa

@hi-ogawa hi-ogawa commented Sep 23, 2021

Copy link
Copy Markdown
Contributor

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.

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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

@JukkaL JukkaL left a comment

Copy link
Copy Markdown
Collaborator

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

jumble commented Sep 24, 2021

Copy link
Copy Markdown

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