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 'Call' object has no attribute 'value' when typing.cast is used on dataclass field #4963

Closed
kalekseev opened this issue Sep 4, 2021 · 0 comments · Fixed by #4967
Closed
Labels
Crash 💥 A bug that makes pylint crash Needs astroid update Needs an astroid update (probably a release too) before being mergable
Milestone

Comments

@kalekseev
Copy link

Version:

❯ pylint --version
pylint 2.10.2
astroid 2.7.3
Python 3.9.4 (default, May 27 2021, 06:13:04)
[Clang 7.1.0 (tags/RELEASE_710/final)]

Code:

from dataclasses import dataclass, field
from typing import cast


@dataclass
class Example:
    a: int = cast(int, field(default_factory=dict))

pylint crashed with a AttributeError and with the following stacktrace:

Traceback (most recent call last):
  File "/python-3.9.4/lib/python3.9/site-packages/astroid/inference_tip.py", line 28, in _inference_tip_cached
    result = _cache[func, node]
KeyError: (<function infer_typing_cast at 0x1110c2b80>, <Call l.7 at 0x1116128b0>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/python-3.9.4/lib/python3.9/site-packages/astroid/inference_tip.py", line 28, in _inference_tip_cached
    result = _cache[func, node]
KeyError: (<function infer_dataclass_field_call at 0x111096790>, <Call l.7 at 0x111612a30>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/python-3.9.4/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1024, in _check_files
    self._check_file(
  File "/python-3.9.4/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1063, in _check_file
    check_astroid_module(ast_node)
  File "/python-3.9.4/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1200, in check_astroid_module
    retval = self._check_astroid_module(
  File "/python-3.9.4/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1245, in _check_astroid_module
    walker.walk(ast_node)
  File "/python-3.9.4/lib/python3.9/site-packages/pylint/utils/ast_walker.py", line 78, in walk
    self.walk(child)
  File "/python-3.9.4/lib/python3.9/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    callback(astroid)
  File "/python-3.9.4/lib/python3.9/site-packages/pylint/checkers/classes.py", line 850, in visit_classdef
    self._check_bases_classes(node)
  File "/python-3.9.4/lib/python3.9/site-packages/pylint/checkers/classes.py", line 1860, in _check_bases_classes
    unimplemented_abstract_methods(node, is_abstract).items(),
  File "/python-3.9.4/lib/python3.9/site-packages/pylint/checkers/utils.py", line 876, in unimplemented_abstract_methods
    inferred = safe_infer(obj)
  File "/python-3.9.4/lib/python3.9/site-packages/pylint/checkers/utils.py", line 1192, in safe_infer
    value = next(infer_gen)
  File "/python-3.9.4/lib/python3.9/site-packages/astroid/nodes/node_ng.py", line 99, in infer
    yield from self._infer(context, **kwargs)
  File "/python-3.9.4/lib/python3.9/site-packages/astroid/decorators.py", line 129, in raise_if_nothing_inferred
    yield next(generator)
  File "/python-3.9.4/lib/python3.9/site-packages/astroid/decorators.py", line 98, in wrapped
    for res in _func(node, context, **kwargs):
  File "/python-3.9.4/lib/python3.9/site-packages/astroid/bases.py", line 154, in _infer_stmts
    for inf in stmt.infer(context=context):
  File "/python-3.9.4/lib/python3.9/site-packages/astroid/nodes/node_ng.py", line 89, in infer
    results = tuple(self._explicit_inference(self, context, **kwargs))
  File "/python-3.9.4/lib/python3.9/site-packages/astroid/inference_tip.py", line 30, in _inference_tip_cached
    result = _cache[func, node] = list(func(*args, **kwargs))
  File "/python-3.9.4/lib/python3.9/site-packages/astroid/nodes/node_ng.py", line 89, in infer
    results = tuple(self._explicit_inference(self, context, **kwargs))
  File "/python-3.9.4/lib/python3.9/site-packages/astroid/inference_tip.py", line 30, in _inference_tip_cached
    result = _cache[func, node] = list(func(*args, **kwargs))
  File "/python-3.9.4/lib/python3.9/site-packages/astroid/brain/brain_dataclasses.py", line 237, in infer_dataclass_field_call
    field_call = node.parent.value
AttributeError: 'Call' object has no attribute 'value'
DanielNoord added a commit to DanielNoord/astroid that referenced this issue Sep 5, 2021
Fixes the crash reported on pylint-dev/pylint#4963
Tests added there.
DanielNoord added a commit to DanielNoord/astroid that referenced this issue Sep 5, 2021
Fixes the crash reported at pylint-dev/pylint#4963
Tests added there.
DanielNoord added a commit to DanielNoord/pylint that referenced this issue Sep 5, 2021
This closes pylint-dev#4963 and is based on the fix in PyCQA/astroid#41165
@Pierre-Sassoulas Pierre-Sassoulas added the Crash 💥 A bug that makes pylint crash label Sep 5, 2021
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.11.0 milestone Sep 5, 2021
Pierre-Sassoulas pushed a commit to pylint-dev/astroid that referenced this issue Sep 13, 2021
* Fix crash on datafields
Fixes the crash reported at pylint-dev/pylint#4963
Tests added there.

* Change to ``if not``

* Update astroid/brain/brain_dataclasses.py

* Add tests

* Update and merge test

* Use ``raise UseInferenceDefault``
@Pierre-Sassoulas Pierre-Sassoulas added the Needs astroid update Needs an astroid update (probably a release too) before being mergable label Sep 13, 2021
Pierre-Sassoulas pushed a commit that referenced this issue Sep 14, 2021
* Add tests for dataclasses
This closes #4963 and is based on the fix in pylint-dev/astroid#1165
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.

2 participants