Skip to main content
Filter by
Sorted by
Tagged with
-2 votes
1 answer
62 views

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)" # `...
Guti_Haz's user avatar
  • 2,752
3 votes
1 answer
70 views

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 ...
globglogabgalab's user avatar
0 votes
0 answers
31 views

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 ...
Aadvik's user avatar
  • 1,522
2 votes
2 answers
91 views

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 ...
Dominik Kaszewski's user avatar
0 votes
1 answer
46 views

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 ...
Hecatonchires's user avatar
4 votes
3 answers
158 views

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 ...
Jaime 's user avatar
  • 143
1 vote
2 answers
122 views

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 ...
5th's user avatar
  • 2,515
1 vote
1 answer
103 views

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]) -> '...
hvtilborg's user avatar
  • 1,487
0 votes
1 answer
205 views

How to do add support for custom smart type completion in Python? Let's say I have a dataclass: @dataclass class MyData: mine: str yours: str def col(self, value: str): return "The ...
Ant's user avatar
  • 5,484
0 votes
0 answers
79 views

IPython/Jupyter has built-in functionality to visualise JSON structures as an interactive tree where you can expand and collapse nodes. I like using it for lists and dictionaries, but now I want to ...
sTievie's user avatar
  • 75
2 votes
1 answer
132 views

I have a Protocol subclass that defines objects with attributes from an external library: class P(Protocol): val: int For testing purposes, I want to turn this protocol class into something I can ...
Jan Šimbera's user avatar
0 votes
1 answer
61 views

Less object oriented snippet (1): class Trickjump(TypedDict): id: int name: str difficulty: str ... Dataclass snippet (2): @dataclass class Trickjump(): id: IdAttr name: ...
JoniKauf's user avatar
  • 346
2 votes
2 answers
346 views

Consider a simple data class: from ctypes import c_int32, c_int16 from dataclasses import dataclass @dataclass class MyClass: field1: c_int32 field2: c_int16 According to the docs, if we ...
PavelDev's user avatar
  • 713
2 votes
1 answer
82 views

How can I express @dataclass class Measurements: width: int height: int head_left: int head_right: int head_width: int head_top: int head_bottom: int head_height: int ...
Nils's user avatar
  • 434
0 votes
1 answer
49 views

I have a parent class, that contains a child class. Both are implemented with python dataclasses. The classes look like this: from __future__ import annotations from dataclasses import dataclass @...
Hazel's user avatar
  • 313
1 vote
0 answers
75 views

I have been struggling to refactor this marshmellow schema to pydantic 2. Problem is with AttributeValue field. When I refactor this to pydantic, I always get strange errors regarding this field. This ...
Sharmiko's user avatar
  • 643
0 votes
0 answers
71 views

I am using numpy arrays extensively in my codebase. The different columns of the array relate to different data. I want to create a class that enforces some schema and allows custom methods to be ...
MattLovesJam's user avatar
2 votes
1 answer
267 views

Is there a consistent way of reading a c struct from a file back into a Python Dataclass? E.g. I have this c struct struct boh { uint32_t a; int8_t b; boolean c; }; And I want to read it's data ...
Brendon Mendicino's user avatar
0 votes
1 answer
45 views

I have a dataclass use strategy that is quite flexible, but I am unsure if it is relying on features that aren't part of the type contract. I am often telling people to not rely on the insertion order ...
probinso's user avatar
  • 307
-1 votes
3 answers
101 views

I'd like to create a decorator that basically wraps an already existing decorator that has parameters, such that the new decorator acts like the old one with some of the arguments supplied. ...
VY_CMa's user avatar
  • 355
0 votes
2 answers
81 views

Here is descriptor class: #descriptor class Validator: def __set_name__(self,owner,name): self.private_name = '_' + name def __set__(self,obj,value): self.validate(value) ...
Subham Kumar's user avatar
0 votes
1 answer
346 views

In my code, I am generating classes run-time using the make_dataclass function. The problem is that such dataclasses cannot be serialized with pickle as shown in the code snippet here below. It is ...
toto's user avatar
  • 367
0 votes
1 answer
67 views

Can this dataclass declaration: @dataclass class Point: x: float y: float z: float be rewritten in order to reduce boilerplate and resemble something like this: @dataclass class Point: x, y, ...
Paul Jurczak's user avatar
  • 8,630
1 vote
1 answer
201 views

Let's say I have the following class: from dataclasses import dataclass from typing import Annotated @dataclass class Pizza: price: Annotated[float, "money"] size: Annotated[float, &...
sams-studio's user avatar
3 votes
2 answers
324 views

In opposition to standard classes in Python dataclasses fields must have a type annotation. But I don't understand what the purpose of these type annotations really is. One can create a dataclass like ...
asmaier's user avatar
  • 11.9k

1
2 3 4 5
21