astroid icon indicating copy to clipboard operation
astroid copied to clipboard

`kw_only` argument of `dataclasses.field` is not supported

Open Infernio opened this issue 3 years ago • 0 comments

Moved here from https://github.com/PyCQA/pylint/issues/7290#issuecomment-1274885773.

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.

Infernio avatar Oct 11 '22 19:10 Infernio