Skip to content

Rewrite closure cells in decorated methods#1560

Open
Sean-Kenneth-Doherty wants to merge 2 commits into
python-attrs:mainfrom
Sean-Kenneth-Doherty:fix/wrapped-method-super-cells
Open

Rewrite closure cells in decorated methods#1560
Sean-Kenneth-Doherty wants to merge 2 commits into
python-attrs:mainfrom
Sean-Kenneth-Doherty:fix/wrapped-method-super-cells

Conversation

@Sean-Kenneth-Doherty
Copy link
Copy Markdown

Summary

  • Recursively inspect wrapped/nested functions when rewriting stale __class__ closure cells for slotted classes.
  • Preserve the existing classmethod, staticmethod, property, cached-property, and method handling while also following closures and __wrapped__ links.
  • Add a regression for a decorated method using zero-argument super().

Fixes #1038.

Tests

  • PYTHONPATH=src python - <<'PY' ... manual issue reproducer now prints A instead of raising TypeError
  • uv run --group tests pytest tests/test_slots.py::TestClosureCellRewriting -q
  • uv run --group tests pytest tests/test_slots.py -q
  • uv run --group tests pytest -q
  • uv run --group dev ruff check src/attr/_make.py tests/test_slots.py
  • uv run --group dev ruff format --check src/attr/_make.py tests/test_slots.py
  • python -m compileall -q src/attr/_make.py tests/test_slots.py
  • git diff --check

@Sean-Kenneth-Doherty Sean-Kenneth-Doherty force-pushed the fix/wrapped-method-super-cells branch from fde0008 to 289f77a Compare May 17, 2026 03:17
@Sean-Kenneth-Doherty Sean-Kenneth-Doherty force-pushed the fix/wrapped-method-super-cells branch from 289f77a to 5251f7a Compare May 17, 2026 07:04
@Sean-Kenneth-Doherty
Copy link
Copy Markdown
Author

Pushed e26ac66 to cover the missing coverage branch in _closure_cells.

The failed coverage job reported only src/attr/_make.py:565 as missing. The added regression creates a self-referential __wrapped__ chain and verifies _closure_cells() stops revisiting wrapped functions.

Local validation after the push:

  • uv run --group tests pytest tests/test_slots.py::TestClosureCellRewriting -q -> 9 passed
  • uv run --group tests pytest tests/test_slots.py -q -> 58 passed, 1 skipped
  • uv run --group tests pytest -q -> 1390 passed, 5 skipped, 1 xfailed
  • uv run --group dev ruff check src/attr/_make.py tests/test_slots.py -> passed
  • uv run --group dev ruff format --check src/attr/_make.py tests/test_slots.py -> passed
  • python -m compileall -q src/attr/_make.py tests/test_slots.py -> passed
  • git diff --check -> passed
  • Targeted coverage run no longer lists line 565 as missing.

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.

TypeError when calling super() in decorated method

1 participant