Skip to content

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

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

Open
robertvi opened this issue Jul 29, 2023 · 0 comments

Comments

@robertvi
Copy link
Collaborator

robertvi commented Jul 29, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant