Skip to content

Commit ddd2123

Browse files
Fix crash on uninferable decorators on Python 3.6 and 3.7 (#5549)
Co-authored-by: Mark Byrne <[email protected]>
1 parent fd18848 commit ddd2123

File tree

5 files changed

+16
-1
lines changed

5 files changed

+16
-1
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ Release date: TBA
7979

8080
Closes #5323
8181

82+
* Fixed crash on uninferable decorators on Python 3.6 and 3.7
83+
8284
* Add checker ``unnecessary-ellipsis``: Emitted when the ellipsis constant is used unnecessarily.
8385

8486
Closes #5460

doc/whatsnew/2.13.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ Other Changes
7373

7474
Closes #5065
7575

76+
* Fixed crash on uninferable decorators on Python 3.6 and 3.7
77+
7678
* Fatal errors now emit a score of 0.0 regardless of whether the linted module
7779
contained any statements
7880

pylint/checkers/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,11 @@ def uninferable_final_decorators(
876876
except AttributeError:
877877
continue
878878
elif isinstance(decorator, nodes.Name):
879-
import_node = decorator.lookup(decorator.name)[1][0]
879+
lookup_values = decorator.lookup(decorator.name)
880+
if lookup_values[1]:
881+
import_node = lookup_values[1][0]
882+
else:
883+
continue # pragma: no cover # Covered on Python < 3.8
880884
else:
881885
continue
882886

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""Test a crash regression for the overridden-final-method checker on uninferable decorators"""
2+
3+
4+
@unknown_decorator # [undefined-variable]
5+
def crash_test():
6+
"""A docstring"""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
undefined-variable:4:1:4:18:crash_test:Undefined variable 'unknown_decorator':UNDEFINED

0 commit comments

Comments
 (0)