Skip to content

Commit d768d7f

Browse files
Ahmed AzzaouiPCManticore
Ahmed Azzaoui
authored andcommitted
handle case of "attr" decorators with arguments
1 parent e260d5c commit d768d7f

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

astroid/brain/brain_attrs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def is_decorated_with_attrs(
2121
if not node.decorators:
2222
return False
2323
for decorator_attribute in node.decorators.nodes:
24+
if isinstance(decorator_attribute, astroid.Call): # decorator with arguments
25+
decorator_attribute = decorator_attribute.func
2426
if decorator_attribute.as_string() in decorator_names:
2527
return True
2628
return False

astroid/tests/unittest_brain.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,10 +819,18 @@ class Foo:
819819
820820
f = Foo()
821821
f.d['answer'] = 42
822+
823+
@attr.s(slots=True)
824+
class Bar:
825+
d = attr.ib(attr.Factory(dict))
826+
827+
g = Bar()
828+
g.d['answer'] = 42
822829
""")
823830

824-
should_be_attribute = next(module.getattr('f')[0].infer()).getattr('d')[0]
825-
self.assertIsInstance(should_be_attribute, astroid.Unknown)
831+
for name in ('f', 'g'):
832+
should_be_unknown = next(module.getattr(name)[0].infer()).getattr('d')[0]
833+
self.assertIsInstance(should_be_unknown, astroid.Unknown)
826834

827835

828836
if __name__ == '__main__':

0 commit comments

Comments
 (0)