Fix inherited default method overrides (#1549) - #1626
Open
sb123sb123 wants to merge 1 commit into
Open
sb123sb123 wants to merge 1 commit into
sb123sb123 wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1549
Issue: #1549
Problem
A subclass that overrides the method used by an inherited @field.default factory still receives the base class default. The generated initializer retains the parent factory, so the override is silently ignored.
Cause
Inherited attrs.Attribute instances carry the Factory created while the base class is built. Base-attribute collection did not resolve a replacement self-taking factory from the subclass when that method was overridden.
Fix
Rebind inherited self-taking default factories when the subclass resolves a different callable under the original factory name. The behavior is applied to both MRO collection paths and covered for attr.s and attr.define.
Tests
tests/test_make.py -k inherited_default_method_override)git diff --check: passedLimitations
tests/test_converters.py::TestPipe::test_wrapped_annotationfails on this Windows/Python 3.11 host and reproduces on a clean origin/main worktree; it is excluded from the package-suite result above.AI assistance disclosure
OpenAI Codex assisted with repository research, implementation, testing, and drafting this PR. The submitter reviewed the change and takes full technical and legal responsibility for every line. No AI tool is included as a co-author.