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

filters from setup(...) has incorrect type annotation #330

Closed
rkdl opened this issue Mar 23, 2020 · 0 comments · Fixed by #331
Closed

filters from setup(...) has incorrect type annotation #330

rkdl opened this issue Mar 23, 2020 · 0 comments · Fixed by #331

Comments

@rkdl
Copy link
Contributor

rkdl commented Mar 23, 2020

Hi, I've found a small typing issue after updating aiohttp_jinja2 from 1.1.0 to 1.2.0
mypy report:

app.py:125: error: Dict entry 0 has incompatible type "str": "Callable[[Any], str]"; expected "Callable[..., str]": "Callable[[Any], str]"

and the example code is

def statify(state) -> str:
    return json.dumps(state, ensure_ascii=False, indent=3)

aiohttp_jinja2.setup(
   app,
   loader=jinja2.FileSystemLoader('templates'),
   filters={'statify': statify},
)

PyCharm type checker also reports about typing issue

Expected type 'Optional[Iterable[(...) -> str]]', got 'Dict[str, (state: Any) -> str]' instead

The thing is, filters must be either mapping or iterable of key/value pairs, as it's passed to dict.update method, but current type annotation requires it to be a plain iterable of callables

if filters is not None:
    env.filters.update(filters)
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.

1 participant