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

Cleanup Context type alias #5883

Closed
1 task done
AustinScola opened this issue Jul 15, 2021 · 5 comments
Closed
1 task done

Cleanup Context type alias #5883

AustinScola opened this issue Jul 15, 2021 · 5 comments

Comments

@AustinScola
Copy link
Contributor

Is your feature request related to a problem?

When typing an application, there is no type alias for a cleanup context available for users to use.

Describe the solution you'd like

Add a type alias CleanupContext to aiohttp.typedefs:

CleanupContext = Callable[[Application], AsyncIterator[None]]

Describe alternatives you've considered

  • Define it myself in my code.
  • Don't bother typing it

Related component

Server

Additional context

This is similar to #5842 which was addressed in #5847.

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct
@Dreamsorcerer
Copy link
Member

What's an example of when this would be used?

@AustinScola
Copy link
Contributor Author

Here is an example of how a user might use this:

from typing import List

from aiohttp.web import Application

from server.contexts.database_client import database_client_context
from server.contexts.web_client import web_client_context

app = Application()

contexts: List[CleanupContext] = [database_client_context, web_client_context]
for context in contexts:
    app.cleanup_ctx.append(context)

@AustinScola
Copy link
Contributor Author

It could also be used internally in aiohttp.

@Dreamsorcerer
Copy link
Member

Seems reasonable enough. I've added it to #4686. Feel free to make a PR (also, one for Middleware if you fancy closing out that issue).

@AustinScola
Copy link
Contributor Author

Will do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants