]> git.ipfire.org Git - thirdparty/starlette.git/commitdiff
add note on type ignore in templating.py (#1556)
authorAdrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>
Mon, 28 Mar 2022 04:33:49 +0000 (23:33 -0500)
committerGitHub <noreply@github.com>
Mon, 28 Mar 2022 04:33:49 +0000 (06:33 +0200)
* add note on type ignore

* Update templating.py

* Update templating.py

* Update templating.py

starlette/templating.py

index cfc4a766e10d21f949ac05076b4e145b6c66c61d..27939c95e00ee5895e82246ecf4cdd4771c2e7a5 100644 (file)
@@ -8,7 +8,10 @@ from starlette.types import Receive, Scope, Send
 try:
     import jinja2
 
-    # @contextfunction renamed to @pass_context in Jinja 3.0, to be removed in 3.1
+    # @contextfunction was renamed to @pass_context in Jinja 3.0, and was removed in 3.1
+    # hence we try to get pass_context (most installs will be >=3.1)
+    # and fall back to contextfunction,
+    # adding a type ignore for mypy to let us access an attribute that may not exist
     if hasattr(jinja2, "pass_context"):
         pass_context = jinja2.pass_context
     else:  # pragma: nocover