Skip to content

Allow keyword-only attributes before positional attributes #448

@oakkitten

Description

@oakkitten

I want to be able to write both Message("message", timestamp=time.time()) and Message("message"), where timestamp is an attribute of a base class. Currently the following code:

@attrs
class Base:
    timestamp = attrib(kw_only=True, default=None)


@attrs
class Message(Base):
    message = attrib()

produces the following error:

ValueError: Non keyword-only attributes are not allowed after a keyword-only attribute.

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 Messages that are convenient to create using positional arguments, but the timestamp field is not always meaningful, e.g. for outgoing messages)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions