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 'NoneType' object is not iterable #5036

Closed
altendky opened this issue Sep 17, 2021 · 1 comment · Fixed by pylint-dev/astroid#1181 or #5037
Closed

Crash 'NoneType' object is not iterable #5036

altendky opened this issue Sep 17, 2021 · 1 comment · Fixed by pylint-dev/astroid#1181 or #5037
Labels
Astroid Related to astroid Crash 💥 A bug that makes pylint crash Needs astroid update Needs an astroid update (probably a release too) before being mergable Regression
Milestone

Comments

@altendky
Copy link

altendky commented Sep 17, 2021

Bug description

Here is the stripped down file that still recreated the error TypeError: 'NoneType' object is not iterable.

"""This demonstrates a crash in astroid via pylint

TypeError: 'NoneType' object is not iterable
astroid_example.py:1:0: F0001: Fatal error while checking 'astroid_example.py'.
Please open an issue in our bug tracker so we address this.
There is a pre-filled template that you can use in
'/home/altendky/.cache/pylint/pylint-crash-2021-09-17-09.txt'. (fatal)
"""

from typing import Tuple, Type


def is_type_list(f_type: Type) -> bool:
    """just here to show the issue"""
    return f_type == list


assert not is_type_list(Tuple)
expand to see my recreation

I used this bash to recreate the issue.

python3.9 -m venv astroid_venv
astroid_venv/bin/pip install pylint
astroid_venv/bin/pip freeze --all
cat > astroid_example.py <<EOF
"""This demonstrates a crash in astroid via pylint

TypeError: 'NoneType' object is not iterable
astroid_example.py:1:0: F0001: Fatal error while checking 'astroid_example.py'.
Please open an issue in our bug tracker so we address this.
There is a pre-filled template that you can use in
'/home/altendky/.cache/pylint/pylint-crash-2021-09-17-09.txt'. (fatal)
"""

from typing import Tuple, Type


def is_type_list(f_type: Type) -> bool:
    """just here to show the issue"""
    return f_type == list


assert not is_type_list(Tuple)
EOF
astroid_venv/bin/pylint astroid_example.py

Resulting in this output.

$ python3.9 -m venv astroid_venv
$ astroid_venv/bin/pip install pylint
Collecting pylint
  Using cached pylint-2.11.1-py3-none-any.whl (392 kB)
Collecting platformdirs>=2.2.0
  Using cached platformdirs-2.3.0-py3-none-any.whl (13 kB)
Collecting mccabe<0.7,>=0.6
  Using cached mccabe-0.6.1-py2.py3-none-any.whl (8.6 kB)
Collecting astroid<2.9,>=2.8.0
  Using cached astroid-2.8.0-py3-none-any.whl (242 kB)
Collecting toml>=0.7.1
  Using cached toml-0.10.2-py2.py3-none-any.whl (16 kB)
Collecting isort<6,>=4.2.5
  Using cached isort-5.9.3-py3-none-any.whl (106 kB)
Collecting typing-extensions>=3.10.0
  Using cached typing_extensions-3.10.0.2-py3-none-any.whl (26 kB)
Requirement already satisfied: setuptools>=20.0 in ./astroid_venv/lib/python3.9/site-packages (from astroid<2.9,>=2.8.0->pylint) (56.0.0)
Collecting lazy-object-proxy>=1.4.0
  Using cached lazy_object_proxy-1.6.0-cp39-cp39-manylinux1_x86_64.whl (57 kB)
Collecting wrapt<1.13,>=1.11
  Using cached wrapt-1.12.1-cp39-cp39-linux_x86_64.whl
Installing collected packages: wrapt, typing-extensions, lazy-object-proxy, toml, platformdirs, mccabe, isort, astroid, pylint
Successfully installed astroid-2.8.0 isort-5.9.3 lazy-object-proxy-1.6.0 mccabe-0.6.1 platformdirs-2.3.0 pylint-2.11.1 toml-0.10.2 typing-extensions-3.10.0.2 wrapt-1.12.1
WARNING: You are using pip version 21.1.1; however, version 21.2.4 is available.
You should consider upgrading via the '/home/altendky/repos/chia-blockchain/astroid_venv/bin/python3.9 -m pip install --upgrade pip' command.                                                                                                  
$ astroid_venv/bin/pip freeze --all
astroid==2.8.0
isort==5.9.3
lazy-object-proxy==1.6.0
mccabe==0.6.1
pip==21.1.1
platformdirs==2.3.0
pylint==2.11.1
setuptools==56.0.0
toml==0.10.2
typing-extensions==3.10.0.2
wrapt==1.12.1
$ cat > astroid_example.py <<EOF
> """This demonstrates a crash in astroid via pylint
> 
> TypeError: 'NoneType' object is not iterable
> astroid_example.py:1:0: F0001: Fatal error while checking 'astroid_example.py'.
> Please open an issue in our bug tracker so we address this.
> There is a pre-filled template that you can use in
> '/home/altendky/.cache/pylint/pylint-crash-2021-09-17-09.txt'. (fatal)
> """
> 
> from typing import Tuple, Type
> 
> 
> def is_type_list(f_type: Type) -> bool:
>     """just here to show the issue"""
>     return f_type == list
> 
> 
> assert not is_type_list(Tuple)
> EOF
$ astroid_venv/bin/pylint astroid_example.py
Exception on node <UnaryOp l.18 at 0x7f1c89c97970> in file '/home/altendky/repos/chia-blockchain/astroid_example.py'
Traceback (most recent call last):
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    callback(astroid)
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/pylint/checkers/typecheck.py", line 1686, in visit_unaryop
    for error in node.type_errors():
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/nodes/node_classes.py", line 3790, in type_errors
    return [
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/nodes/node_classes.py", line 3790, in <listcomp>
    return [
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/inference.py", line 492, in _infer_unaryop
    for operand in self.operand.infer(context):
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/nodes/node_ng.py", line 105, in infer
    yield from self._infer(context, **kwargs)
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/decorators.py", line 141, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/decorators.py", line 110, in wrapped
    for res in _func(node, context, **kwargs):
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/inference.py", line 246, in infer_call
    yield from callee.infer_call_result(caller=self, context=callcontext)
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/nodes/scoped_nodes.py", line 1809, in infer_call_result
    yield from returnnode.value.infer(context)
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/nodes/node_ng.py", line 119, in infer
    for i, result in enumerate(generator):
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/inference.py", line 872, in _infer_compare
    retval = _do_compare(lhs, op, rhs)
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/inference.py", line 842, in _do_compare
    left, right = _to_literal(left), _to_literal(right)
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/inference.py", line 814, in _to_literal
    return ast.literal_eval(node.as_string())
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/nodes/node_ng.py", line 547, in as_string
    return AsStringVisitor()(self)
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/nodes/as_string.py", line 55, in __call__
    return node.accept(self).replace(DOC_NEWLINE, "\n")
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/nodes/node_ng.py", line 186, in accept
    return func(self)
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/nodes/as_string.py", line 185, in visit_classdef
    args += [n.accept(self) for n in node.keywords]
TypeError: 'NoneType' object is not iterable
************* Module astroid_example
astroid_example.py:1:0: F0001: Fatal error while checking 'astroid_example.py'. Please open an issue in our bug tracker so we address this. There is a pre-filled template that you can use in '/home/altendky/.cache/pylint/pylint-crash-2021-09-17-10.txt'. (fatal)

----------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: -60.00/10, +70.00)

Configuration

None

Command used

astroid_venv/bin/pylint astroid_example.py

Pylint output

Exception on node <UnaryOp l.18 at 0x7f1c89c97970> in file '/home/altendky/repos/chia-blockchain/astroid_example.py'
Traceback (most recent call last):
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    callback(astroid)
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/pylint/checkers/typecheck.py", line 1686, in visit_unaryop
    for error in node.type_errors():
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/nodes/node_classes.py", line 3790, in type_errors
    return [
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/nodes/node_classes.py", line 3790, in <listcomp>
    return [
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/inference.py", line 492, in _infer_unaryop
    for operand in self.operand.infer(context):
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/nodes/node_ng.py", line 105, in infer
    yield from self._infer(context, **kwargs)
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/decorators.py", line 141, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/decorators.py", line 110, in wrapped
    for res in _func(node, context, **kwargs):
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/inference.py", line 246, in infer_call
    yield from callee.infer_call_result(caller=self, context=callcontext)
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/nodes/scoped_nodes.py", line 1809, in infer_call_result
    yield from returnnode.value.infer(context)
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/nodes/node_ng.py", line 119, in infer
    for i, result in enumerate(generator):
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/inference.py", line 872, in _infer_compare
    retval = _do_compare(lhs, op, rhs)
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/inference.py", line 842, in _do_compare
    left, right = _to_literal(left), _to_literal(right)
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/inference.py", line 814, in _to_literal
    return ast.literal_eval(node.as_string())
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/nodes/node_ng.py", line 547, in as_string
    return AsStringVisitor()(self)
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/nodes/as_string.py", line 55, in __call__
    return node.accept(self).replace(DOC_NEWLINE, "\n")
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/nodes/node_ng.py", line 186, in accept
    return func(self)
  File "/home/altendky/repos/chia-blockchain/astroid_venv/lib/python3.9/site-packages/astroid/nodes/as_string.py", line 185, in visit_classdef
    args += [n.accept(self) for n in node.keywords]
TypeError: 'NoneType' object is not iterable
************* Module astroid_example
astroid_example.py:1:0: F0001: Fatal error while checking 'astroid_example.py'. Please open an issue in our bug tracker so we address this. There is a pre-filled template that you can use in '/home/altendky/.cache/pylint/pylint-crash-2021-09-17-10.txt'. (fatal)

----------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: -60.00/10, +70.00)

Expected behavior

I would rather it not have a traceback. :]

Pylint version

pylint 2.11.1
astroid 2.8.0
Python 3.9.5 (default, Jun  3 2021, 15:18:23) 
[GCC 9.3.0]

OS / Environment

Distributor ID: Ubuntu
Description:    Ubuntu 20.04.3 LTS
Release:        20.04
Codename:       focal

Additional dependencies

astroid==2.8.0
isort==5.9.3
lazy-object-proxy==1.6.0
mccabe==0.6.1
pip==21.1.1
platformdirs==2.3.0
pylint==2.11.1
setuptools==56.0.0
toml==0.10.2
typing-extensions==3.10.0.2
wrapt==1.12.1

@altendky altendky added Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 17, 2021
DanielNoord added a commit to DanielNoord/astroid that referenced this issue Sep 17, 2021
DanielNoord added a commit to DanielNoord/pylint that referenced this issue Sep 17, 2021
@DanielNoord DanielNoord added Astroid Related to astroid Crash 💥 A bug that makes pylint crash Regression Needs astroid update Needs an astroid update (probably a release too) before being mergable and removed Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 17, 2021
@DanielNoord DanielNoord added this to the 2.11.2 milestone Sep 17, 2021
@DanielNoord
Copy link
Collaborator

Reporting the same error as #5030. I have added your reproducing example in the tests cases of #5037. Should be fixed with the release of astroid 2.8.1 and pylint 2.11.2. Those shouldn't take too long to be released I think.
Closing for now in favour of #5030.

cdce8p pushed a commit that referenced this issue Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Astroid Related to astroid Crash 💥 A bug that makes pylint crash Needs astroid update Needs an astroid update (probably a release too) before being mergable Regression
Projects
None yet
2 participants