Skip to content
Myr

improve annotations for methods returning copies

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

authored by Victor Westerhuis · committed by David Lord · parent 53c7591 · Browse files · 6 files+11 added−7 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+11 added−7 removed

  • other:+11 added−7 removed

6 files+11 added−7 removed

modified:src/jinja2/compiler.py+2 added-2 removed
214 unmodified lines
215 # expression as it determines which errors should be raised during runtime216 # or compile time.217 self.soft_frame = False218219 def copy(self) -> "Frame":219 def copy(self) -> "te.Self":220 """Create a copy of the current one."""221 rv = object.__new__(self.__class__)222 rv.__dict__.update(self.__dict__)223 rv.symbols = self.symbols.copy()
4 unmodified lines
228 if isolated:229 return Frame(self.eval_ctx, level=self.symbols.level + 1)230 return Frame(self.eval_ctx, self)231232 def soft(self) -> "Frame":232 def soft(self) -> "te.Self":233 """Return a soft frame. A soft frame may not be modified as234 standalone thing as it shares the resources with the frame it235 was created of, but it's not a rootlevel frame any longer.236
1745 unmodified lines
modified:src/jinja2/environment.py+2 added-2 removed
121 unmodified lines
122123 return result124125126def _environment_config_check(environment: "Environment") -> "Environment":126def _environment_config_check(environment: _env_bound) -> _env_bound:127 """Perform a sanity check on the environment."""128 assert issubclass(129 environment.undefined, Undefined130 ), "'undefined' must be a subclass of 'jinja2.Undefined'."
275 unmodified lines
406 cache_size: int = missing,407 auto_reload: bool = missing,408 bytecode_cache: t.Optional["BytecodeCache"] = missing,409 enable_async: bool = missing,410 ) -> "Environment":410 ) -> "te.Self":411 """Create a new overlay environment that shares all the data with the412 current environment except for cache and the overridden attributes.413 Extensions cannot be removed for an overlayed environment. An overlayed414 environment automatically gets all the extensions of the environment it
1258 unmodified lines
modified:src/jinja2/ext.py+1 added-1 removed
87 unmodified lines
8889 def __init__(self, environment: Environment) -> None:90 self.environment = environment9192 def bind(self, environment: Environment) -> "Extension":92 def bind(self, environment: Environment) -> "te.Self":93 """Create a copy of this extension bound to another environment."""94 rv = object.__new__(self.__class__)95 rv.__dict__.update(self.__dict__)96 rv.environment = environment
774 unmodified lines
modified:src/jinja2/idtracking.py+4 added-1 removed
1 unmodified line
23from . import nodes4from .visitor import NodeVisitor56if t.TYPE_CHECKING:7 import typing_extensions as te89VAR_LOAD_PARAMETER = "param"10VAR_LOAD_RESOLVE = "resolve"11VAR_LOAD_ALIAS = "alias"12VAR_LOAD_UNDEFINED = "undefined"
72 unmodified lines
85 f" unknown to the frame ({name!r})"86 )87 return rv8886 def copy(self) -> "Symbols":89 def copy(self) -> "te.Self":90 rv = object.__new__(self.__class__)91 rv.__dict__.update(self.__dict__)92 rv.refs = self.refs.copy()93 rv.loads = self.loads.copy()
228 unmodified lines
modified:src/jinja2/utils.py+1 added-1 removed
460 unmodified lines
461462 def __getnewargs__(self) -> t.Tuple[t.Any, ...]:463 return (self.capacity,)464465 def copy(self) -> "LRUCache":465 def copy(self) -> "te.Self":466 """Return a shallow copy of the instance."""467 rv = self.__class__(self.capacity)468 rv._mapping.update(self._mapping)469 rv._queue.extend(self._queue)
295 unmodified lines
modified:CHANGES.rst+1 added
37 unmodified lines
38- The error message from ``FileSystemLoader`` includes the paths that were39 searched. :issue:`1661`40- ``PackageLoader`` shows a clearer error message when the package does not41 contain the templates directory. :issue:`1705`42- Improve annotations for methods returning copies. :pr:`1880`434445Version 3.1.446-------------
994 unmodified lines