Category "python-dataclasses"

How to make attribute in dataclass read-only?

Let's say I have a class like this: class C: def __init__(self, stuff: int): self._stuff = stuff @property def stuff(self) -> int:

Combining a descriptor class with dataclass and field

I am using a dataclass and field to pass in a default value. When an argument is provided I want to validate it using a descriptor class. Is there any way to ut

how to solve the recursion problem when specifying type hints for classes from different files

how to solve the recursion problem when specifying type hints for classes from different files models1.py from models2 import Second @dataclass class First:

python3 dataclass with **kwargs(asterisk)

Currently I used DTO(Data Transfer Object) like this. class Test1: def __init__(self, user_id: int = None, body: str = None): self

How can I silence a PyCharm "Unexpected argument" message for simple, indirect object creation

I am getting an "Unexpected argument" message with Python 3.7 and PyCharm 2020.2 when using the code below. from dataclasses import dataclass @dataclass class

How do I pass kwargs to pydantic validator

I'm trying to write pydantic validators, but I can't seem to understand how to make use of the kwargs argument that is mentioned in the docs. I would like to p