Conversation
Also dropped the install condition for aiohttp (it has worked on Python 3.12 for a while now)
| async with Context() as ctx: | ||
| ctx.add_resource(request, types=[Request]) | ||
| async with Context(): | ||
| add_resource(request, types=[Request]) |
There was a problem hiding this comment.
| add_resource(request, types=[Request]) | |
| add_resource(request, types=Request) |
There was a problem hiding this comment.
types accepts a single type, which is the case here, right?
There was a problem hiding this comment.
No, this is what it says in the docstring:
:param types: type(s) to register the resource as (omit to use the type of
value)
And the annotation is:
types: type | Sequence[type] = (),
There was a problem hiding this comment.
hmm so it seems that it can accept a single type, or am I missing something?
There was a problem hiding this comment.
It can, althought the naming of the parameter suggests that it should be passed an iterable of types.
There was a problem hiding this comment.
Fair enough, it doesn't matter a lot.
| async with Context(): | ||
| scope_type = HTTPScope if scope["type"] == "http" else WebSocketScope | ||
| ctx.add_resource(scope, types=[scope_type]) | ||
| add_resource(scope, types=[scope_type]) |
There was a problem hiding this comment.
| add_resource(scope, types=[scope_type]) | |
| add_resource(scope, types=scope_type) |
| add_resource(request) | ||
| if isinstance(request, ASGIRequest): | ||
| ctx.add_resource(request.scope, types=[HTTPScope]) | ||
| add_resource(request.scope, types=[HTTPScope]) |
There was a problem hiding this comment.
| add_resource(request.scope, types=[HTTPScope]) | |
| add_resource(request.scope, types=HTTPScope) |
| if scope["type"] == "http": | ||
| ctx.add_resource(scope, types=[HTTPScope]) | ||
| ctx.add_resource(Request(scope)) | ||
| add_resource(scope, types=[HTTPScope]) |
There was a problem hiding this comment.
| add_resource(scope, types=[HTTPScope]) | |
| add_resource(scope, types=HTTPScope) |
| elif scope["type"] == "websocket": | ||
| ctx.add_resource(scope, types=[WebSocketScope]) | ||
| ctx.add_resource(Request(scope)) | ||
| add_resource(scope, types=[WebSocketScope]) |
There was a problem hiding this comment.
| add_resource(scope, types=[WebSocketScope]) | |
| add_resource(scope, types=WebSocketScope) |
| async with Context(): | ||
| if scope["type"] == "http": | ||
| ctx.add_resource(scope, types=[HTTPScope]) | ||
| add_resource(scope, types=[HTTPScope]) |
There was a problem hiding this comment.
| add_resource(scope, types=[HTTPScope]) | |
| add_resource(scope, types=HTTPScope) |
| add_resource(scope, types=[HTTPScope]) | ||
| elif scope["type"] == "websocket": | ||
| ctx.add_resource(scope, types=[WebSocketScope]) | ||
| add_resource(scope, types=[WebSocketScope]) |
There was a problem hiding this comment.
| add_resource(scope, types=[WebSocketScope]) | |
| add_resource(scope, types=WebSocketScope) |
|
|
||
| async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -> Response: | ||
| current_context().add_resource(request, types=[Request]) | ||
| add_resource(request, types=[Request]) |
There was a problem hiding this comment.
| add_resource(request, types=[Request]) | |
| add_resource(request, types=Request) |
No description provided.