Skip to content

Fix @noreentry decorator breaking static type-checking of decorated methods — Closes #183#184

Merged
conradbzura merged 1 commit intowool-labs:masterfrom
conradbzura:183-fix-noreentry-annotation
Apr 23, 2026
Merged

Fix @noreentry decorator breaking static type-checking of decorated methods — Closes #183#184
conradbzura merged 1 commit intowool-labs:masterfrom
conradbzura:183-fix-noreentry-annotation

Conversation

@conradbzura
Copy link
Copy Markdown
Contributor

Summary

Annotate noreentry with a pass-through generic signature so Pyright/Pylance preserve the wrapped callable's type through the decorator. Previously the decorator returned an un-annotated NoReentryBoundMethod instance, so type-checkers inferred decorated attributes as the descriptor type and flagged async with WorkerPool(): ... and async with WorkerProxy(...): ... as not satisfying the AsyncContextManager protocol. The descriptor's __get__ already returns the correct async wrapper at runtime — the fix is purely a type-hint change with no behavioral impact.

Closes #183

Proposed changes

wool/src/wool/utilities/noreentry.py

Type noreentry as Callable[P, R] -> Callable[P, R] using a ParamSpec and TypeVar. The NoReentryBoundMethod(fn) return is suppressed with # type: ignore[return-value] since the descriptor is invoked through __get__ at access time and produces a callable matching the declared signature. No runtime logic changes.

Test cases

No new tests. The change is a pure type annotation — runtime behavior, including the single-use guard semantics, is unchanged and already covered by the existing noreentry suite. The regression is observable only to static type-checkers.

Without a type annotation, static type-checkers inferred the return
type of noreentry as NoReentryBoundMethod. Methods decorated with
@noreentry — including WorkerPool.__aenter__ and WorkerProxy.__aenter__
— were therefore reported as not matching the AsyncContextManager
protocol, producing spurious errors on every async with call site.

Typing noreentry as Callable[P, R] -> Callable[P, R] preserves the
wrapped callable's signature so the checker continues to see the
original async method.
@conradbzura conradbzura self-assigned this Apr 23, 2026
@conradbzura conradbzura marked this pull request as ready for review April 23, 2026 20:27
@conradbzura conradbzura changed the base branch from main to master April 23, 2026 20:27
@conradbzura conradbzura merged commit c5b3f32 into wool-labs:master Apr 23, 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.

Fix @noreentry decorator breaking static type-checking of decorated methods

1 participant