Skip to content

Crash with new min/max refactoring checker #4379

Closed
@cdce8p

Description

@cdce8p

Steps to reproduce

Given a file a.py:

var = 1
if var == -1:
    var = None

Current behavior

Result of pylint a.py:

Traceback (most recent call last):
  File "/../pylint/venv-39_link/bin/pylint", line 33, in <module>
    sys.exit(load_entry_point('pylint', 'console_scripts', 'pylint')())
  File "/../pylint/pylint/__init__.py", line 24, in run_pylint
    PylintRun(sys.argv[1:])
  File "/../pylint/pylint/lint/run.py", line 358, in __init__
    linter.check(args)
  File "/../pylint/pylint/lint/pylinter.py", line 873, in check
    self._check_files(
  File "/../pylint/pylint/lint/pylinter.py", line 907, in _check_files
    self._check_file(get_ast, check_astroid_module, name, filepath, modname)
  File "/../pylint/pylint/lint/pylinter.py", line 933, in _check_file
    check_astroid_module(ast_node)
  File "/../pylint/pylint/lint/pylinter.py", line 1067, in check_astroid_module
    retval = self._check_astroid_module(
  File "/../pylint/pylint/lint/pylinter.py", line 1112, in _check_astroid_module
    walker.walk(ast_node)
  File "/../pylint/pylint/utils/ast_walker.py", line 77, in walk
    self.walk(child)
  File "/../pylint/pylint/utils/ast_walker.py", line 74, in walk
    callback(astroid)
  File "/../pylint/pylint/checkers/refactoring/refactoring_checker.py", line 622, in visit_if
    self._check_consider_using_min_max_builtin(node)
  File "/../pylint/pylint/checkers/refactoring/refactoring_checker.py", line 680, in _check_consider_using_min_max_builtin
    right_statement_value = right_statement.value
AttributeError: 'UnaryOp' object has no attribute 'value'

Expected behavior

No crash.

pylint --version output

pylint 2.8.0.dev1
astroid 2.5.3
Python 3.9.4 (v3.9.4:1f2e3088f3, Apr  4 2021, 12:32:44) 
[Clang 6.0 (clang-600.0.57)]

--
Related to #4359
/CC: @Pierre-Sassoulas, @Qwiddle13, @manderj

I'll open a MR for it shortly.

Metadata

Metadata

Assignees

Labels

Blocker 🙅Blocks the next releaseCrash 💥A bug that makes pylint crash

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions