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

context_processors arg to setup has wrong type annotation #354

Closed
bmerry opened this issue Jun 22, 2020 · 4 comments
Closed

context_processors arg to setup has wrong type annotation #354

bmerry opened this issue Jun 22, 2020 · 4 comments

Comments

@bmerry
Copy link

bmerry commented Jun 22, 2020

Given this code, with aiohttp_jinja2 1.2.0:

#!/usr/bin/env python3

import os

from aiohttp import web
import aiohttp_jinja2
import jinja2

@aiohttp_jinja2.template('foo.txt')
def handler(request):
    return {}

app = web.Application()
aiohttp_jinja2.setup(
    app,
    loader=jinja2.FileSystemLoader(os.path.abspath('./templates')),
    context_processors=[aiohttp_jinja2.request_processor]
)
app.router.add_get('/foo.txt', handler)
web.run_app(app)

mypy reports this error:

demo.py:17: error: List item 0 has incompatible type "Callable[[Request], Coroutine[Any, Any, Dict[str, Request]]]"; expected "Callable[[Request], Dict[str, Any]]"
@Dreamsorcerer
Copy link
Member

I don't have the code setup right now to test it, but I suspect this line just needs to be updated to expect an awaitable:
https://github.com/aio-libs/aiohttp-jinja2/blob/master/aiohttp_jinja2/__init__.py#L51

context_processors: Iterable[Callable[[web.Request], Awaitable[Dict[str, Any]]]] = ()

@asvetlov
Copy link
Member

Please feel free to prepare a pull request

@Dreamsorcerer
Copy link
Member

Tested out the fix, seems to be correct.

@asvetlov
Copy link
Member

asvetlov commented Nov 3, 2020

Fixed by #386

@asvetlov asvetlov closed this as completed Nov 3, 2020
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 a pull request may close this issue.

3 participants