Skip to content

ValueError: No mandatory attributes allowed after an attribute with a default value or factory. #2

Open
@robertvi

Description

@robertvi

This error is seen whenever a subclass defines a mandatory attribute when a base class defines attribute(s) with default values.

see test_kwonly_fix.py
and test_sbase.py

The docs say to apply kw_only=True to the subclass attribute, and this allows the spec to be defined but still causes and error when trying to instantiate the object: if effectively turns the kw_only attribute into a required attribute as an error happens if no value is set, therefore we need to use default=None to supply a dummy default value anyway.

Therefore the best solution seems to be to ignore kw_only and just set everything to have default=None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions