From 5143e3a28b59fcf42addaabb0c93d55f911c890a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Thu, 7 Oct 2021 14:31:35 +0200 Subject: Add tests for ClassDef inference regression (#5037) Closes #5030 Closes #5036 --- ChangeLog | 5 ++++ tests/functional/r/regression/regression_5030.py | 31 ++++++++++++++++++++++++ tests/functional/r/regression/regression_5030.rc | 2 ++ 3 files changed, 38 insertions(+) create mode 100644 tests/functional/r/regression/regression_5030.py create mode 100644 tests/functional/r/regression/regression_5030.rc diff --git a/ChangeLog b/ChangeLog index addf49578..00eb650ec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -75,6 +75,11 @@ Release date: TBA * Add ``is_sys_guard`` and ``is_typing_guard`` helper functions from astroid to ``pylint.checkers.utils``. +* Fix regression on ClassDef inference + + Closes #5030 + Closes #5036 + What's New in Pylint 2.11.1? ============================ diff --git a/tests/functional/r/regression/regression_5030.py b/tests/functional/r/regression/regression_5030.py new file mode 100644 index 000000000..8aa22f879 --- /dev/null +++ b/tests/functional/r/regression/regression_5030.py @@ -0,0 +1,31 @@ +"""Regression in astroid on ClassDef inference with two test cases. +Fixed in https://github.com/PyCQA/astroid/pull/1181""" + +from typing import Tuple, Type +from typing import Dict, List, Any +from dataclasses import dataclass, field + +# https://github.com/PyCQA/pylint/issues/5030 +def is_type_list(f_type: Type) -> bool: + """just here to show the issue""" + return f_type == list + +assert not is_type_list(Tuple) + + +# https://github.com/PyCQA/pylint/issues/5036 +@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"]) diff --git a/tests/functional/r/regression/regression_5030.rc b/tests/functional/r/regression/regression_5030.rc new file mode 100644 index 000000000..a17bb22da --- /dev/null +++ b/tests/functional/r/regression/regression_5030.rc @@ -0,0 +1,2 @@ +[testoptions] +min_pyver=3.7 -- cgit v1.2.1