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
Provenance
- Commit
ded9915- Tree
5f4a80d- Author
Victor Westerhuis <victor@westerhu.is>- Committer
David Lord <davidism@gmail.com>- Parent
53c7591
6 files changed+11 added−7 removed
modified:src/jinja2/compiler.py+2 added-2 removed
214 unmodified lines215 # expression as it determines which errors should be raised during runtime216 # or compile time.217 self.soft_frame = False218 219- 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 lines228 if isolated:229 return Frame(self.eval_ctx, level=self.symbols.level + 1)230 return Frame(self.eval_ctx, self)231 232- 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 linesmodified:src/jinja2/environment.py+2 added-2 removed
121 unmodified lines122 123 return result124 125 126-def _environment_config_check(environment: "Environment") -> "Environment":126+def _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 lines406 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 it1258 unmodified linesmodified:src/jinja2/ext.py+1 added-1 removed
87 unmodified lines88 89 def __init__(self, environment: Environment) -> None:90 self.environment = environment91 92- 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 = environment774 unmodified linesmodified:src/jinja2/idtracking.py+4 added-1 removed
1 unmodified line2 3 from . import nodes4 from .visitor import NodeVisitor5 6+if t.TYPE_CHECKING:7+ import typing_extensions as te8+9 VAR_LOAD_PARAMETER = "param"10 VAR_LOAD_RESOLVE = "resolve"11 VAR_LOAD_ALIAS = "alias"12 VAR_LOAD_UNDEFINED = "undefined"72 unmodified lines85 f" unknown to the frame ({name!r})"86 )87 return rv88 86- 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 linesmodified:src/jinja2/utils.py+1 added-1 removed
460 unmodified lines461 462 def __getnewargs__(self) -> t.Tuple[t.Any, ...]:463 return (self.capacity,)464 465- 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 linesmodified:CHANGES.rst+1 added
37 unmodified lines38 - 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`43 44 45 Version 3.1.446 -------------994 unmodified lines