Repository navigation
fix: keep sync handlers sync under @inject - #48
Merged
Merged
Conversation
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.
Closes #46
injectalways returned anasync defwrapper. aiohttp checksinspect.iscoroutinefunction(handler)when a route is added, and only wraps a handler that is not a coroutine function in its own adapter. Under@injectit saw a coroutine function, awaited the wrapper, and the wrapper then awaited theResponsereturned by the sync body. The request failed with a 500 andTypeError: 'Response' object can't be awaited.injectnow returns an async wrapper for a coroutine function and a sync wrapper otherwise, the same split modern-di-starlette (#52) and modern-di-flask use. aiohttp sees a plain function, emits its usual "Bare functions are deprecated" warning, and wraps it exactly as it would the undecorated handler. Marker resolution is synchronous in modern-di, so both wrappers share one resolve helper.The signature changes from
Callable[..., Awaitable[T]] -> Callable[..., Awaitable[T]]toCallable[..., T] -> Callable[..., T], so the return type follows the input without overloads. aiohttp's ownHandlertype only admits async handlers, so registering a sync handler still fails type checking in user code, with or without@inject. The new test suppresses that one diagnostic.web.Viewmethods are unchanged. aiohttp awaits view methods directly, so a sync view method fails without@injecttoo.Tests in
tests/test_sync_handlers.pycover a sync handler served end to end (asserting aiohttp's deprecation warning fires, which shows aiohttp treats the decorated handler as sync), the wrapper kind for sync and async input, and the two error paths for sync handlers. Existing tests cover async handlers. The README now says@injectaccepts sync handlers.