Skip to content

Fix suppression lifetime for coroutine functions - #604

Open
adenzhou1350 wants to merge 2 commits into
agronholm:masterfrom
adenzhou1350:codex/fix-async-typecheck-suppression
Open

adenzhou1350 wants to merge 2 commits into
agronholm:masterfrom
adenzhou1350:codex/fix-async-typecheck-suppression

Conversation

@adenzhou1350

Copy link
Copy Markdown

Changes

@suppress_type_checks currently restores checking as soon as an async function returns its coroutine object, before its body runs. For example, a decorated async def that calls check_type(1, str) after an await still raises TypeCheckError.

Use an async wrapper for coroutine functions and reuse the existing suppression context manager around the await. Suppression starts on execution, survives suspension, and unwinds on completion, exception or cancellation. Synchronous functions and the existing globally shared suppression semantics are unchanged; this does not introduce task-local isolation or generator support.

Validation

  • Five new regression nodes fail on unchanged production code and pass with the fix. They cover direct/instrumented checking, nesting, exceptions and cancellation, plus coroutine identity, argument/return forwarding, creation without activation and restoration.
  • Windows CPython 3.12 full suite: 540 passed, 9 skipped, 9 xfailed (warnings treated as errors by project configuration).
  • Pinned Ruff 0.15.20 lint/format and git diff --check: pass.
  • A clean, non-incremental full-source mypy 2.1.0 run reports the same pre-existing missing typeshed.stdlib.types import at _decorators.py:22 on baseline and candidate. No additional error is reported. Other Python versions and the Sphinx build have not been run locally.

Checklist

  • Added failing-before regression tests
  • Updated the user guide and API documentation
  • Added a changelog entry

Signed-off-by: Xucheng Zhou <aden1350@outlook.com>
Signed-off-by: Xucheng Zhou <aden1350@outlook.com>
@coveralls

coveralls commented Oct 9, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 94.876% (+0.02%) from 94.853% — adenzhou1350:codex/fix-async-typecheck-suppression into agronholm:master

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.

2 participants