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

Exception when combining mock and queue #4633

Closed
robsan00 opened this issue Jun 30, 2021 · 2 comments · Fixed by pylint-dev/astroid#1082 or #4634
Closed

Exception when combining mock and queue #4633

robsan00 opened this issue Jun 30, 2021 · 2 comments · Fixed by pylint-dev/astroid#1082 or #4634
Assignees
Labels
Blocker 🙅 Blocks the next release Crash 💥 A bug that makes pylint crash Needs astroid update Needs an astroid update (probably a release too) before being mergable
Milestone

Comments

@robsan00
Copy link

Steps to reproduce

Call pylint pylint_err.py on the following script (more or less empty venv besides pylint and using Python 3.8.8):

from queue import Queue
from unittest.mock import MagicMock
mock = MagicMock(name="mock")

class Ham(mock.spam):
    def __init__(self):
        self.queue = Queue()

class SecondHam:
    def whatever(self):
        test_var = Ham()
        while not test_var.queue.empty():
            pass

venv:

(pylint_crash) C:\work>pip freeze
astroid==2.6.1
colorama==0.4.4
isort==5.9.1
lazy-object-proxy==1.6.0
mccabe==0.6.1
pylint==2.9.0
toml==0.10.2
wrapt==1.12.1

Python version:

(pylint_crash) C:\work>python --version
Python 3.8.8

Current behavior

Exception on node <UnaryOp l.12 at 0x270b57dfa60> in file 'C:\work\pylint_err.py'
Traceback (most recent call last):
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\astroid\inference_tip.py", line 19, in _inference_tip_cached
    return iter(_cache[func, node])
KeyError: (<function register_builtin_transform.<locals>._transform_wrapper at 0x00000270B5340550>, <Call l.209 at 0x270b58ed490>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Python38\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\Python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\work\dev\venv\pylint_crash\Scripts\pylint.exe\__main__.py", line 7, in <module>
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\pylint\__init__.py", line 24, in run_pylint
    PylintRun(sys.argv[1:])
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\pylint\lint\run.py", line 384, in __init__
    linter.check(args)
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\pylint\lint\pylinter.py", line 973, in check
    self._check_files(
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\pylint\lint\pylinter.py", line 1007, in _check_files
    self._check_file(get_ast, check_astroid_module, name, filepath, modname)
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\pylint\lint\pylinter.py", line 1033, in _check_file
    check_astroid_module(ast_node)
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\pylint\lint\pylinter.py", line 1170, in check_astroid_module
    retval = self._check_astroid_module(
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\pylint\lint\pylinter.py", line 1215, in _check_astroid_module
    walker.walk(ast_node)
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\pylint\utils\ast_walker.py", line 77, in walk
    self.walk(child)
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\pylint\utils\ast_walker.py", line 77, in walk
    self.walk(child)
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\pylint\utils\ast_walker.py", line 77, in walk
    self.walk(child)
  [Previous line repeated 1 more time]
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\pylint\utils\ast_walker.py", line 74, in walk
    callback(astroid)
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\pylint\checkers\typecheck.py", line 1662, in visit_unaryop
    for error in node.type_errors():
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\astroid\node_classes.py", line 4367, in type_errors
    return [
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\astroid\node_classes.py", line 4367, in <listcomp>
    return [
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\astroid\inference.py", line 498, in _infer_unaryop
    for operand in self.operand.infer(context):
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\astroid\node_classes.py", line 353, in infer
    yield from self._infer(context, **kwargs)
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\astroid\decorators.py", line 136, in raise_if_nothing_inferred
    yield next(generator)
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\astroid\decorators.py", line 100, in wrapped
    res = next(generator)
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\astroid\inference.py", line 239, in infer_call
    yield from callee.infer_call_result(caller=self, context=callcontext)
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\astroid\scoped_nodes.py", line 1768, in infer_call_result
    yield from returnnode.value.infer(context)
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\astroid\node_classes.py", line 367, in infer
    for i, result in enumerate(generator):
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\astroid\decorators.py", line 136, in raise_if_nothing_inferred
    yield next(generator)
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\astroid\decorators.py", line 100, in wrapped
    res = next(generator)
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\astroid\inference.py", line 554, in infer_unaryop
    yield from _filter_operation_errors(
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\astroid\inference.py", line 486, in _filter_operation_errors
    for result in infer_callable(self, context):
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\astroid\inference.py", line 498, in _infer_unaryop
    for operand in self.operand.infer(context):
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\astroid\node_classes.py", line 367, in infer
    for i, result in enumerate(generator):
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\astroid\decorators.py", line 136, in raise_if_nothing_inferred
    yield next(generator)
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\astroid\decorators.py", line 100, in wrapped
    res = next(generator)
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\astroid\inference.py", line 239, in infer_call
    yield from callee.infer_call_result(caller=self, context=callcontext)
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\astroid\scoped_nodes.py", line 1768, in infer_call_result
    yield from returnnode.value.infer(context)
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\astroid\node_classes.py", line 343, in infer
    results = tuple(self._explicit_inference(self, context, **kwargs))
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\astroid\inference_tip.py", line 21, in _inference_tip_cached
    result = func(*args, **kwargs)
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\astroid\brain\brain_builtin_inference.py", line 193, in _transform_wrapper
    result = transform(node, context=context)
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\astroid\brain\brain_builtin_inference.py", line 785, in infer_len
    return nodes.Const(helpers.object_len(argument_node, context=context))
  File "c:\work\dev\venv\pylint_crash\lib\site-packages\astroid\helpers.py", line 293, in object_len
    result_of_len = next(len_call.infer_call_result(node, context))
TypeError: 'Uninferable' object is not an iterator

Expected behavior

no exception

pylint --version output

Result of pylint --version output:

pylint 2.9.0
astroid 2.6.1
Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:18:16) [MSC v.1928 64 bit (AMD64)]
@Pierre-Sassoulas Pierre-Sassoulas added Blocker 🙅 Blocks the next release Crash 💥 A bug that makes pylint crash labels Jun 30, 2021
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.9.1 milestone Jun 30, 2021
@Pierre-Sassoulas Pierre-Sassoulas self-assigned this Jun 30, 2021
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jun 30, 2021
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jun 30, 2021
@Pierre-Sassoulas Pierre-Sassoulas added the Needs astroid update Needs an astroid update (probably a release too) before being mergable label Jun 30, 2021
Pierre-Sassoulas added a commit to pylint-dev/astroid that referenced this issue Jun 30, 2021
Pierre-Sassoulas added a commit to pylint-dev/astroid that referenced this issue Jun 30, 2021
Pierre-Sassoulas added a commit to pylint-dev/astroid that referenced this issue Jun 30, 2021
Pierre-Sassoulas added a commit to pylint-dev/astroid that referenced this issue Jun 30, 2021
@Pierre-Sassoulas
Copy link
Member

Thank you for opening the issue, this should be fixed after astroid 2.6.2 is released (if you force the installation of astroid 2.6.2) or in pylint 2.9.1. There's another problem currently and I'd like a review before merging the fix so it could be tomorrow.

@robsan00
Copy link
Author

Thanks for the very fast feedback!

Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jun 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocker 🙅 Blocks the next release Crash 💥 A bug that makes pylint crash Needs astroid update Needs an astroid update (probably a release too) before being mergable
Projects
None yet
2 participants