Skip to content
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

kw_only argument of dataclasses.field is not supported #1830

Closed
Infernio opened this issue Oct 11, 2022 · 1 comment · Fixed by #1899
Closed

kw_only argument of dataclasses.field is not supported #1830

Infernio opened this issue Oct 11, 2022 · 1 comment · Fixed by #1899
Labels

Comments

@Infernio
Copy link

Infernio commented Oct 11, 2022

Moved here from pylint-dev/pylint#7290 (comment).

Steps to reproduce

from dataclasses import dataclass, field

@dataclass
class ClassA:
    kw_field: str = field(kw_only=True)

@dataclass
class ClassB(ClassA):
    normal_field: int

print(ClassB(42, kw_field='Hello World'))

The above code runs fine in Python 3.10 and produces

ClassB(kw_field='Hello World', normal_field=42)

Running pylint, however, produces errors:

************* Module demo
/tmp/demo.py:14:6: E1124: Argument 'kw_field' passed by position and keyword in constructor call (redundant-keyword-arg)
/tmp/demo.py:14:6: E1120: No value for argument 'normal_field' in constructor call (no-value-for-parameter)

python -c "from astroid import __pkginfo__; print(__pkginfo__.version)" output

2.12.11

Python version is 3.10.7, pylint version is 2.15.4.

@DanielNoord
Copy link
Collaborator

Closed by #1899 2 months ago.

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

Successfully merging a pull request may close this issue.

3 participants