3 ms·
If you have enough arguments that the signature becomes obscure to read you need a dataclass to pass into the function instead. I would rather: @dataclass
by jpc0 3y ago
If you have enough arguments that the signature becomes obscure to read you need a dataclass to pass into the function instead.
I would rather:
@dataclass(frozen=True, slots=True)
class VarThings:
n: int
...
def variable(a: VarThings):
...
Than a million args
- b5n 3y agoI usually start with a namedtuple unless I need the additional features provided by a dataclass.
- joshuamorton 3y agoWhy? Dataclasses are vastly better: more typesafe, less hacky, etc.
- akvadrako 3y agoThe new syntax is basically the same as dataclasses: class Employee(NamedTuple): name: str id: int