Skip to content
Myr

move closure out of loop for bugbear B023

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 · parent 033bfd1 · Browse files · 1 file+17 added−17 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+17 added−17 removed

  • other:+17 added−17 removed

1 file+17 added−17 removed

modified:src/jinja2/loaders.py+17 added-17 removed
13 unmodified lines
14from types import ModuleType1516from .exceptions import TemplateNotFound17from .utils import internalcode18from .utils import open_if_exists1819if t.TYPE_CHECKING:20 from .environment import Environment21 from .environment import Template
169 unmodified lines
191 def get_source(192 self, environment: "Environment", template: str193 ) -> t.Tuple[str, str, t.Callable[[], bool]]:194 pieces = split_template_path(template)195196 for searchpath in self.searchpath:197 # Use posixpath even on Windows to avoid "drive:" or UNC198 # segments breaking out of the search directory.199 filename = posixpath.join(searchpath, *pieces)200 f = open_if_exists(filename)201 if f is None:202 continue203 try:204 contents = f.read().decode(self.encoding)205 finally:206 f.close()200208 mtime = os.path.getmtime(filename)201 if os.path.isfile(filename):202 break203 else:204 raise TemplateNotFound(template)205210 def uptodate() -> bool:211 try:212 return os.path.getmtime(filename) == mtime213 except OSError:214 return False206 with open(filename, encoding=self.encoding) as f:207 contents = f.read()208216 # Use normpath to convert Windows altsep to sep.217 return contents, os.path.normpath(filename), uptodate218 raise TemplateNotFound(template)209 mtime = os.path.getmtime(filename)210211 def uptodate() -> bool:212 try:213 return os.path.getmtime(filename) == mtime214 except OSError:215 return False216217 # Use normpath to convert Windows altsep to sep.218 return contents, os.path.normpath(filename), uptodate219220 def list_templates(self) -> t.List[str]:221 found = set()222 for searchpath in self.searchpath:223 walk_dir = os.walk(searchpath, followlinks=self.followlinks)
438 unmodified lines