|
8 | 8 | Without this hook pylint reports unsupported-assignment-operation
|
9 | 9 | for attrs classes
|
10 | 10 | """
|
| 11 | +from astroid.helpers import safe_infer |
11 | 12 | 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 |
20 | 14 | from astroid.nodes.scoped_nodes import ClassDef
|
21 | 15 |
|
22 | 16 | ATTRIB_NAMES = frozenset(
|
@@ -47,18 +41,10 @@ def is_decorated_with_attrs(node, decorator_names=ATTRS_NAMES) -> bool:
|
47 | 41 | decorator_attribute = decorator_attribute.func
|
48 | 42 | if decorator_attribute.as_string() in decorator_names:
|
49 | 43 | 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) |
54 | 44 |
|
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 |
62 | 48 | return False
|
63 | 49 |
|
64 | 50 |
|
|
0 commit comments