python dataclasses

Creator
Creator
Seonglae ChoSeonglae Cho
Created
Created
2023 Jun 5 4:16
Editor
Edited
Edited
2025 Jul 3 13:54
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] = []
 
 
 
 
[파이썬] 데이터 클래스 사용법 (dataclasses 모듈)
Engineering Blog by Dale Seo
[파이썬] 데이터 클래스 사용법 (dataclasses 모듈)
 
 

Recommendations