from typing import Dict
from dataclasses import dataclass, field
@dataclass
class TestClass:
foo: str
bar: str
baz_dict: Dict[str, str] = field(default_factory=dict)
def some_func(self) -> None:
for key, value in self.baz_dict.items():
print(key)
print(value)
Pylint reports:
"Instance of 'Field' has no 'items' member"
No error, because the field is a Dict and thus does have the items() member.
(Pylint thinks it's just a Field, but it's the default factory returns a dict)
pylint 2.1.1
astroid 2.0.4
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)]
(I also tested with "pip install pylint astroid --pre -U", which resulted in the same thing)
Thanks for creating an issue @kazaamjt Pylint currently does not fully understand dataclasses, we'll probably need inference support in inferring field as the type of the value passed via default_factory
Note: of course same behavior with keys and values :)
While dataclasses are not supported, is there a way to disable certain checks on dataclasses only, using pylintrc?
You can try --ignored-classes to see if it helps.
Most helpful comment
Note: of course same behavior with
keysandvalues:)