python dataclasses

Creator
Creator
Seonglae Cho
Created
Created
2023 Jun 5 4:16
Editor
Edited
Edited
2024 Feb 29 5:9
auto generate
Python Object Member
Does not use
Python __slots__
as default
python dataclasses members
from dataclasses import dataclass from datetime import date # Slots option is available after python 3.10 @dataclass(slots=True) class User: id: int name: str birthdate: date admin: bool = False
 
 

Immutable

@dataclass(frozen=True)
 
 

Order

@dataclass(order=True)
 
 

Hash Key

@dataclass(unsafe_hash=True)
 
 

Default value for dynamic type is error

@dataclass(unsafe_hash=True) class User: id: int name: str birthdate: date admin: bool = False friends: List[int] = []
 
 
 
 
 
 

Recommendations