> > It becomes more painful the more parameters the parent has- parameters > which the dataclass may not even care about. It not only makes the class > definition long, it adds so these additional parameters to the init > signature, which is icky for introspection and discoverability. Lots of > "What the heck is this parameter doing here?" head scratching for future me > (because I forget everything). > > > I think that’s backward. The signature is there for the user of the > dataclass, not the implementer. And the user had better care about that x > argument, because it’s a mandatory parameter of the X class, so if they > don’t pass one, they’re going to get an exception from inside some class > they never heard of. So having x show up in the signature would be helpful > for introspection and discovery, not harmful. It makes your users ask “What > the heck is the x parameter doing here?” but that’s a question that they’d > better have an answer to or they can’t construct a Y instance. (And notice > that the X doesn’t take or pass along *args, so if the Y claims to take > *args as well as **kwargs, that’s even more misleading, because passing any > extra positional args to the constructor will also raise.) And that’s as > true for tools as for human readers—an IDE auto-completing the parameters > of Y(…) should be prompting you for an x; a static analyzer should be > catching that you forgot to pass as x; etc. >
This is a good critique of what I said! Just want to clarify, though, that I was thinking the entire time of OPTIONAL arguments-- like, for example, of the kind heavily used in pandas. There tons of optional arguments in that library I do not care about, ever. But you are correct about non-optional arguments.
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/KIDHIKHW7WTRYMM3BCDFN2FXD3JCJKNA/ Code of Conduct: http://python.org/psf/codeofconduct/