1,037 questions
-2 votes
1 answer
62 views
dataclass __repr__ shows init=False members
import dataclasses @dataclasses.dataclass class MyClass: a: int b: int = dataclasses.field(default=0, init=False) m = MyClass(a=0) print(repr(m)) # prints: "MyClass(a=0, b=0)" # `...
3 votes
1 answer
70 views
Trying to reduce the verboseness of __post_init__ in a python dataclass
I am writing a Python config script that creates an array of input files in a domain-specific language (DSL), so my use case is a bit unusual. In this scenario, we want medium-level users to be able ...
0 votes
0 answers
31 views
How to use the data class itself as the type of its attribute [duplicate]
I have a data class: from dataclasses import dataclass from typing import Any @dataclass class Url: http: bool params: dict[str: Any] body: str # More stuff here Here I have a Url ...
2 votes
2 answers
91 views
Data class with argument optional only in init
I have the following simple class in Python: class Point: def __init__(x: int, y: int | None = None): self.x = x self.y = y if y is not None else x How can the same thing be ...
0 votes
1 answer
46 views
Find field throwing error in Python Dataclass conversion
I'm trying to convert a json array to a Python list of typed objects. It's data from Teltonika FOTA The call result_list = fromlist(FotaDevice, intermediate_list) is failing with the error message ...
4 votes
3 answers
158 views
Create a typing from a custom dataclass
I'm currently working with a dataclass (defined in one of the dependencies I'm currently working with inside of my project), which is defined similar to this snippet: from dataclasses import dataclass ...
1 vote
2 answers
122 views
Dataclass/attrs based orm models and their relationships
I am building a small python application to learn Domain-Driven-Design (DDD) approaches. Therefore I am using a dataclass/attrs class as my domain model and also use this class to imperatively model ...
1 vote
1 answer
103 views
Python dataclasses, inheritance and alternate class constructors
In Python, I am using dataclass with the following class hierarchy: from dataclasses import dataclass @dataclass class Foo: id: str @classmethod def fromRaw(cls, raw: dict[str, str]) -> '...