Sync main with release#308
Merged
Merged
Conversation
Pushing a guarded context manager onto an ExitStack or AsyncExitStack raised TypeError, the error the decorator emits for bare functions. contextlib looks special methods up on the type and calls them unbound, so type(cm).__enter__(cm) reaches the descriptor itself rather than a bound wrapper, and __call__ rejected it. WorkerPool was affected: a pool could not be composed onto a stack alongside other resources. Record the owning class via __set_name__ and treat an owned descriptor invoked with an instance of its owner as the bound call it actually is, delegating through __get__ so the guard, the coroutine-ness, and the wrapper cache all still apply. Class-level access keeps returning the descriptor, so introspection is unchanged, and a bare function still has no owner and is still rejected. Teardown works the same way: contextlib registers exit as a method of the type, so a guarded __exit__ receives its exception triple through the same path.
Pin the reported failure at both the utility and the WorkerPool level: a guarded manager enters through ExitStack and AsyncExitStack, and the guard still rejects a second entry there. Guard the argument-forwarding half of the contract, which nothing exercised. contextlib registers teardown as a method of the type, so a guarded exit is routed through the descriptor with its exception triple as trailing arguments; every prior test entered with no arguments at all, so an implementation that dropped them silently passed. Cover the exception details reaching a guarded exit through both stacks, and argument forwarding on a direct unbound call. Pin the guard as shared across the bound and unbound call forms, by example and by a property over arbitrary interleavings of the two, so the widened dispatch cannot become a way around single-use semantics. Cover a subclass entering through a stack, since dispatch admits any instance of the owning class rather than only exact instances, and the plain statement form, which had no coverage of its own. Rename the bare-function test to say what it asserts: it calls an owned descriptor with no instance, which is a distinct rejection branch from a genuinely unowned function. Drop the unbound-access test, whose only assertion could not fail.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Auto-generated by the sync branches workflow.