Eric V. Smith <> added the comment:

I'd forgotten about this issue and created #33493. I'll close it. Copied here 
is my comment from that issue:

I've had several requests for keyword-only arguments. This is a placeholder to 
remind me to work on it. I have not decided if it's a good idea or not.

I propose adding a keyword_only argument to field(), defaulting to False.

I'm thinking that the basic idea would be to put all keyword-only fields at the 
end of the arguments to __init__, but for all other uses, leave them where they 
appear in the class definition. That way comparison operations, in particular, 
would use the fields as they appear in the class definition (which is the 
current behavior). Since they'd be at the end of __init__, and since order 
doesn't matter (they're keyword-only, after all), then this would work as 
expected for base classes.

That is, given:

class B:
    a: field(type=int, keyword_only=True)
    b: int

class C(B):
    c: int
    d: field(type=int, keyword_only=True)

Then B's __init__ would take (b, c, *, a, d) as its arguments, but its 
comparison functions would compare the tuples as (a, b, c, d).

It would be an error for a ClassVar field to be keyword-only. I think it would 
be okay if an InitVar field were keyword-only, but I haven't given it a lot of 


Python tracker <>
Python-bugs-list mailing list

Reply via email to