On Tue, May 5, 2020 at 3:14 PM Steven D'Aprano <steve@pearwood.info> wrote:
On Tue, May 05, 2020 at 02:55:24PM +0200, Alex Hall wrote:

> Perhaps we should take the energy that is going into this thread and direct
> it towards supporting keyword-only arguments in dataclasses, a discussion
> which is apparently struggling:

Why? How are dataclasses relevant (don't assume it is as obvious to
everyone as it may be to you)? I'm especially interested in how
dataclasses may help me solve the DRY problem for module-level
functions:

    def function(spam, eggs, cheese, aardvark):
        do stuff
        call _private_function(spam, eggs, cheese, aardvark)

since this bites me about twice as often as the `self.spam = spam`
issue.
 
Well this thread is meant to be about assigning attributes in `__init__`, which dataclasses do quite well, and OP specifically said (which I quoted) "Maybe a data class which supported kW-only args and pos-only args would suit my use case."
Solving that problem seems quite attainable.

Your idea for parameters() seems pretty good, but it's an ambitious proposal which sounds like it belongs in a new thread. That's just my opinion though, I'm pretty new here and don't know how this stuff works.

I think attempting to solve the larger problem of repeating names (both in your example and the self.spam=spam problem) is best done with a shortcut for same-named parameters as we've been discussing recently, as it's more general and flexible.

dataclasses are a mystery to me, so I don't know what they can and can't
do.)

This is interesting to me. When I first came across attrs I thought it was awesome, but I've never used it. When I heard about dataclasses I was excited and read all about them, but didn't use them for a long time. I've still barely used them. I know others have similar experiences. I wonder why they look so good on paper but just aren't used that much?