From 3f9553b47922d49f19b844595042c50d288d7ea8 Mon Sep 17 00:00:00 2001 From: Mark Byrne Date: Sat, 7 May 2022 00:26:38 +0200 Subject: [PATCH] Add an exception for `IndexError` inside `uninferable_final_decorators` method. --- ChangeLog | 2 ++ doc/whatsnew/2.14.rst | 2 ++ pylint/checkers/utils.py | 2 +- .../regression/regression_6531_crash_index_error.py | 13 +++++++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/functional/r/regression/regression_6531_crash_index_error.py 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..1e5f0a85aad --- /dev/null +++ b/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