diff --git a/ChangeLog b/ChangeLog index aec24186b62..c5983fd3a3b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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``. diff --git a/doc/whatsnew/2.14.rst b/doc/whatsnew/2.14.rst index d59c4792ec6..cfb4b57072c 100644 --- a/doc/whatsnew/2.14.rst +++ b/doc/whatsnew/2.14.rst @@ -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`` diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py index 5a48ecf0a3f..ecb7b682521 100644 --- a/pylint/checkers/utils.py +++ b/pylint/checkers/utils.py @@ -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) diff --git a/tests/functional/r/regression/regression_6531_crash_index_error.py b/tests/functional/r/regression/regression_6531_crash_index_error.py new file mode 100644 index 00000000000..7a89b4e15cc --- /dev/null +++ b/tests/functional/r/regression/regression_6531_crash_index_error.py @@ -0,0 +1,28 @@ +# pylint: disable=missing-docstring + +import pytest + + +class Wallet: + def __init__(self): + self.balance = 0 + + def add_cash(self, earned): + self.balance += earned + + def spend_cash(self, spent): + self.balance -= spent + +@pytest.fixture(name="my_wallet") +def fixture_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 diff --git a/tests/functional/r/regression/regression_6531_crash_index_error.txt b/tests/functional/r/regression/regression_6531_crash_index_error.txt new file mode 100644 index 00000000000..e69de29bb2d