Merge branch '3.1.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 a0dd775, 8efee35 · Browse files · 6 files·+56 added−13 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+56 added−13 removed
- other:+56 added−13 removed
Provenance
- Commit
52843b5- Tree
4be5fc0- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent 1
a0dd775- Parent 2
8efee35
6 files changed+56 added−13 removed
modified:requirements/dev.txt+1 added-1 removed
18 unmodified lines19 filelock==3.6.020 # via21 # tox22 # virtualenv23-identify==2.4.1223+identify==2.5.024 # via pre-commit25 nodeenv==1.6.026 # via pre-commit27 pep517==0.12.033 unmodified linesmodified:requirements/typing.txt+1 added-1 removed
3 unmodified lines4 # To update, run:5 #6 # pip-compile-multi7 #8-mypy==0.9428+mypy==0.9509 # via -r requirements/typing.in10 mypy-extensions==0.4.311 # via mypy12 tomli==2.0.13 unmodified linesmodified:src/jinja2/bccache.py+48 added-6 removed
77 unmodified lines78 except (EOFError, ValueError, TypeError):79 self.reset()80 return81 82- def write_bytecode(self, f: t.BinaryIO) -> None:82+ def write_bytecode(self, f: t.IO[bytes]) -> None:83 """Dump the bytecode into the file or file like object passed."""84 if self.code is None:85 raise TypeError("can't write empty bucket")86 f.write(bc_magic)174 unmodified lines261 262 def load_bytecode(self, bucket: Bucket) -> None:263 filename = self._get_cache_filename(bucket)264 265- if os.path.exists(filename):266- with open(filename, "rb") as f:267- bucket.load_bytecode(f)265+ # Don't test for existence before opening the file, since the266+ # file could disappear after the test before the open.267+ try:268+ f = open(filename, "rb")269+ except (FileNotFoundError, IsADirectoryError, PermissionError):270+ # PermissionError can occur on Windows when an operation is271+ # in progress, such as calling clear().272+ return273 274+ with f:275+ bucket.load_bytecode(f)276+277 def dump_bytecode(self, bucket: Bucket) -> None:270- with open(self._get_cache_filename(bucket), "wb") as f:271- bucket.write_bytecode(f)278+ # Write to a temporary file, then rename to the real name after279+ # writing. This avoids another process reading the file before280+ # it is fully written.281+ name = self._get_cache_filename(bucket)282+ f = tempfile.NamedTemporaryFile(283+ mode="wb",284+ dir=os.path.dirname(name),285+ prefix=os.path.basename(name),286+ suffix=".tmp",287+ delete=False,288+ )289 290+ def remove_silent() -> None:291+ try:292+ os.remove(f.name)293+ except OSError:294+ # Another process may have called clear(). On Windows,295+ # another program may be holding the file open.296+ pass297+298+ try:299+ with f:300+ bucket.write_bytecode(f)301+ except BaseException:302+ remove_silent()303+ raise304+305+ try:306+ os.replace(f.name, name)307+ except OSError:308+ # Another process may have called clear(). On Windows,309+ # another program may be holding the file open.310+ remove_silent()311+ except BaseException:312+ remove_silent()313+ raise314+315 def clear(self) -> None:316 # imported lazily here because google app-engine doesn't support317 # write access on the file system and the function does not exist318 # normally.88 unmodified linesmodified:src/jinja2/filters.py+3 added-3 removed
1284 unmodified lines1285 1286 Total: {{ items|sum(attribute='price') }}1287 1288 .. versionchanged:: 2.61289- The `attribute` parameter was added to allow suming up over1290- attributes. Also the `start` parameter was moved on to the right.1289+ The ``attribute`` parameter was added to allow summing up over1290+ attributes. Also the ``start`` parameter was moved on to the right.1291 """1292 if attribute is not None:1293 iterable = map(make_attrgetter(environment, attribute), iterable)1294 1295- return sum(iterable, start)1295+ return sum(iterable, start) # type: ignore[no-any-return, call-overload]1296 1297 1298 @async_variant(sync_do_sum) # type: ignore1299 async def do_sum(541 unmodified linesmodified:.pre-commit-config.yaml+2 added-2 removed
12234567891011111213141519 unmodified linesci: autoupdate_branch: "3.0.x" autoupdate_branch: "3.1.x" autoupdate_schedule: monthlyrepos: - repo: https://github.com/asottile/pyupgrade rev: v2.32.0 hooks: - id: pyupgrade args: ["--py37-plus"] - repo: https://github.com/asottile/reorder_python_imports rev: v3.0.1 rev: v3.1.0 hooks: - id: reorder-python-imports args: ["--application-directories", "src"] additional_dependencies: ["setuptools>60.9"]19 unmodified linesmodified:CHANGES.rst+1 added
11 unmodified lines12 Unreleased13 14 - Add parameters to ``Environment.overlay`` to match ``__init__``.15 :issue:`1645`16+- Handle race condition in ``FileSystemBytecodeCache``. :issue:`1654`17 18 19 Version 3.1.120 -------------961 unmodified lines