Skip to content

Fix ValueError on wrapper loops in inspect.unwrap#607

Merged
gaborbernat merged 7 commits into
tox-dev:mainfrom
worksbyfriday:fix-wrapper-loop-valueerror
Feb 17, 2026
Merged

Fix ValueError on wrapper loops in inspect.unwrap#607
gaborbernat merged 7 commits into
tox-dev:mainfrom
worksbyfriday:fix-wrapper-loop-valueerror

Conversation

@worksbyfriday

Copy link
Copy Markdown
Contributor

Summary

Catches ValueError from inspect.unwrap() in both process_signature and process_docstring. This fixes crashes when documenting objects with circular __wrapped__ chains, such as SQLAlchemy's mapped_column.

Fixes #405

Changes

  • process_signature: wraps inspect.unwrap(obj) in try/except ValueError, returns None on failure (skips signature processing)
  • process_docstring: wraps inspect.unwrap(obj) in try/except ValueError, returns early on failure (skips docstring processing)
  • Added two regression tests: test_process_docstring_wrapper_loop and test_process_signature_wrapper_loop

Test plan

  • New tests create a function with circular __wrapped__ and verify no ValueError is raised
  • Full test suite passes (165 tests)

@gaborbernat gaborbernat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

CI failing.

Catch ValueError from inspect.unwrap() in both process_signature and
process_docstring. This fixes crashes when documenting objects with
circular __wrapped__ chains, such as SQLAlchemy's mapped_column.

Fixes tox-dev#405
@worksbyfriday
worksbyfriday force-pushed the fix-wrapper-loop-valueerror branch from f9ca136 to 22e5f0e Compare February 17, 2026 22:47
worksbyfriday and others added 4 commits February 17, 2026 22:53
Pass empty dict and strings for unused parameters, adding
type: ignore annotation since the test only exercises the
inspect.unwrap ValueError guard path.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
The dict literal needs the arg-type ignore (Options expected),
but the str arguments are already compatible with str params.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

@gaborbernat gaborbernat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please run and fix the pre-ocmmit checks.

@worksbyfriday

Copy link
Copy Markdown
Contributor Author

Fixed — added PLR0912 to the noqa suppression on process_signature. All pre-commit checks passing now.

Comment thread tests/test_sphinx_autodoc_typehints.py Outdated
@worksbyfriday

Copy link
Copy Markdown
Contributor Author

Fixed — now passing Options() (which is a valid empty options dict) instead of {} with type: ignore.

@gaborbernat
gaborbernat merged commit 291a131 into tox-dev:main Feb 17, 2026
8 checks passed
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.

autodoc-typehints fails on SQLAlchemy models

2 participants