Skip to content

Fix inherited default method overrides (#1549) - #1626

Open
sb123sb123 wants to merge 1 commit into
python-attrs:mainfrom
sb123sb123:fix/1549-inherited-default-method
Open

sb123sb123 wants to merge 1 commit into
python-attrs:mainfrom
sb123sb123:fix/1549-inherited-default-method

Conversation

@sb123sb123

Copy link
Copy Markdown

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

  • Focused regression: 2 passed (tests/test_make.py -k inherited_default_method_override)
  • Package suite excluding one clean-baseline converter annotation failure: 1,402 passed, 10 skipped, 1 deselected, 1 xfailed
  • Ruff check: passed for the repository
  • Ruff format check: passed for the repository
  • git diff --check: passed

Limitations

  • tests/test_converters.py::TestPipe::test_wrapped_annotation fails on this Windows/Python 3.11 host and reproduces on a clean origin/main worktree; it is excluded from the package-suite result above.
  • Python 3.13/3.14-, PyPy-, and Pyright-specific tests were skipped because those runtimes/tools are unavailable on the host.
  • The repository pre-commit run could not initialize the interrogate hook because the host could not connect to github.com:443; Ruff and the focused/full practical tests passed.

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.

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.

Decorated functions do not work with inheritance

1 participant