forked from pylint-dev/pylint
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a regression tests for dataclasses with fields
Refer to pylint-dev#4899, was fixed in astroid's pylint-dev/astroid#1144
- Loading branch information
1 parent
7cdd8f3
commit a828247
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[testoptions] | ||
min_pyver=3.7 |