-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fix errors caused in jinja StrictUndefined mode #2571
Conversation
|
||
Fixes: | ||
|
||
* Jinja templates can now be loaded in StrictUndefined mode. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure if 1) this change warranted an entry,
2) this was the correct version header
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great - that'll be the next version, so perfect :)
@@ -3,6 +3,7 @@ | |||
|
|||
from admin import app | |||
from admin.data import build_sample_db | |||
from jinja2 import StrictUndefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the optimal import sorting, given that "admin" is a local folder, but ruff does not know that. I could use "." to make it clearer, or we could just be okay with it.
This seems to be the only example complex enough to have both an app.py and a folder of other modules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am personally fine with it. If someone was so inclined, we could probably add some ruff config that would help it sort "correctly" - but I consider it broadly unimportant given the small scope, as you note.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work on this - thank you :)
Fixes #2522
This PR addresses errors that arise when running jinja in StrictUndefined mode (like mypy for Jinja!). There were different ways that I addressed the issues depending on the attribute:
Generally, for most cases, I ended up using the "is defined" pattern, but if you think there are more situations where .py changes would be warranted, let me know!