Skip to content

Crash AttributeError: 'NoneType' object has no attribute 'value' #8109

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

Closed
siner308 opened this issue Jan 25, 2023 · 2 comments · Fixed by pylint-dev/astroid#2024
Closed

Crash AttributeError: 'NoneType' object has no attribute 'value' #8109

siner308 opened this issue Jan 25, 2023 · 2 comments · Fixed by pylint-dev/astroid#2024
Assignees
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
Milestone

Comments

@siner308
Copy link

siner308 commented Jan 25, 2023

Bug description

pylint failed with Fatal error but code is working

# number.py

from dataclasses import dataclass


@dataclass
class Number:
    amount: int | float
    round: int = 2

    def __str__(self):
        number_format = "{:,.%sf}" % self.round
        return number_format.format(self.amount).rstrip("0").rstrip(".")

Command used

pylint number.py

Pylint output

pylint crashed with a ``AstroidError`` and with the following stacktrace:

Traceback (most recent call last):
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/astroid/inference_tip.py", line 38, in _inference_tip_cached
    result = _cache[func, node]
             ~~~~~~^^^^^^^^^^^^
KeyError: (<function _infer_str_format_call at 0x1056fb6a0>, <Call l.11 at 0x107c0e250>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/pylint/lint/pylinter.py", line 790, in _lint_file
    check_astroid_module(module)
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/pylint/lint/pylinter.py", line 1060, in check_astroid_module
    retval = self._check_astroid_module(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/pylint/lint/pylinter.py", line 1110, in _check_astroid_module
    walker.walk(node)
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/pylint/utils/ast_walker.py", line 93, in walk
    self.walk(child)
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/pylint/utils/ast_walker.py", line 93, in walk
    self.walk(child)
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/pylint/utils/ast_walker.py", line 90, in walk
    callback(astroid)
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/pylint/checkers/classes/special_methods_checker.py", line 183, in visit_functiondef
    inferred = _safe_infer_call_result(node, node)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/pylint/checkers/classes/special_methods_checker.py", line 42, in _safe_infer_call_result
    value = next(inferit)
            ^^^^^^^^^^^^^
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 1749, in infer_call_result
    yield from returnnode.value.infer(context)
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/astroid/nodes/node_ng.py", line 169, in infer
    yield from self._infer(context=context, **kwargs)
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/astroid/decorators.py", line 140, in raise_if_nothing_inferred
    yield next(generator)
          ^^^^^^^^^^^^^^^
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/astroid/decorators.py", line 109, in wrapped
    for res in _func(node, context, **kwargs):
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/astroid/inference.py", line 256, in infer_call
    for callee in self.func.infer(context):
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/astroid/nodes/node_ng.py", line 182, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/astroid/decorators.py", line 140, in raise_if_nothing_inferred
    yield next(generator)
          ^^^^^^^^^^^^^^^
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/astroid/decorators.py", line 109, in wrapped
    for res in _func(node, context, **kwargs):
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/astroid/inference.py", line 344, in infer_attribute
    for owner in self.expr.infer(context):
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/astroid/nodes/node_ng.py", line 182, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/astroid/decorators.py", line 140, in raise_if_nothing_inferred
    yield next(generator)
          ^^^^^^^^^^^^^^^
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/astroid/decorators.py", line 109, in wrapped
    for res in _func(node, context, **kwargs):
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/astroid/inference.py", line 256, in infer_call
    for callee in self.func.infer(context):
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/astroid/nodes/node_ng.py", line 182, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/astroid/decorators.py", line 140, in raise_if_nothing_inferred
    yield next(generator)
          ^^^^^^^^^^^^^^^
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/astroid/decorators.py", line 109, in wrapped
    for res in _func(node, context, **kwargs):
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/astroid/inference.py", line 344, in infer_attribute
    for owner in self.expr.infer(context):
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/astroid/nodes/node_ng.py", line 159, in infer
    results = list(self._explicit_inference(self, context, **kwargs))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/astroid/inference_tip.py", line 45, in _inference_tip_cached
    result = _cache[func, node] = list(func(*args, **kwargs))
                                       ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/astroid/brain/brain_builtin_inference.py", line 937, in _infer_str_format_call
    format_template = value.value
                      ^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'value'

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

Traceback (most recent call last):
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/pylint/lint/pylinter.py", line 755, in _lint_files
    self._lint_file(fileitem, module, check_astroid_module)
  File "/Users/siner308/Library/Caches/pypoetry/virtualenvs/myproject-6nZamvkJ-py3.11/lib/python3.11/site-packages/pylint/lint/pylinter.py", line 792, in _lint_file
    raise astroid.AstroidError from e
astroid.exceptions.AstroidError

Expected behavior

pass pylint

Pylint version

pylint 2.15.6
astroid 2.12.13
Python 3.11.0 (main, Nov 30 2022, 12:30:30) [Clang 14.0.0 (clang-1400.0.29.202)]
@siner308 siner308 added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jan 25, 2023
@nickdrozd nickdrozd added Crash 💥 A bug that makes pylint crash Astroid Related to astroid and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jan 25, 2023
@Pierre-Sassoulas Pierre-Sassoulas added the Needs astroid update Needs an astroid update (probably a release too) before being mergable label Feb 12, 2023
Pierre-Sassoulas added a commit to pylint-dev/astroid that referenced this issue Feb 12, 2023
@Pierre-Sassoulas Pierre-Sassoulas self-assigned this Feb 12, 2023
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.16.2 milestone Feb 12, 2023
Pierre-Sassoulas added a commit to pylint-dev/astroid that referenced this issue Feb 12, 2023
github-actions bot pushed a commit to pylint-dev/astroid that referenced this issue Feb 12, 2023
@Pierre-Sassoulas
Copy link
Member

Released in astroid 2.14.2, a pip install astroid -U will fix with already installed version of pylint.

Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Feb 12, 2023
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Feb 12, 2023
Pierre-Sassoulas added a commit that referenced this issue Feb 13, 2023
@siner308
Copy link
Author

thanks a lot! 🙇

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants