You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If all fields in a dataclass are keyword only then mypy should not raise errors regarding the order of attributes with default values.
Python 3.10.0 introduces a new dataclass parameter kw_only.
When this parameter is set to true then all fields in the dataclass will be marked as keyword only. If all fields in a dataclass are keyword only then checking the order of attributes with default values is not relevant.
Prior art:
[attrs plugin] Support kw_only=True #6107
Allow attrs kw_only arguments at any position #8803
bpo-43532: Add keyword-only fields to dataclasses. python/cpython#25608
Sync typeshed #10537 (introduced the kw_only dataclass parameter to mypy)
To Reproduce
Ensure you are using python version 3.10.0b4 (although should be reproducible with other 3.10 beta versions)
Ensure you are using a dev build of mypy off of master
Create a file test_dataclass.py which contains the following
$ mypy test_dataclass.py
test_dataclass.py:7: error: Attributes without a default cannot follow attributes with one
Found 1 error in 1 file (checked 1 source file)
Expected Behavior
This should not cause a mypy error. Checking the ordering of attributes with default parameters is not necessary when kw_only=True is specified.
Your Environment
Mypy version used: 0.920+dev.97b3b90356893e2a9f6947ebe52b41cd54ab1cb7
Mypy command-line flags: mypy test_dataclass.py
Mypy configuration options from mypy.ini (and other config files): n/a; default
Python version used: 3.10.0b4
Operating system and version: OS X 10.15.5
The text was updated successfully, but these errors were encountered:
Bug Report
If all fields in a dataclass are keyword only then mypy should not raise errors regarding the order of attributes with default values.
Python 3.10.0 introduces a new dataclass parameter
kw_only
.When this parameter is set to true then all fields in the dataclass will be marked as keyword only. If all fields in a dataclass are keyword only then checking the order of attributes with default values is not relevant.
Prior art:
[attrs plugin] Support kw_only=True #6107
Allow attrs kw_only arguments at any position #8803
bpo-43532: Add keyword-only fields to dataclasses. python/cpython#25608
Sync typeshed #10537 (introduced the
kw_only
dataclass parameter to mypy)To Reproduce
3.10.0b4
(although should be reproducible with other 3.10 beta versions)test_dataclass.py
which contains the followingExpected Behavior
This should not cause a mypy error. Checking the ordering of attributes with default parameters is not necessary when
kw_only=True
is specified.Your Environment
mypy.ini
(and other config files): n/a; defaultThe text was updated successfully, but these errors were encountered: