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

Templating engines (jinja2, ...) #8249

Closed
dumblob opened this issue Jan 6, 2020 · 3 comments
Closed

Templating engines (jinja2, ...) #8249

dumblob opened this issue Jan 6, 2020 · 3 comments

Comments

@dumblob
Copy link

dumblob commented Jan 6, 2020

  • Are you reporting a bug, or opening a feature request?

Can't judge (I'm new to mypy). Therefore first of all just question whether I'm missing something.

  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.

E.g. any Flask app as Flask uses jinja2 templating engine.

  • What is the actual behavior/output?
templates/dashboard.html:1: error: invalid syntax
Found 1 error in 1 file (checked 6 source files)

(note how mypy didn't output any other error though the other 5 files are *.py files full of typing errors if checked separately)

  • What is the behavior/output you expect?

mypy shall find out relevant parts in templates and then checks them (e.g. pytype from Google seems to do that somehow if I'm not mistaken) instead of outputting such a general error which additionally suppresses all other errors in other files 😮

  • What are the versions of mypy and Python you are using?

mypy 0.761 (release)
Python 3.8.1 (release)

Do you see the same issue after installing mypy from Git master?

didn't check

  • What are the mypy flags you are using? (For example --strict-optional)

no flags

  • If mypy crashed with a traceback, please paste
    the full traceback below.

no traceback, just the output above 😢

@JelleZijlstra
Copy link
Member

How are you invoking mypy? It should normally just pick up Python files.

Perhaps a system could be built by which mypy could extract the Python parts of a template file and typecheck them, but that's not going to be easy.

@dumblob
Copy link
Author

dumblob commented Jan 7, 2020

Thanks for a quick response.

How are you invoking mypy?

mypy *.py templates/*html

It should normally just pick up Python files.
I need to whitelist what shall be checked (there are python files which I definitely don't want to check in some (sub)directories and there are non-python files like templates which I definitely want to check).

I came here from pytype because I wanted to check against Python 3.8 and pytype support for 3.8 lands not earlier than in March/April.

Perhaps a system could be built by which mypy could extract the Python parts of a template file and typecheck them, but that's not going to be easy.

Fair enough. I think this issue can be closed then as I won't have time to implement injection of mypy check routines in the jinja engine to check templates. If you don't want to close this issue, just tell me and I'll leave it open.

Another thing though is, that mypy doesn't try to skip the errorneous files and report typing errors in other files. If I run it like this (compare it to the above):

mypy *.py

then it works and mypy reports bunch of errors for each of the *.py files (i.e. mypy behaves like I'd expect).

@hauntsaninja
Copy link
Collaborator

mypy isn't going to add native support for jinja2

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Aug 13, 2023
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

4 participants