From 3dd1818d8f630c94ca34a918d7ceddcdf7c6e468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Fri, 17 Sep 2021 16:39:19 +0200 Subject: [PATCH 1/4] Add tests for ``ClassDef`` inference regression Closes #5030 Closes #5036 --- .../r/regression/regression_5030.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/functional/r/regression/regression_5030.py diff --git a/tests/functional/r/regression/regression_5030.py b/tests/functional/r/regression/regression_5030.py new file mode 100644 index 0000000000..f4454f0d51 --- /dev/null +++ b/tests/functional/r/regression/regression_5030.py @@ -0,0 +1,30 @@ +"""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 + +# Example 1 +def is_type_list(f_type: Type) -> bool: + """just here to show the issue""" + return f_type == list + +assert not is_type_list(Tuple) + +# Example 2 +@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"]) From c0ad3ed89527ba55b6e65a7254d4393a575cb794 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Sat, 18 Sep 2021 10:00:34 +0200 Subject: [PATCH 2/4] Fix formatting --- tests/functional/r/regression/regression_5030.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/functional/r/regression/regression_5030.py b/tests/functional/r/regression/regression_5030.py index f4454f0d51..8aa22f8792 100644 --- a/tests/functional/r/regression/regression_5030.py +++ b/tests/functional/r/regression/regression_5030.py @@ -5,14 +5,15 @@ from typing import Dict, List, Any from dataclasses import dataclass, field -# Example 1 +# 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) -# Example 2 + +# https://github.com/PyCQA/pylint/issues/5036 @dataclass class SomeData: """A dataclass.""" From cdd8cd58b6fa4329f099c3f6da2843549e2f8267 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 7 Oct 2021 14:19:56 +0200 Subject: [PATCH 3/4] Require Python 3.7 for test --- tests/functional/r/regression/regression_5030.rc | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 tests/functional/r/regression/regression_5030.rc diff --git a/tests/functional/r/regression/regression_5030.rc b/tests/functional/r/regression/regression_5030.rc new file mode 100644 index 0000000000..a17bb22daf --- /dev/null +++ b/tests/functional/r/regression/regression_5030.rc @@ -0,0 +1,2 @@ +[testoptions] +min_pyver=3.7 From e9f19b33ffa324888d4f657aff4f61a9cbe3e4d1 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 7 Oct 2021 14:21:01 +0200 Subject: [PATCH 4/4] Add changelog entry --- ChangeLog | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index addf49578d..00eb650ec6 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? ============================