Skip to content

Commit 0533111

Browse files
[fix] Fix a crash for class decorators mistaken for class attributes (#10362) (#10363)
Closes #10105 (cherry picked from commit 1812899) Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
1 parent 887b1b6 commit 0533111

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

doc/whatsnew/fragments/10105.bugfix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixed a crash when importing a class decorator that did not exist with the same name than a class attribute after the class definition.
2+
3+
Closes #10105

pylint/checkers/variables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2448,7 +2448,7 @@ def _is_only_type_assignment(
24482448
node_frame = node.frame()
24492449

24502450
parent = node
2451-
while parent is not defstmt_frame.parent:
2451+
while parent not in {defstmt_frame.parent, None}:
24522452
parent_scope = parent.scope()
24532453

24542454
# Find out if any nonlocals receive values in nested functions
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# pylint: disable=too-few-public-methods,missing-docstring,used-before-assignment,import-error,unused-import
2+
# pylint: disable=wrong-import-position
3+
4+
5+
@decorator
6+
class DecoratedClass:
7+
decorator: int
8+
9+
import decorator

0 commit comments

Comments
 (0)