Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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


I usually start with a namedtuple unless I need the additional features provided by a dataclass.


Why? Dataclasses are vastly better: more typesafe, less hacky, etc.


The new syntax is basically the same as dataclasses:

  class Employee(NamedTuple):
    name: str
    id: int




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: