python-dataclasses
/python-dataclasses
Pomaga wybrać między dataclass, NamedTuple i pydantic oraz poprawnie ustawić frozen, slots i walidację przy modelowaniu danych strukturalnych.
- Autor
- Amey-Thakur ↗
- Repozytorium
- AI-SKILLS ↗
- Licencja
- MIT
- Ostatnia zmiana repozytorium
- 05.09.2026
Ocena i bezpieczeństwo
- Pliki w paczce
- 1
- Skrypty
- 0
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 0
Brak sygnałów. Repozytorium zmienione 05.09.2026, bez odwołań do wycofanych modeli i API.
MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.
Co robi i kiedy
Pomaga wybrać między dataclass, NamedTuple i pydantic oraz poprawnie ustawić frozen, slots i walidację przy modelowaniu danych strukturalnych.
Oryginalny opis (EN)
Choose between dataclass, NamedTuple, and pydantic, and configure frozen, slots, and validation correctly. Use when modeling structured data in Python or reviewing class boilerplate.
Jak działa
- Method
- Boundaries
Podgląd SKILL.md
---
name: python-dataclasses
description: Choose between dataclass, NamedTuple, and pydantic, and configure frozen, slots, and validation correctly. Use when modeling structured data in Python or reviewing class boilerplate.
---
# Python dataclasses
Pick the lightest structure that enforces what you need: dataclass for
behavior-bearing records, NamedTuple for immutable tuples with names,
pydantic only where data crosses a trust boundary.
## Method
1. **Default to `@dataclass(slots=True)`.** Slots cut per-instance memory
roughly in half and catch attribute typos at assignment. Omit slots only
when you need dynamic attributes, multiple inheritance with other
slotted classes, or `functools.cached_property`.
2. **Freeze value objects.** `frozen=True` gives hashability (with `eq=True`)
and safe use as dict keys and set members. Model identities (things with
a lifecycle) as mutable; model values (money, coordinates, config) as
frozen.
3. **Use NamedTuple when tuple-ness is the point.** Unpacking, positional
returns from internal helpers, zero-cost immutability. Its weakness is
accidental comparison and unpacking compatibility with any same-length
tuple; do not use it for domain models.
4. **Reserve pydantic for untrusted input.** Parsing JSON from an API, env
config, user forms: validation and coercion earn their runtime cost at
the boundary. Inside your own code, plain dataclasses keep imports light
and construction honest.
5. **Validate in `__post_init__`, not in callers.** Raise `ValueError` there
for invariants ("port must be 1-65535"). For frozen classes set derived
fields with `object.__setattr__(self, "field", value)`.
6. **Beware mutable defaults.** `field(default_factory=list)`, never
`= []`. The class-level default is shared across instances; the factory
is per instance.
7. **Control the generated API.** `kw_only=True` keeps wide constructors
readable and lets you reorder fields without breaking callers;
`repr=False` on secrets keeps them out of logs.
## Boundaries
- Dataclasses do not validate types at runtime; annotations are
documentation plus static-checker input. Do not assume a `int` field
rejects a string.
- Inheritance across dataclasses with defaults is field-order sensitive;
prefer composition when the hierarchy needs more than one level.
Wersje
W bazie nie ma innych skilli o nazwie python-dataclasses.
Migawka bazy z 13.11.2026 · wersja paczki 7d775349890d (skrót SHA-256 całej paczki)
Pobrania w ostatnich 30 dniach: 0 · ranking
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 100writing-dataclasses
Podaje zasady PostHog dla dataclass w Pythonie: kiedy użyć ich zamiast krotki lub słownika, dekorator @frozen, nazewnictwo, ewolucja i ukrywanie sekretów w repr. - 95python-data-classes
Pomaga modelować dane w Pythonie przy użyciu dataclasses, attrs i Pydantic oraz tworzyć struktury danych i modele. - 100writing-data-models
Określa zasady wdrażania i przeglądu modeli danych w Pydantic v2, dataclasses i SQLModel: serializację, niezmienność i wydajność. - 90python-domain-modeling
Projektuje adnotacje typów, obiekty domeny, granice walidacji i modele dataclass lub Pydantic dla inwariantów i kontraktów. - 100pydantic
Pomaga w złożonym modelowaniu danych w Pydantic, bibliotece walidacji i serializacji opartej na typach: ograniczenia pól i hierarchie modeli z podklasami. - 95pydantic
Obsługuje walidację danych w Pydantic v2: BaseModel, walidatory pól i modeli, własne typy, serializację i generowanie schematów, do konfiguracji i typowanych modeli danych w Pythonie.