Skip to content

Commit 345b91c

Browse files
committed
Use inference to determine membership of attr(s) module
1 parent 8c55e5c commit 345b91c

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

astroid/brain/brain_attrs.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,9 @@
88
Without this hook pylint reports unsupported-assignment-operation
99
for attrs classes
1010
"""
11+
from astroid.helpers import safe_infer
1112
from astroid.manager import AstroidManager
12-
from astroid.nodes.node_classes import (
13-
AnnAssign,
14-
Assign,
15-
AssignName,
16-
Call,
17-
ImportFrom,
18-
Unknown,
19-
)
13+
from astroid.nodes.node_classes import AnnAssign, Assign, AssignName, Call, Unknown
2014
from astroid.nodes.scoped_nodes import ClassDef
2115

2216
ATTRIB_NAMES = frozenset(
@@ -47,18 +41,10 @@ def is_decorated_with_attrs(node, decorator_names=ATTRS_NAMES) -> bool:
4741
decorator_attribute = decorator_attribute.func
4842
if decorator_attribute.as_string() in decorator_names:
4943
return True
50-
# Check if by including the origin module of the decorator -
51-
# and concatenating them we get one of ATTRS_NAMES
52-
decorator_name = decorator_attribute.as_string()
53-
local_value = decorator_attribute.scope().locals.get(decorator_name)
5444

55-
# TODO: hack, as sometimes its a list?
56-
if isinstance(local_value, ImportFrom) or (
57-
isinstance(local_value, list) and isinstance(local_value[0], ImportFrom)
58-
):
59-
decorator_module = local_value[0].modname
60-
if f"{decorator_module}.{decorator_name}" in ATTRS_NAMES:
61-
return True
45+
inferred = safe_infer(decorator_attribute)
46+
if inferred and inferred.root().name == "attr._next_gen":
47+
return True
6248
return False
6349

6450

0 commit comments

Comments
 (0)