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 51bed96
Showing 1 changed file with 32 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
)

0 comments on commit 51bed96

Please sign in to comment.