summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2021-08-27 08:03:00 +0200
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2021-08-30 19:27:06 +0200
commit15b5b564766dc493b4a09f420ceadb57dadd0c18 (patch)
treefa26ab24053d6e115050f0ad221d4e8fc839c78f
parent7cdd8f35cec17c36e98a5dfc385fe0c76962e531 (diff)
downloadpylint-git-15b5b564766dc493b4a09f420ceadb57dadd0c18.tar.gz
Add a regression tests for dataclasses with fields
Refer to #4899, was fixed in astroid's https://github.com/PyCQA/astroid/pull/1144
-rw-r--r--tests/functional/d/dataclass_with_field.py32
-rw-r--r--tests/functional/d/dataclass_with_field.rc2
-rw-r--r--tests/functional/d/dataclass_with_field.txt1
3 files changed, 35 insertions, 0 deletions
diff --git a/tests/functional/d/dataclass_with_field.py b/tests/functional/d/dataclass_with_field.py
new file mode 100644
index 000000000..9a807becb
--- /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 000000000..a17bb22da
--- /dev/null
+++ b/tests/functional/d/dataclass_with_field.rc
@@ -0,0 +1,2 @@
+[testoptions]
+min_pyver=3.7
diff --git a/tests/functional/d/dataclass_with_field.txt b/tests/functional/d/dataclass_with_field.txt
new file mode 100644
index 000000000..1caf8470a
--- /dev/null
+++ b/tests/functional/d/dataclass_with_field.txt
@@ -0,0 +1 @@
+import-error:7:0::Unable to import 'pydantic.dataclasses':HIGH