Dat Python, dataclass

Tags

  • py

Dataclasses are cool, but what’s cooler is using immutable structures as your default parameters. Do it like so:

import dataclasses as dc

@dc.dataclass(frozen=True)
class MinCut:
  T:set = dc.field(
    default_factory=set, compare=False)
  F:set = dc.field(
    default_factory=set, compare=False)

Also check out some more magic in the official docs. Of note: representation, __post_init__ hooks, dataclasses.replace fields.