summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Mueller <30130371+cdce8p@users.noreply.github.com>2021-04-19 21:36:37 +0200
committerGitHub <noreply@github.com>2021-04-19 21:36:37 +0200
commit95c05e024cf4d74fa25ee1a8cbcc5e08ebc1407f (patch)
tree6a5bf8ee5b942ca34873d0e05ea2598ad68e651b
parent00a2394ec7d5aedc3e768260bf1073c85821430e (diff)
downloadpylint-git-95c05e024cf4d74fa25ee1a8cbcc5e08ebc1407f.tar.gz
Fix crash min-max refactoring checker (#4380)
* Fix crash min-max refactoring checker * Small update to test
-rw-r--r--pylint/checkers/refactoring/refactoring_checker.py4
-rw-r--r--tests/functional/c/consider/consider_using_min_max_builtin.py10
2 files changed, 13 insertions, 1 deletions
diff --git a/pylint/checkers/refactoring/refactoring_checker.py b/pylint/checkers/refactoring/refactoring_checker.py
index bab86b4bf..e63386186 100644
--- a/pylint/checkers/refactoring/refactoring_checker.py
+++ b/pylint/checkers/refactoring/refactoring_checker.py
@@ -676,8 +676,10 @@ class RefactoringChecker(checkers.BaseTokenChecker):
if isinstance(right_statement, astroid.Name):
right_statement_value = right_statement.name
- else:
+ elif isinstance(right_statement, astroid.Const):
right_statement_value = right_statement.value
+ else:
+ return
# Verify the right part of the statement is the same.
if right_statement_value != body_value:
diff --git a/tests/functional/c/consider/consider_using_min_max_builtin.py b/tests/functional/c/consider/consider_using_min_max_builtin.py
index e12e4992f..6e7c7b886 100644
--- a/tests/functional/c/consider/consider_using_min_max_builtin.py
+++ b/tests/functional/c/consider/consider_using_min_max_builtin.py
@@ -95,3 +95,13 @@ if value > 10:
value = 10
else:
value = 3
+
+
+# https://github.com/PyCQA/pylint/issues/4379
+var = 1
+if var == -1:
+ var = None
+
+var2 = 1
+if var2 in [1, 2]:
+ var2 = None