Open
Conversation
Author
|
The error from
I'll use the older |
Author
|
I think the typing error is basically what I discussed above about the use of The 3.7 error I really don't get. Looking at the manifest, versions 3.7.1-17 are available. |
Member
|
Don't worry about < 3.10. You don't need to use the type var |
Member
|
Also note that |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A minimal PR adding a type annotation to
FILTERSas discussed in #2120The change was tested in my venv and fixed my project's issues.
You should be aware that it causes the following Pylance warning in the jinja codebase:
Looking into this a little more, my understanding is that
TypeVars should really only be used for genericfunctionandclassdeclarations. microsoft/pyright#9826 (reply in thread)A type alias may be more appropriate in line 44.
jinja/src/jinja2/filters.py
Line 44 in 5ef7011
Additionally, I was unable to find any use of
Ffrom line 44 and ranpytestwith the line commented out. I am fairly certain that it was dead code until now.#2135
#2139
The above PRs tried to address #2120 in a different way.
fixes #2120
I don't think I can test this without adding a Pylance action, which would fail anyways since jinja is not written with type checkers in mind.
We could be more explicit about the requirements in Custom Filters but this doesn't really change anything about them. Python type annotations usually serve as documentation only.
Other considerations
Aside from annotating
FILTERS, this same annotation could be applied tojinja/src/jinja2/environment.py
Line 352 in 5ef7011
During my search for use of line 44, I noticed that the same definition of
Fis declared five times. There may be a semantic difference between the otherwise identical declarations.