Skip to content

Commit

Permalink
Add an exception for IndexError inside `uninferable_final_decorator…
Browse files Browse the repository at this point in the history
…s` method.
  • Loading branch information
mbyrnepr2 committed May 6, 2022
1 parent d4631af commit 3f9553b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ChangeLog
Expand Up @@ -25,6 +25,8 @@ Release date: TBA

Closes #4301

* Fix ``IndexError`` crash in ``uninferable_final_decorators`` method.

* By default the similarity checker will now ignore imports and ignore function signatures when computing
duplication. If you want to keep the previous behaviour set ``ignore-imports`` and ``ignore-signatures`` to ``False``.

Expand Down
2 changes: 2 additions & 0 deletions doc/whatsnew/2.14.rst
Expand Up @@ -305,6 +305,8 @@ Other Changes
* By default the similarity checker will now ignore imports and ignore function signatures when computing
duplication. If you want to keep the previous behaviour set ``ignore-imports`` and ``ignore-signatures`` to ``False``.

* Fix ``IndexError`` crash in ``uninferable_final_decorators`` method.

* Pylint now expands the user path (i.e. ``~`` to ``home/yusef/``) and expands environment variables (i.e. ``home/$USER/$project``
to ``home/yusef/pylint`` for ``USER=yusef`` and ``project=pylint``) for pyreverse's ``output-directory``,
``import-graph``, ``ext-import-graph``, ``int-import-graph`` options, and the spell checker's ``spelling-private-dict-file``
Expand Down
2 changes: 1 addition & 1 deletion pylint/checkers/utils.py
Expand Up @@ -850,7 +850,7 @@ def uninferable_final_decorators(
if isinstance(decorator, nodes.Attribute):
try:
import_node = decorator.expr.lookup(decorator.expr.name)[1][0]
except AttributeError:
except (AttributeError, IndexError):
continue
elif isinstance(decorator, nodes.Name):
lookup_values = decorator.lookup(decorator.name)
Expand Down
13 changes: 13 additions & 0 deletions tests/functional/r/regression/regression_6531_crash_index_error.py
@@ -0,0 +1,13 @@
@pytest.fixture
def my_wallet():
'''Returns a Wallet instance with a zero balance'''
return Wallet()

@pytest.mark.parametrize("earned,spent,expected", [
(30, 10, 20),
(20, 2, 18),
])
def test_transactions(my_wallet, earned, spent, expected):
my_wallet.add_cash(earned)
my_wallet.spend_cash(spent)
assert my_wallet.balance == expected

0 comments on commit 3f9553b

Please sign in to comment.