-
-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow keyword-only attributes before positional attributes #448
Comments
it’s indeed weird that we don’t allow kw_only attributes anywhere. Someone should research why we chose that route. they are a lot more useful if you can sprinkle them anywhere. |
I suspect that "Non keyword-only attributes are not allowed after a keyword-only attribute" because that's an existing constraint in function argument ordering. One problem is allowing them anywhere is that the ordering of arguments to |
Agreed this type of functionality would be useful. I'm curious what a current best-practice workaround would look like. |
This has been fixed by #559 |
I want to be able to write both
Message("message", timestamp=time.time())
andMessage("message")
, wheretimestamp
is an attribute of a base class. Currently the following code:produces the following error:
As
timestamp
is keyword-only, it, as far as I understand, does not pose an ordering issue.(In my particular use-case, I have a bunch of
Message
s that are convenient to create using positional arguments, but thetimestamp
field is not always meaningful, e.g. for outgoing messages)The text was updated successfully, but these errors were encountered: