Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrated to Asphalt 5 #68

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open

Migrated to Asphalt 5 #68

wants to merge 18 commits into from

Conversation

agronholm
Copy link
Member

No description provided.

@coveralls
Copy link

coveralls commented Dec 30, 2024

Coverage Status

coverage: 99.617% (+7.3%) from 92.283%
when pulling ec37026 on asphalt5
into 917211b on master.

async with Context() as ctx:
ctx.add_resource(request, types=[Request])
async with Context():
add_resource(request, types=[Request])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
add_resource(request, types=[Request])
add_resource(request, types=Request)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

types accepts a single type, which is the case here, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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] = (),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm so it seems that it can accept a single type, or am I missing something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can, althought the naming of the parameter suggests that it should be passed an iterable of types.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, it doesn't matter a lot.

scope_type = HTTPScope if scope["type"] == "http" else WebSocketScope
ctx.add_resource(scope, types=[scope_type])
add_resource(scope, types=[scope_type])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
add_resource(scope, types=[scope_type])
add_resource(scope, types=scope_type)

if isinstance(request, ASGIRequest):
ctx.add_resource(request.scope, types=[HTTPScope])
add_resource(request.scope, types=[HTTPScope])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
add_resource(scope, types=[WebSocketScope])
add_resource(scope, types=WebSocketScope)

if scope["type"] == "http":
ctx.add_resource(scope, types=[HTTPScope])
add_resource(scope, types=[HTTPScope])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
add_resource(scope, types=[WebSocketScope])
add_resource(scope, types=WebSocketScope)


await super().__call__(scope, receive, send)

async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -> Response:
current_context().add_resource(request, types=[Request])
add_resource(request, types=[Request])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
add_resource(request, types=[Request])
add_resource(request, types=Request)

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.

3 participants