Skip to content

Commit

Permalink
Add a regression tests for dataclasses with fields
Browse files Browse the repository at this point in the history
Refer to pylint-dev#4899, was fixed in astroid's pylint-dev/astroid#1144
  • Loading branch information
Pierre-Sassoulas committed Aug 30, 2021
1 parent 7cdd8f3 commit a828247
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/functional/d/dataclass_with_field.py
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
)
2 changes: 2 additions & 0 deletions tests/functional/d/dataclass_with_field.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[testoptions]
min_pyver=3.7

0 comments on commit a828247

Please sign in to comment.