Skip to content

Commit 09d69d2

Browse files
committed
Merge remote-tracking branch 'upstream/main' into add-3.13
2 parents a5def83 + ea26bcb commit 09d69d2

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

deadcode/visitor/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def get_decorator_name(decorator: ast.Call | ast.Attribute) -> str:
5757
while isinstance(decorator, ast.Attribute):
5858
parts.append(decorator.attr)
5959
decorator = decorator.value # type: ignore
60-
parts.append(decorator.id) # type: ignore
60+
parts.append(str(id(decorator))) # type: ignore
6161
return '@' + '.'.join(reversed(parts))
6262

6363

tests/visitor/test_utils.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import ast
2+
import re
3+
4+
from deadcode.visitor.utils import get_decorator_name
5+
6+
class TestUtils:
7+
def test_get_decorator_name_attribute(self):
8+
# Test with a decorator with an attribute
9+
decorator = ast.Attribute(value=ast.Name(id='module', ctx=ast.Load()), attr='my_decorator1')
10+
assert get_decorator_name(decorator).endswith('.my_decorator1')
11+
12+
# Test with a complex decorator
13+
decorator = ast.Attribute(
14+
value=decorator, # Create nested attributes
15+
attr='my_decorator2',
16+
ctx=ast.Load()
17+
)
18+
assert re.match(r'@\d+\.my_decorator1\.\d+\.my_decorator2', get_decorator_name(decorator))
19+
20+
21+
def test_get_decorator_name_call(self):
22+
decorator = ast.Attribute(value=ast.Name(id='module', ctx=ast.Load()), attr='my_decorator')
23+
assert re.match(r'@\d+\.my_decorator', get_decorator_name(decorator))
24+
25+
# Test with a decorator that is a call
26+
decorator = ast.Call(
27+
func=decorator,
28+
args=[],
29+
keywords=[]
30+
)
31+
assert re.match(r'@\d+\.my_decorator', get_decorator_name(decorator))

0 commit comments

Comments
 (0)