Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash using isinstance + super due to Astroid #8554

Closed
nathanjmcdougall opened this issue Apr 8, 2023 · 3 comments · Fixed by #8682
Closed

Crash using isinstance + super due to Astroid #8554

nathanjmcdougall opened this issue Apr 8, 2023 · 3 comments · Fixed by #8682
Assignees
Labels
Crash 💥 A bug that makes pylint crash Needs astroid update Needs an astroid update (probably a release too) before being mergable
Milestone

Comments

@nathanjmcdougall
Copy link

Bug description

When parsing the following a.py:

class A:
    def __init__(self):
        if not isinstance(super(), float):
            pass

there is a crash. Note however that this snippet is fine:

class A:
    def __init__(self):
        if isinstance(super(), float):
            pass

with not removed. Also I believe it's nothing to do with float: you can replace this with a custom class, or another built-in.

Command used

pylint a.py

Pylint output

pylint crashed with a ``AstroidError`` and with the following stacktrace:
Traceback (most recent call last):
  File "/home/bugreport/.venv/lib/python3.10/site-packages/astroid/inference_tip.py", line 33, in _inference_tip_cached
    result = _cache[func, node]
KeyError: (<function register_builtin_transform.<locals>._transform_wrapper at 0x7fbe7b0e5b40>, <Call l.3 at 0x7fbe7a87c910>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/namc/pylintbugreport/.venv/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 772, in _lint_file
    check_astroid_module(module)
  File "/home/namc/pylintbugreport/.venv/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 1001, in check_astroid_module
    retval = self._check_astroid_module(
  File "/home/namc/pylintbugreport/.venv/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 1047, in _check_astroid_module
    walker.walk(node)
  File "/home/namc/pylintbugreport/.venv/lib/python3.10/site-packages/pylint/utils/ast_walker.py", line 94, in walk
    self.walk(child)
  File "/home/namc/pylintbugreport/.venv/lib/python3.10/site-packages/pylint/utils/ast_walker.py", line 94, in walk
    self.walk(child)
  File "/home/namc/pylintbugreport/.venv/lib/python3.10/site-packages/pylint/utils/ast_walker.py", line 94, in walk
    self.walk(child)
  [Previous line repeated 1 more time]
  File "/home/namc/pylintbugreport/.venv/lib/python3.10/site-packages/pylint/utils/ast_walker.py", line 91, in walk
    callback(astroid)
  File "/home/namc/pylintbugreport/.venv/lib/python3.10/site-packages/pylint/checkers/typecheck.py", line 1903, in visit_unaryop
    for error in node.type_errors():
  File "/home/namc/pylintbugreport/.venv/lib/python3.10/site-packages/astroid/nodes/node_classes.py", line 4466, in type_errors
    return [
  File "/home/namc/pylintbugreport/.venv/lib/python3.10/site-packages/astroid/nodes/node_classes.py", line 4466, in <listcomp>
    return [
  File "/home/namc/pylintbugreport/.venv/lib/python3.10/site-packages/astroid/inference.py", line 565, in _infer_unaryop
    for operand in self.operand.infer(context):
  File "/home/namc/pylintbugreport/.venv/lib/python3.10/site-packages/astroid/nodes/node_ng.py", line 161, in infer
    results = list(self._explicit_inference(self, context, **kwargs))
  File "/home/namc/pylintbugreport/.venv/lib/python3.10/site-packages/astroid/inference_tip.py", line 40, in _inference_tip_cached
    result = _cache[func, node] = list(func(*args, **kwargs))
  File "/home/namc/pylintbugreport/.venv/lib/python3.10/site-packages/astroid/brain/brain_builtin_inference.py", line 175, in _transform_wrapper
    result = transform(node, context=context)
  File "/home/namc/pylintbugreport/.venv/lib/python3.10/site-packages/astroid/brain/brain_builtin_inference.py", line 725, in infer_isinstance
    isinstance_bool = helpers.object_isinstance(obj_node, class_container, context)
  File "/home/namc/pylintbugreport/.venv/lib/python3.10/site-packages/astroid/helpers.py", line 133, in object_isinstance
    obj_type = object_type(node, context)
  File "/home/namc/pylintbugreport/.venv/lib/python3.10/site-packages/astroid/helpers.py", line 87, in object_type
    types = set(_object_type(node, context))
  File "/home/namc/pylintbugreport/.venv/lib/python3.10/site-packages/astroid/helpers.py", line 71, in _object_type
    raise AssertionError(f"We don't handle {type(inferred)} currently")
AssertionError: We don't handle <class 'astroid.objects.Super'> currently

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/namc/pylintbugreport/.venv/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 736, in _lint_files
    self._lint_file(fileitem, module, check_astroid_module)
  File "/home/namc/pylintbugreport/.venv/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 774, in _lint_file
    raise astroid.AstroidError from e
astroid.exceptions.AstroidError

Expected behaviour

No crash.

Pylint version

pylint 3.0.0a6
astroid 2.15.1
Python 3.10.8 (main, Dec 19 2022, 16:27:32) [GCC 9.4.0]

OS / Environment

linux (Linux)

@Pierre-Sassoulas Pierre-Sassoulas added Crash 💥 A bug that makes pylint crash Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning labels Apr 15, 2023
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.17.4 milestone Apr 15, 2023
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.17.4, 2.17.5 May 5, 2023
@jacobtylerwalls jacobtylerwalls added Needs astroid update Needs an astroid update (probably a release too) before being mergable and removed Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning labels May 13, 2023
@jacobtylerwalls jacobtylerwalls self-assigned this May 13, 2023
@jacobtylerwalls
Copy link
Member

Also necessary to reproduce is the argument-less call to super():

>>> super()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: super(): no arguments

jacobtylerwalls added a commit to jacobtylerwalls/pylint that referenced this issue May 13, 2023
@nathanjmcdougall
Copy link
Author

@jacobtylerwalls I think this issue is broader in scope than just when there is an argument-less call. For example, this causes a crash as well:

class B:
    pass

class A(B):
    def __init__(self):
        if not isinstance(super(B, self), float):
            pass

@jacobtylerwalls
Copy link
Member

Good news is that this case is fixed as well. I'll update the changelog entry, thanks. 👍

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue May 21, 2023
    Handle objects.Super in helpers.object_type().
    Refs pylint-dev/pylint#8554
Pierre-Sassoulas added a commit that referenced this issue Jun 7, 2023
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
github-actions bot pushed a commit that referenced this issue Jun 7, 2023
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
(cherry picked from commit 2acca90)
Pierre-Sassoulas pushed a commit that referenced this issue Jun 7, 2023
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
(cherry picked from commit 2acca90)

Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Crash 💥 A bug that makes pylint crash Needs astroid update Needs an astroid update (probably a release too) before being mergable
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants