Skip to content

docs: explain decorator defaults in subclasses - #1651

Open
MonikaDvorackova wants to merge 2 commits into
python-attrs:mainfrom
MonikaDvorackova:docs/inherited-default-decorator
Open

MonikaDvorackova wants to merge 2 commits into
python-attrs:mainfrom
MonikaDvorackova:docs/inherited-default-decorator

Conversation

@MonikaDvorackova

Copy link
Copy Markdown

Summary

Fixes #753.

The defaults section now explains that decorator-based defaults can reference only fields declared in the same class body. A doctest shows how a subclass can redeclare an inherited field to provide its own default.

This is a documentation-only change.

@Franky100-pig Franky100-pig left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redeclaring value in Child also drops anything Base set on that field — validators, converters,
metadata. The example is fine as-is but it reads like a free override; worth one sentence saying the
whole field is replaced, or showing field(default=...) as the alternative when Base has a validator.

@MonikaDvorackova

Copy link
Copy Markdown
Author

Thanks for the suggestion. I added a sentence clarifying that redeclaring value replaces the inherited field, including its validator, converter, and metadata.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

Subclassed decorator methods not working

2 participants