Top "Python-dataclasses" questions

For questions concerning the Python dataclasses module (new in Python 3.7). Dataclasses are python classes but are specifically suited for storing data objects.

What are data classes and how are they different from common classes?

With PEP 557 data classes are introduced into python standard library. They make use of the @dataclass decorator and they are …

python class python-3.7 python-dataclasses
Python dataclass from a nested dict

The standard library in 3.7 can recursively convert a dataclass into a dict (example from the docs): from dataclasses import dataclass, …

python python-3.x python-dataclasses
Type hints in namedtuple

Consider following piece of code: from collections import namedtuple point = namedtuple("Point", ("x:int", "y:int")) The Code above is …

python python-3.x type-hinting namedtuple python-dataclasses
Make the Python json encoder support Python's new dataclasses

Starting with Python 3.7, there is something called a dataclass: from dataclasses import dataclass @dataclass class Foo: x: str However, the …

python python-dataclasses
How can I get Python 3.7 new dataclass field types?

Python 3.7 introduces new feature called data classes. from dataclasses import dataclass @dataclass class MyClass: id: int = 0 name: str = '' When …

python python-dataclasses
Class inheritance in Python 3.7 dataclasses

I'm currently trying my hands on the new dataclass constructions introduced in Python 3.7. I am currently stuck on trying to …

python python-3.x python-3.7 python-dataclasses
Validating detailed types in python dataclasses

Python 3.7 was released a while ago, and I wanted to test some of the fancy new dataclass+typing features. Getting …

python typing python-dataclasses
How can I make a python dataclass hashable without making them immutable?

Say a I have a dataclass in python3. I want to be able to hash and order these objects. I …

python python-3.x hash python-dataclasses
Creating nested dataclass objects in Python

I have a dataclass object that has nested dataclass objects in it. However, when I create the main object, the …

python object serialization nested python-dataclasses
Dataclasses and property decorator

I've been reading up on Python 3.7's dataclass as an alternative to namedtuples (what I typically use when having to …

python python-3.7 python-dataclasses