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

Fatal error with dataclass after 2.11 #5030

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

Fatal error with dataclass after 2.11 #5030

friggog 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

@friggog
Copy link

friggog commented Sep 17, 2021

Bug description

After 2.11 dataclass with dict causes fatal error.

Example code:

"""Example of fatal pylint error with dataclass."""
from typing import Dict, List, Any
from dataclasses import dataclass, field


@dataclass
class SomeData:
    """A dataclass."""
    a_dict: Dict[str, List[str]] = field(default_factory=dict)


@dataclass
class SubSomeData(SomeData):
    """A subclass of a dataclass."""

    def __init__(self, **kwargs: Dict[str, Any]) -> None:
        """Subclass init func."""
        super().__init__(**kwargs)
        if "test" in self.a_dict:
            print(self.a_dict["test"])

Configuration

No response

Command used

pylint pylint_test.py

Pylint output

Exception on node <If l.19 at 0x206550d06c8> in file '..\pylint_test.py'
Traceback (most recent call last):
  File "...\lib\site-packages\pylint\utils\ast_walker.py", line 75, in walk
    callback(astroid)
  File "...\lib\site-packages\pylint\checkers\base.py", line 1104, in visit_if
    self._check_using_constant_test(node, node.test)
  File "...\lib\site-packages\pylint\checkers\base.py", line 1142, in _check_using_constant_test
    inferred = utils.safe_infer(test)
  File "...\lib\site-packages\pylint\checkers\utils.py", line 1181, in safe_infer
    value = next(infer_gen)
  File "...\lib\site-packages\astroid\nodes\node_ng.py", line 105, in infer
    yield from self._infer(context, **kwargs)
  File "...\lib\site-packages\astroid\inference.py", line 872, in _infer_compare
    retval = _do_compare(lhs, op, rhs)
  File "...\lib\site-packages\astroid\inference.py", line 842, in _do_compare
    left, right = _to_literal(left), _to_literal(right)
  File "...\lib\site-packages\astroid\inference.py", line 814, in _to_literal
    return ast.literal_eval(node.as_string())
  File "...\lib\site-packages\astroid\nodes\node_ng.py", line 547, in as_string
    return AsStringVisitor()(self)
  File "...\lib\site-packages\astroid\nodes\as_string.py", line 55, in __call__
    return node.accept(self).replace(DOC_NEWLINE, "\n")
  File "...\lib\site-packages\astroid\nodes\node_ng.py", line 186, in accept
    return func(self)
  File "...\lib\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 pylint_test
pylint_test.py:1:0: F0001: Fatal error while checking 'pylint_test.py'. Please open an issue in our bug tracker so we address this. There is a pre-filled template that you can use in 'C:\Users\chewitt\AppData\Local\pylint\pylint\Cache\pylint-crash-2021-09-17-09.txt'. (fatal)

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

Expected behavior

As on 2.10:

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

Pylint version

2.11.*

astroid==2.8.0

OS / Environment

Windows 10

Additional dependencies

No response

@friggog friggog added Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 17, 2021
@DanielNoord
Copy link
Collaborator

Adding if node.keywords seems to work, but I don't immediately have a good idea about a unittest for this.
Unittest should be added to tests/unittest_brain_dataclasses.py in astroid.

@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 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling Bug 🪲 Needs astroid update Needs an astroid update (probably a release too) before being mergable 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 the Needs astroid update Needs an astroid update (probably a release too) before being mergable label Sep 17, 2021
@DanielNoord DanielNoord added this to the 2.11.2 milestone Sep 17, 2021
@cdce8p cdce8p reopened this Sep 17, 2021
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
3 participants