I'll see if I can find out how positional only and keyword only arguments are used in __init__ methods in the wild and I'll see if there have been any other discussions talking about what this approach could offer.
On Sun, 17 Apr 2022 at 02:54, dn <pythonl...@danceswithmice.info> wrote: > > On 17/04/2022 09.20, Sam Ezeh wrote: > >> Perhaps I'm missing the point, but what functionality or advantage(s) > >> does this give, over data-classes? > > > > One advantage is maintaining control over the __init__ function without > > having to write extra code to do so. In the linked discussion from > > python-ideas, it was mentioned that keyword-only and positional-only > > arguments can't be used with dataclasses [1]. > > > >> Maybe Dataclasses are not being used as much as one might hope, but they > >> are relatively new, and many Python-Masters simply carry-on constructing > >> classes the way they have for years... > > > > I think one concern I have is that even if this is useful, it might > > still fall to the same fate. > > > Don't be discouraged by that - and that thread was not the first of such > discussions! The way Python is being applied is continually changing... > > I'm not sure about the criticism of dataclasses though. Starting with > 'explicit over implicit', once a parameter-list is more than two or > three long, shouldn't we be using 'labels' in order to avoid (potential) > confusion, ie keyword-parameters? > > This removes the order/sequence of arguments from the list of potential > problems/gotchas one can fall into! > > In which case, I'm wondering just how often the criticism applies 'in > real life'? > > So, now the question becomes: what are the cases/examples which > require/desire improvement over the 'traditional' __init__ of > attributes, and facilities offered through dataclasses? > -- > Regards, > =dn > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list