-
-
Notifications
You must be signed in to change notification settings - Fork 856
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
Add env argument to Jinja2Templates, remove **env_options. (ref #2134) #2159
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
93d98ad
Add env argument to Jinja2Templates, remove **env_options.
alex-oleshkevich 89c5d28
simplify changes
alex-oleshkevich f764843
uniform formatting in tests
alex-oleshkevich 39ee96e
get back env_options
alex-oleshkevich 7c9f4fc
warn about env_options usage
alex-oleshkevich 5969aec
Add env argument to Jinja2Templates, remove **env_options.
alex-oleshkevich a3e8975
simplify changes
alex-oleshkevich 8907911
uniform formatting in tests
alex-oleshkevich f603512
get back env_options
alex-oleshkevich aeb1726
warn about env_options usage
alex-oleshkevich 15c70ed
Do not cast directory
Kludex abdd56d
Fix linter
Kludex d305e67
Use string type hint for jinja2 uninstalled environments
Kludex c8c2822
Merge branch 'master' into jinja-env
alex-oleshkevich 9e00299
Merge branch 'jinja-env' of github.com:alex-oleshkevich/starlette int…
alex-oleshkevich 06b6ba7
add overloads
alex-oleshkevich a2d06bc
add a link to jinja2.Environment API
alex-oleshkevich File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import typing | ||
import warnings | ||
from os import PathLike | ||
|
||
from starlette.background import BackgroundTask | ||
|
@@ -62,19 +63,57 @@ class Jinja2Templates: | |
return templates.TemplateResponse("index.html", {"request": request}) | ||
""" | ||
|
||
@typing.overload | ||
def __init__( | ||
self, | ||
directory: typing.Union[ | ||
str, PathLike, typing.Sequence[typing.Union[str, PathLike]] | ||
str, | ||
PathLike, | ||
typing.Sequence[typing.Union[str, PathLike]], | ||
], | ||
*, | ||
context_processors: typing.Optional[ | ||
typing.List[typing.Callable[[Request], typing.Dict[str, typing.Any]]] | ||
] = None, | ||
**env_options: typing.Any, | ||
) -> None: | ||
... | ||
|
||
@typing.overload | ||
def __init__( | ||
self, | ||
*, | ||
env: "jinja2.Environment", | ||
context_processors: typing.Optional[ | ||
typing.List[typing.Callable[[Request], typing.Dict[str, typing.Any]]] | ||
] = None, | ||
) -> None: | ||
... | ||
|
||
def __init__( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we overload this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good idea |
||
self, | ||
directory: typing.Union[ | ||
str, PathLike, typing.Sequence[typing.Union[str, PathLike]], None | ||
] = None, | ||
*, | ||
context_processors: typing.Optional[ | ||
typing.List[typing.Callable[[Request], typing.Dict[str, typing.Any]]] | ||
] = None, | ||
env: typing.Optional["jinja2.Environment"] = None, | ||
**env_options: typing.Any, | ||
) -> None: | ||
if env_options: | ||
warnings.warn( | ||
"Extra environment options are deprecated. Use a preconfigured jinja2.Environment instead.", # noqa: E501 | ||
DeprecationWarning, | ||
) | ||
assert jinja2 is not None, "jinja2 must be installed to use Jinja2Templates" | ||
self.env = self._create_env(directory, **env_options) | ||
assert directory or env, "either 'directory' or 'env' arguments must be passed" | ||
self.context_processors = context_processors or [] | ||
if directory is not None: | ||
self.env = self._create_env(directory, **env_options) | ||
elif env is not None: | ||
self.env = env | ||
|
||
def _create_env( | ||
self, | ||
|
This file contains 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
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.
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 think this doesn't render very well on mkdocs
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.
it looks good
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.
Ah ok. Great 👍