Skip to content

Commit

Permalink
Add attr.Factory to the recognized class attributes for classes d…
Browse files Browse the repository at this point in the history
…ecorated with ``attrs``.

Closes pylint-dev/pylint#4341
  • Loading branch information
mbyrnepr2 committed Apr 19, 2023
1 parent ae9ce82 commit e341b0c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion astroid/brain/brain_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
(
Expand Down
8 changes: 7 additions & 1 deletion tests/brain/test_attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit e341b0c

Please sign in to comment.