summaryrefslogtreecommitdiff
path: root/astroid
diff options
context:
space:
mode:
authorAhmed Azzaoui <ahmed.azzaoui@engie.com>2018-01-17 17:06:22 +0100
committerClaudiu Popa <pcmanticore@gmail.com>2018-01-18 11:23:58 +0100
commitd768d7f3528749f8caae9fab6776617421bb7b84 (patch)
tree4e2bcecdfd68d83056824ce9144115b634b3280e /astroid
parente260d5ce84c3dea5c0e94e9e3139b0b768d44e22 (diff)
downloadastroid-git-d768d7f3528749f8caae9fab6776617421bb7b84.tar.gz
handle case of "attr" decorators with arguments
Diffstat (limited to 'astroid')
-rw-r--r--astroid/brain/brain_attrs.py2
-rw-r--r--astroid/tests/unittest_brain.py12
2 files changed, 12 insertions, 2 deletions
diff --git a/astroid/brain/brain_attrs.py b/astroid/brain/brain_attrs.py
index ed27e609..2ad32987 100644
--- a/astroid/brain/brain_attrs.py
+++ b/astroid/brain/brain_attrs.py
@@ -21,6 +21,8 @@ def is_decorated_with_attrs(
if not node.decorators:
return False
for decorator_attribute in node.decorators.nodes:
+ if isinstance(decorator_attribute, astroid.Call): # decorator with arguments
+ decorator_attribute = decorator_attribute.func
if decorator_attribute.as_string() in decorator_names:
return True
return False
diff --git a/astroid/tests/unittest_brain.py b/astroid/tests/unittest_brain.py
index b024ea5e..079b979e 100644
--- a/astroid/tests/unittest_brain.py
+++ b/astroid/tests/unittest_brain.py
@@ -819,10 +819,18 @@ class AttrsTest(unittest.TestCase):
f = Foo()
f.d['answer'] = 42
+
+ @attr.s(slots=True)
+ class Bar:
+ d = attr.ib(attr.Factory(dict))
+
+ g = Bar()
+ g.d['answer'] = 42
""")
- should_be_attribute = next(module.getattr('f')[0].infer()).getattr('d')[0]
- self.assertIsInstance(should_be_attribute, astroid.Unknown)
+ for name in ('f', 'g'):
+ should_be_unknown = next(module.getattr(name)[0].infer()).getattr('d')[0]
+ self.assertIsInstance(should_be_unknown, astroid.Unknown)
if __name__ == '__main__':