From 70ea1d3e224638aa7db10e7814105a590c09cdff Mon Sep 17 00:00:00 2001 From: Adriano Scoditti Date: Tue, 19 Nov 2019 15:26:39 +0100 Subject: [PATCH] use 'callable' instead of typechecking to inject context --- CHANGES.rst | 2 ++ jinja2/nodes.py | 4 ---- jinja2/runtime.py | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 07528541..31aa4804 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -75,6 +75,8 @@ Unreleased lines. :issue:`175` - Add ``break_on_hyphens`` parameter to ``|wordwrap`` filter. :issue:`550` +- Use :func:`callable` to inject context at runtime for compatibility + with Cython compiled functions. :pr:`1108` Version 2.10.3 diff --git a/jinja2/nodes.py b/jinja2/nodes.py index 9a58d436..058e3e6b 100644 --- a/jinja2/nodes.py +++ b/jinja2/nodes.py @@ -20,10 +20,6 @@ from jinja2.utils import Markup from jinja2._compat import izip, with_metaclass, text_type, PY2 -#: the types we support for context functions -_context_function_types = (types.FunctionType, types.MethodType) - - _binop_to_func = { '*': operator.mul, '/': operator.truediv, diff --git a/jinja2/runtime.py b/jinja2/runtime.py index 135ff27b..e3aa1f84 100644 --- a/jinja2/runtime.py +++ b/jinja2/runtime.py @@ -13,7 +13,7 @@ import sys from itertools import chain from types import MethodType -from jinja2.nodes import EvalContext, _context_function_types +from jinja2.nodes import EvalContext from jinja2.utils import Markup, soft_unicode, escape, missing, concat, \ internalcode, object_type_repr, evalcontextfunction, Namespace from jinja2.exceptions import UndefinedError, TemplateRuntimeError, \ @@ -251,7 +251,7 @@ class Context(with_metaclass(ContextMeta)): __obj = fn break - if isinstance(__obj, _context_function_types): + if callable(__obj): if getattr(__obj, 'contextfunction', 0): args = (__self,) + args elif getattr(__obj, 'evalcontextfunction', 0): -- 2.47.2