Merge branch '2.11.x'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parents b3a9df3, 07b5c01 · Browse files · 6 files·+41 added−15 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+41 added−15 removed
- tests:+15 added−0 removed
- other:+26 added−15 removed
Provenance
- Commit
c074fd5- Tree
ba581aa- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent 1
b3a9df3- Parent 2
07b5c01
6 files changed+41 added−15 removed
modified:docs/api.rst+4 added-3 removed
3 unmodified lines4 .. module:: jinja25 :noindex:6 :synopsis: public Jinja API7 8-This document describes the API to Jinja and not the template language. It9-will be most useful as reference to those implementing the template interface10-to the application and not those who are creating Jinja templates.8+This document describes the API to Jinja and not the template language9+(for that, see :doc:`/templates`). It will be most useful as reference10+to those implementing the template interface to the application and not11+those who are creating Jinja templates.12 13 Basics14 ------15 856 unmodified linesmodified:src/jinja2/debug.py+1 added-4 removed
236 unmodified lines237 238 class _CTraceback(ctypes.Structure):239 _fields_ = [240 # Extra PyObject slots when compiled with Py_TRACE_REFS.241- (242- "PyObject_HEAD",243- ctypes.c_byte * (32 if hasattr(sys, "getobjects") else 16),244- ),241+ ("PyObject_HEAD", ctypes.c_byte * object().__sizeof__()),242 # Only care about tb_next as an object, not a traceback.243 ("tb_next", ctypes.py_object),244 ]245 16 unmodified linesmodified:src/jinja2/loaders.py+2 added-2 removed
230 unmodified lines231 template directory is assumed to only be in one namespace232 contributor. Zip files contributing to a namespace are not233 supported.234 235- .. versionchanged:: 2.11.0235+ .. versionchanged:: 3.0236 No longer uses ``setuptools`` as a dependency.237 238- .. versionchanged:: 2.11.0238+ .. versionchanged:: 3.0239 Limited PEP 420 namespace package support.240 """241 242 def __init__(self, package_name, package_path="templates", encoding="utf-8"):320 unmodified linesmodified:src/jinja2/utils.py+7 added-6 removed
156 unmodified lines157 if obj is None:158 return "None"159 elif obj is Ellipsis:160 return "Ellipsis"161- # __builtin__ in 2.x, builtins in 3.x162- if obj.__class__.__module__ in ("__builtin__", "builtins"):163- name = obj.__class__.__name__164- else:165- name = f"{obj.__class__.__module__}.{obj.__class__.__name__}"166- return f"{name} object"161 162+ cls = type(obj)163 164+ if cls.__module__ == "builtins":165+ return f"{cls.__name__} object"166+167+ return f"{cls.__module__}.{cls.__name__} object"168+169+170 def pformat(obj):171 """Format an object using :func:`pprint.pformat`.172 """173 from pprint import pformat492 unmodified linesmodified:tests/test_api.py+15 added
265 unmodified lines266 def test_undefined_and_special_attributes(self):267 with pytest.raises(AttributeError):268 Undefined("Foo").__dict__269 270+ def test_undefined_attribute_error(self):271+ # Django's LazyObject turns the __class__ attribute into a272+ # property that resolves the wrapped function. If that wrapped273+ # function raises an AttributeError, printing the repr of the274+ # object in the undefined message would cause a RecursionError.275+ class Error:276+ @property277+ def __class__(self):278+ raise AttributeError()279+280+ u = Undefined(obj=Error(), name="hello")281+282+ with pytest.raises(UndefinedError):283+ getattr(u, "recursion", None)284+285 def test_logging_undefined(self):286 _messages = []287 288 class DebugLogger:145 unmodified linesmodified:CHANGES.rst+12 added
19 unmodified lines20 :class:`~unittest.mock.Mock` to be treated as a21 :func:`contextfunction`. :issue:`1145`22 - Update ``wordcount`` filter to trigger :class:`Undefined` methods23 by wrapping the input in :func:`soft_str`. :pr:`1160`24+- Fix a hang when displaying tracebacks on Python 32-bit.25+ :issue:`1162`26+- Showing an undefined error for an object that raises27+ ``AttributeError`` on access doesn't cause a recursion error.28+ :issue:`1177`29+- Revert changes to :class:`~loaders.PackageLoader` from 2.10 which30+ removed the dependency on setuptools and pkg_resources, and added31+ limited support for namespace packages. The changes caused issues32+ when using Pytest. Due to the difficulty in supporting Python 2 and33+ :pep:`451` simultaneously, the changes are reverted until 3.0.34+ :pr:`1182`35 36+37 Version 2.11.138 --------------39 40 Released 2020-01-30735 unmodified lines