From a8282478a036a9853c4ffe17358e9944f0f00907 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Fri, 27 Aug 2021 08:03:00 +0200 Subject: [PATCH] Add a regression tests for dataclasses with fields Refer to #4899, was fixed in astroid's https://github.com/PyCQA/astroid/pull/1144 --- tests/functional/d/dataclass_with_field.py | 32 ++++++++++++++++++++++ tests/functional/d/dataclass_with_field.rc | 2 ++ 2 files changed, 34 insertions(+) create mode 100644 tests/functional/d/dataclass_with_field.py create mode 100644 tests/functional/d/dataclass_with_field.rc diff --git a/tests/functional/d/dataclass_with_field.py b/tests/functional/d/dataclass_with_field.py new file mode 100644 index 00000000000..9a807becbf4 --- /dev/null +++ b/tests/functional/d/dataclass_with_field.py @@ -0,0 +1,32 @@ +"""Regression test for https://github.com/PyCQA/pylint/issues/4899""" + +# pylint: disable=missing-docstring,too-few-public-methods + +from dataclasses import field +from typing import List +from pydantic.dataclasses import dataclass # [import-error] + + +class Item: + pass + + +@dataclass +class Case: + """Case class (group Item)""" + + name: str + irr: float = 0 + items: List[Item] = field(default_factory=lambda: []) + + def add_item(self, item: Item) -> None: + """Add an item to the item list.""" + + self.items.append(item) + + def find_item(self, description: str) -> Item: + """Find an item by description""" + + return next( + (item for item in self.items if item.description == description), None + ) diff --git a/tests/functional/d/dataclass_with_field.rc b/tests/functional/d/dataclass_with_field.rc new file mode 100644 index 00000000000..a17bb22dafb --- /dev/null +++ b/tests/functional/d/dataclass_with_field.rc @@ -0,0 +1,2 @@ +[testoptions] +min_pyver=3.7