summaryrefslogtreecommitdiff
path: root/astroid/brain/brain_attrs.py
diff options
context:
space:
mode:
authorTomas Novak <ext.Tomas.Novak@skoda-auto.cz>2019-09-15 23:56:19 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2019-09-26 10:10:08 +0200
commit47bd7bdbe263ae7666a4341ae8389b7fa6017752 (patch)
treedba4a2693a882202b93cbe770f932794d5eb11f2 /astroid/brain/brain_attrs.py
parente1b4e11e383bf281544f1300e41eea2ac6ab251c (diff)
downloadastroid-git-47bd7bdbe263ae7666a4341ae8389b7fa6017752.tar.gz
Allow annotated assign with attrs
Diffstat (limited to 'astroid/brain/brain_attrs.py')
-rw-r--r--astroid/brain/brain_attrs.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/astroid/brain/brain_attrs.py b/astroid/brain/brain_attrs.py
index a9241281..670736fe 100644
--- a/astroid/brain/brain_attrs.py
+++ b/astroid/brain/brain_attrs.py
@@ -37,14 +37,19 @@ def attr_attributes_transform(node):
node.locals["__attrs_attrs__"] = [astroid.Unknown(parent=node)]
for cdefbodynode in node.body:
- if not isinstance(cdefbodynode, astroid.Assign):
+ if not isinstance(cdefbodynode, (astroid.Assign, astroid.AnnAssign)):
continue
if isinstance(cdefbodynode.value, astroid.Call):
if cdefbodynode.value.func.as_string() not in ATTRIB_NAMES:
continue
else:
continue
- for target in cdefbodynode.targets:
+ targets = (
+ cdefbodynode.targets
+ if hasattr(cdefbodynode, "targets")
+ else [cdefbodynode.target]
+ )
+ for target in targets:
rhs_node = astroid.Unknown(
lineno=cdefbodynode.lineno,
@@ -52,6 +57,7 @@ def attr_attributes_transform(node):
parent=cdefbodynode,
)
node.locals[target.name] = [rhs_node]
+ node.instance_attrs[target.name] = [rhs_node]
MANAGER.register_transform(