diff --git a/ChangeLog b/ChangeLog index cbc2edac32..dcafe4fb9f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -64,6 +64,10 @@ Release date: TBA Closes pylint-dev/pylint#8544 +* Add ``attr.Factory`` to the recognized class attributes for classes decorated with ``attrs``. + + Closes pylint-dev/pylint#4341 + * ``infer_property()`` now observes the same property-specific workaround as ``infer_functiondef``. Refs #1490 diff --git a/astroid/brain/brain_attrs.py b/astroid/brain/brain_attrs.py index 44f9572a86..a2aae00b6a 100644 --- a/astroid/brain/brain_attrs.py +++ b/astroid/brain/brain_attrs.py @@ -14,7 +14,15 @@ from astroid.nodes.scoped_nodes import ClassDef ATTRIB_NAMES = frozenset( - ("attr.ib", "attrib", "attr.attrib", "attr.field", "attrs.field", "field") + ( + "attr.Factory", + "attr.ib", + "attrib", + "attr.attrib", + "attr.field", + "attrs.field", + "field", + ) ) ATTRS_NAMES = frozenset( ( diff --git a/tests/brain/test_attr.py b/tests/brain/test_attr.py index 88d78c7a41..5185dff0c1 100644 --- a/tests/brain/test_attr.py +++ b/tests/brain/test_attr.py @@ -74,10 +74,16 @@ class Eggs: l = Eggs(d=1) l.d['answer'] = 42 + + @attr.attrs(auto_attribs=True) + class Eggs: + d: int = attr.Factory(lambda: 3) + + m = Eggs(d=1) """ ) - for name in ("f", "g", "h", "i", "j", "k", "l"): + for name in ("f", "g", "h", "i", "j", "k", "l", "m"): should_be_unknown = next(module.getattr(name)[0].infer()).getattr("d")[0] self.assertIsInstance(should_be_unknown, astroid.Unknown)