nwo
stringlengths
10
28
sha
stringlengths
40
40
path
stringlengths
11
97
identifier
stringlengths
1
64
parameters
stringlengths
2
2.24k
return_statement
stringlengths
0
2.17k
docstring
stringlengths
0
5.45k
docstring_summary
stringlengths
0
3.83k
func_begin
int64
1
13.4k
func_end
int64
2
13.4k
function
stringlengths
28
56.4k
url
stringlengths
106
209
project
int64
1
48
executed_lines
list
executed_lines_pc
float64
0
153
missing_lines
list
missing_lines_pc
float64
0
100
covered
bool
2 classes
filecoverage
float64
2.53
100
function_lines
int64
2
1.46k
mccabe
int64
1
253
coverage
float64
0
100
docstring_lines
int64
0
112
function_nodoc
stringlengths
9
56.4k
id
int64
0
29.8k
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_ExprStmt
(self, node: nodes.ExprStmt, frame: Frame)
1,358
1,360
def visit_ExprStmt(self, node: nodes.ExprStmt, frame: Frame) -> None: self.newline(node) self.visit(node.node, frame)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1358-L1360
42
[ 0, 1, 2 ]
100
[]
0
true
92.742927
3
1
100
0
def visit_ExprStmt(self, node: nodes.ExprStmt, frame: Frame) -> None: self.newline(node) self.visit(node.node, frame)
27,961
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator._default_finalize
(value: t.Any)
return str(value)
The default finalize function if the environment isn't configured with one. Or, if the environment has one, this is called on that function's output for constants.
The default finalize function if the environment isn't configured with one. Or, if the environment has one, this is called on that function's output for constants.
1,367
1,372
def _default_finalize(value: t.Any) -> t.Any: """The default finalize function if the environment isn't configured with one. Or, if the environment has one, this is called on that function's output for constants. """ return str(value)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1367-L1372
42
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
92.742927
6
1
100
3
def _default_finalize(value: t.Any) -> t.Any: return str(value)
27,962
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator._make_finalize
(self)
return self._finalize
Build the finalize function to be used on constants and at runtime. Cached so it's only created once for all output nodes. Returns a ``namedtuple`` with the following attributes: ``const`` A function to finalize constant data at compile time. ``src`` Source code to output around nodes to be evaluated at runtime.
Build the finalize function to be used on constants and at runtime. Cached so it's only created once for all output nodes.
1,376
1,422
def _make_finalize(self) -> _FinalizeInfo: """Build the finalize function to be used on constants and at runtime. Cached so it's only created once for all output nodes. Returns a ``namedtuple`` with the following attributes: ``const`` A function to finalize constant data at compile time. ``src`` Source code to output around nodes to be evaluated at runtime. """ if self._finalize is not None: return self._finalize finalize: t.Optional[t.Callable[..., t.Any]] finalize = default = self._default_finalize src = None if self.environment.finalize: src = "environment.finalize(" env_finalize = self.environment.finalize pass_arg = { _PassArg.context: "context", _PassArg.eval_context: "context.eval_ctx", _PassArg.environment: "environment", }.get( _PassArg.from_obj(env_finalize) # type: ignore ) finalize = None if pass_arg is None: def finalize(value: t.Any) -> t.Any: return default(env_finalize(value)) else: src = f"{src}{pass_arg}, " if pass_arg == "environment": def finalize(value: t.Any) -> t.Any: return default(env_finalize(self.environment, value)) self._finalize = self._FinalizeInfo(finalize, src) return self._finalize
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1376-L1422
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 44, 45, 46 ]
97.87234
[ 43 ]
2.12766
false
92.742927
47
7
97.87234
11
def _make_finalize(self) -> _FinalizeInfo: if self._finalize is not None: return self._finalize finalize: t.Optional[t.Callable[..., t.Any]] finalize = default = self._default_finalize src = None if self.environment.finalize: src = "environment.finalize(" env_finalize = self.environment.finalize pass_arg = { _PassArg.context: "context", _PassArg.eval_context: "context.eval_ctx", _PassArg.environment: "environment", }.get( _PassArg.from_obj(env_finalize) # type: ignore ) finalize = None if pass_arg is None: def finalize(value: t.Any) -> t.Any: return default(env_finalize(value)) else: src = f"{src}{pass_arg}, " if pass_arg == "environment": def finalize(value: t.Any) -> t.Any: return default(env_finalize(self.environment, value)) self._finalize = self._FinalizeInfo(finalize, src) return self._finalize
27,963
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator._output_const_repr
(self, group: t.Iterable[t.Any])
return repr(concat(group))
Given a group of constant values converted from ``Output`` child nodes, produce a string to write to the template module source.
Given a group of constant values converted from ``Output`` child nodes, produce a string to write to the template module source.
1,424
1,429
def _output_const_repr(self, group: t.Iterable[t.Any]) -> str: """Given a group of constant values converted from ``Output`` child nodes, produce a string to write to the template module source. """ return repr(concat(group))
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1424-L1429
42
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
92.742927
6
1
100
3
def _output_const_repr(self, group: t.Iterable[t.Any]) -> str: return repr(concat(group))
27,964
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator._output_child_to_const
( self, node: nodes.Expr, frame: Frame, finalize: _FinalizeInfo )
return finalize.const(const)
Try to optimize a child of an ``Output`` node by trying to convert it to constant, finalized data at compile time. If :exc:`Impossible` is raised, the node is not constant and will be evaluated at runtime. Any other exception will also be evaluated at runtime for easier debugging.
Try to optimize a child of an ``Output`` node by trying to convert it to constant, finalized data at compile time.
1,431
1,450
def _output_child_to_const( self, node: nodes.Expr, frame: Frame, finalize: _FinalizeInfo ) -> str: """Try to optimize a child of an ``Output`` node by trying to convert it to constant, finalized data at compile time. If :exc:`Impossible` is raised, the node is not constant and will be evaluated at runtime. Any other exception will also be evaluated at runtime for easier debugging. """ const = node.as_const(frame.eval_ctx) if frame.eval_ctx.autoescape: const = escape(const) # Template data doesn't go through finalize. if isinstance(node, nodes.TemplateData): return str(const) return finalize.const(const)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1431-L1450
42
[ 0, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ]
60
[]
0
false
92.742927
20
3
100
6
def _output_child_to_const( self, node: nodes.Expr, frame: Frame, finalize: _FinalizeInfo ) -> str: const = node.as_const(frame.eval_ctx) if frame.eval_ctx.autoescape: const = escape(const) # Template data doesn't go through finalize. if isinstance(node, nodes.TemplateData): return str(const) return finalize.const(const)
27,965
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator._output_child_pre
( self, node: nodes.Expr, frame: Frame, finalize: _FinalizeInfo )
Output extra source code before visiting a child of an ``Output`` node.
Output extra source code before visiting a child of an ``Output`` node.
1,452
1,466
def _output_child_pre( self, node: nodes.Expr, frame: Frame, finalize: _FinalizeInfo ) -> None: """Output extra source code before visiting a child of an ``Output`` node. """ if frame.eval_ctx.volatile: self.write("(escape if context.eval_ctx.autoescape else str)(") elif frame.eval_ctx.autoescape: self.write("escape(") else: self.write("str(") if finalize.src is not None: self.write(finalize.src)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1452-L1466
42
[ 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ]
73.333333
[]
0
false
92.742927
15
4
100
2
def _output_child_pre( self, node: nodes.Expr, frame: Frame, finalize: _FinalizeInfo ) -> None: if frame.eval_ctx.volatile: self.write("(escape if context.eval_ctx.autoescape else str)(") elif frame.eval_ctx.autoescape: self.write("escape(") else: self.write("str(") if finalize.src is not None: self.write(finalize.src)
27,966
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator._output_child_post
( self, node: nodes.Expr, frame: Frame, finalize: _FinalizeInfo )
Output extra source code after visiting a child of an ``Output`` node.
Output extra source code after visiting a child of an ``Output`` node.
1,468
1,477
def _output_child_post( self, node: nodes.Expr, frame: Frame, finalize: _FinalizeInfo ) -> None: """Output extra source code after visiting a child of an ``Output`` node. """ self.write(")") if finalize.src is not None: self.write(")")
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1468-L1477
42
[ 0, 5, 6, 7, 8, 9 ]
60
[]
0
false
92.742927
10
2
100
2
def _output_child_post( self, node: nodes.Expr, frame: Frame, finalize: _FinalizeInfo ) -> None: self.write(")") if finalize.src is not None: self.write(")")
27,967
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_Output
(self, node: nodes.Output, frame: Frame)
1,479
1,556
def visit_Output(self, node: nodes.Output, frame: Frame) -> None: # If an extends is active, don't render outside a block. if frame.require_output_check: # A top-level extends is known to exist at compile time. if self.has_known_extends: return self.writeline("if parent_template is None:") self.indent() finalize = self._make_finalize() body: t.List[t.Union[t.List[t.Any], nodes.Expr]] = [] # Evaluate constants at compile time if possible. Each item in # body will be either a list of static data or a node to be # evaluated at runtime. for child in node.nodes: try: if not ( # If the finalize function requires runtime context, # constants can't be evaluated at compile time. finalize.const # Unless it's basic template data that won't be # finalized anyway. or isinstance(child, nodes.TemplateData) ): raise nodes.Impossible() const = self._output_child_to_const(child, frame, finalize) except (nodes.Impossible, Exception): # The node was not constant and needs to be evaluated at # runtime. Or another error was raised, which is easier # to debug at runtime. body.append(child) continue if body and isinstance(body[-1], list): body[-1].append(const) else: body.append([const]) if frame.buffer is not None: if len(body) == 1: self.writeline(f"{frame.buffer}.append(") else: self.writeline(f"{frame.buffer}.extend((") self.indent() for item in body: if isinstance(item, list): # A group of constant data to join and output. val = self._output_const_repr(item) if frame.buffer is None: self.writeline("yield " + val) else: self.writeline(val + ",") else: if frame.buffer is None: self.writeline("yield ", item) else: self.newline(item) # A node to be evaluated at runtime. self._output_child_pre(item, frame, finalize) self.visit(item, frame) self._output_child_post(item, frame, finalize) if frame.buffer is not None: self.write(",") if frame.buffer is not None: self.outdent() self.writeline(")" if len(body) == 1 else "))") if frame.require_output_check: self.outdent()
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1479-L1556
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 39, 40, 41, 42, 43, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 57, 59, 60, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77 ]
87.179487
[]
0
false
92.742927
78
18
100
0
def visit_Output(self, node: nodes.Output, frame: Frame) -> None: # If an extends is active, don't render outside a block. if frame.require_output_check: # A top-level extends is known to exist at compile time. if self.has_known_extends: return self.writeline("if parent_template is None:") self.indent() finalize = self._make_finalize() body: t.List[t.Union[t.List[t.Any], nodes.Expr]] = [] # Evaluate constants at compile time if possible. Each item in # body will be either a list of static data or a node to be # evaluated at runtime. for child in node.nodes: try: if not ( # If the finalize function requires runtime context, # constants can't be evaluated at compile time. finalize.const # Unless it's basic template data that won't be # finalized anyway. or isinstance(child, nodes.TemplateData) ): raise nodes.Impossible() const = self._output_child_to_const(child, frame, finalize) except (nodes.Impossible, Exception): # The node was not constant and needs to be evaluated at # runtime. Or another error was raised, which is easier # to debug at runtime. body.append(child) continue if body and isinstance(body[-1], list): body[-1].append(const) else: body.append([const]) if frame.buffer is not None: if len(body) == 1: self.writeline(f"{frame.buffer}.append(") else: self.writeline(f"{frame.buffer}.extend((") self.indent() for item in body: if isinstance(item, list): # A group of constant data to join and output. val = self._output_const_repr(item) if frame.buffer is None: self.writeline("yield " + val) else: self.writeline(val + ",") else: if frame.buffer is None: self.writeline("yield ", item) else: self.newline(item) # A node to be evaluated at runtime. self._output_child_pre(item, frame, finalize) self.visit(item, frame) self._output_child_post(item, frame, finalize) if frame.buffer is not None: self.write(",") if frame.buffer is not None: self.outdent() self.writeline(")" if len(body) == 1 else "))") if frame.require_output_check: self.outdent()
27,968
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_Assign
(self, node: nodes.Assign, frame: Frame)
1,558
1,564
def visit_Assign(self, node: nodes.Assign, frame: Frame) -> None: self.push_assign_tracking() self.newline(node) self.visit(node.target, frame) self.write(" = ") self.visit(node.node, frame) self.pop_assign_tracking(frame)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1558-L1564
42
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
92.742927
7
1
100
0
def visit_Assign(self, node: nodes.Assign, frame: Frame) -> None: self.push_assign_tracking() self.newline(node) self.visit(node.target, frame) self.write(" = ") self.visit(node.node, frame) self.pop_assign_tracking(frame)
27,969
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_AssignBlock
(self, node: nodes.AssignBlock, frame: Frame)
1,566
1,586
def visit_AssignBlock(self, node: nodes.AssignBlock, frame: Frame) -> None: self.push_assign_tracking() block_frame = frame.inner() # This is a special case. Since a set block always captures we # will disable output checks. This way one can use set blocks # toplevel even in extended templates. block_frame.require_output_check = False block_frame.symbols.analyze_node(node) self.enter_frame(block_frame) self.buffer(block_frame) self.blockvisit(node.body, block_frame) self.newline(node) self.visit(node.target, frame) self.write(" = (Markup if context.eval_ctx.autoescape else identity)(") if node.filter is not None: self.visit_Filter(node.filter, block_frame) else: self.write(f"concat({block_frame.buffer})") self.write(")") self.pop_assign_tracking(frame) self.leave_frame(block_frame)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1566-L1586
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20 ]
95.238095
[]
0
false
92.742927
21
2
100
0
def visit_AssignBlock(self, node: nodes.AssignBlock, frame: Frame) -> None: self.push_assign_tracking() block_frame = frame.inner() # This is a special case. Since a set block always captures we # will disable output checks. This way one can use set blocks # toplevel even in extended templates. block_frame.require_output_check = False block_frame.symbols.analyze_node(node) self.enter_frame(block_frame) self.buffer(block_frame) self.blockvisit(node.body, block_frame) self.newline(node) self.visit(node.target, frame) self.write(" = (Markup if context.eval_ctx.autoescape else identity)(") if node.filter is not None: self.visit_Filter(node.filter, block_frame) else: self.write(f"concat({block_frame.buffer})") self.write(")") self.pop_assign_tracking(frame) self.leave_frame(block_frame)
27,970
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_Name
(self, node: nodes.Name, frame: Frame)
1,590
1,613
def visit_Name(self, node: nodes.Name, frame: Frame) -> None: if node.ctx == "store" and ( frame.toplevel or frame.loop_frame or frame.block_frame ): if self._assign_stack: self._assign_stack[-1].add(node.name) ref = frame.symbols.ref(node.name) # If we are looking up a variable we might have to deal with the # case where it's undefined. We can skip that case if the load # instruction indicates a parameter which are always defined. if node.ctx == "load": load = frame.symbols.find_load(ref) if not ( load is not None and load[0] == VAR_LOAD_PARAMETER and not self.parameter_is_undeclared(ref) ): self.write( f"(undefined(name={node.name!r}) if {ref} is missing else {ref})" ) return self.write(ref)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1590-L1613
42
[ 0, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 18, 21, 22, 23 ]
66.666667
[]
0
false
92.742927
24
10
100
0
def visit_Name(self, node: nodes.Name, frame: Frame) -> None: if node.ctx == "store" and ( frame.toplevel or frame.loop_frame or frame.block_frame ): if self._assign_stack: self._assign_stack[-1].add(node.name) ref = frame.symbols.ref(node.name) # If we are looking up a variable we might have to deal with the # case where it's undefined. We can skip that case if the load # instruction indicates a parameter which are always defined. if node.ctx == "load": load = frame.symbols.find_load(ref) if not ( load is not None and load[0] == VAR_LOAD_PARAMETER and not self.parameter_is_undeclared(ref) ): self.write( f"(undefined(name={node.name!r}) if {ref} is missing else {ref})" ) return self.write(ref)
27,971
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_NSRef
(self, node: nodes.NSRef, frame: Frame)
1,615
1,627
def visit_NSRef(self, node: nodes.NSRef, frame: Frame) -> None: # NSRefs can only be used to store values; since they use the normal # `foo.bar` notation they will be parsed as a normal attribute access # when used anywhere but in a `set` context ref = frame.symbols.ref(node.name) self.writeline(f"if not isinstance({ref}, Namespace):") self.indent() self.writeline( "raise TemplateRuntimeError" '("cannot assign attribute on non-namespace object")' ) self.outdent() self.writeline(f"{ref}[{node.attr!r}]")
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1615-L1627
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 11, 12 ]
76.923077
[]
0
false
92.742927
13
1
100
0
def visit_NSRef(self, node: nodes.NSRef, frame: Frame) -> None: # NSRefs can only be used to store values; since they use the normal # `foo.bar` notation they will be parsed as a normal attribute access # when used anywhere but in a `set` context ref = frame.symbols.ref(node.name) self.writeline(f"if not isinstance({ref}, Namespace):") self.indent() self.writeline( "raise TemplateRuntimeError" '("cannot assign attribute on non-namespace object")' ) self.outdent() self.writeline(f"{ref}[{node.attr!r}]")
27,972
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_Const
(self, node: nodes.Const, frame: Frame)
1,629
1,634
def visit_Const(self, node: nodes.Const, frame: Frame) -> None: val = node.as_const(frame.eval_ctx) if isinstance(val, float): self.write(str(val)) else: self.write(repr(val))
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1629-L1634
42
[ 0, 1, 2, 3, 5 ]
83.333333
[]
0
false
92.742927
6
2
100
0
def visit_Const(self, node: nodes.Const, frame: Frame) -> None: val = node.as_const(frame.eval_ctx) if isinstance(val, float): self.write(str(val)) else: self.write(repr(val))
27,973
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_TemplateData
(self, node: nodes.TemplateData, frame: Frame)
1,636
1,642
def visit_TemplateData(self, node: nodes.TemplateData, frame: Frame) -> None: try: self.write(repr(node.as_const(frame.eval_ctx))) except nodes.Impossible: self.write( f"(Markup if context.eval_ctx.autoescape else identity)({node.data!r})" )
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1636-L1642
42
[ 0, 1, 2, 3, 4 ]
71.428571
[]
0
false
92.742927
7
2
100
0
def visit_TemplateData(self, node: nodes.TemplateData, frame: Frame) -> None: try: self.write(repr(node.as_const(frame.eval_ctx))) except nodes.Impossible: self.write( f"(Markup if context.eval_ctx.autoescape else identity)({node.data!r})" )
27,974
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_Tuple
(self, node: nodes.Tuple, frame: Frame)
1,644
1,651
def visit_Tuple(self, node: nodes.Tuple, frame: Frame) -> None: self.write("(") idx = -1 for idx, item in enumerate(node.items): if idx: self.write(", ") self.visit(item, frame) self.write(",)" if idx == 0 else ")")
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1644-L1651
42
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
92.742927
8
3
100
0
def visit_Tuple(self, node: nodes.Tuple, frame: Frame) -> None: self.write("(") idx = -1 for idx, item in enumerate(node.items): if idx: self.write(", ") self.visit(item, frame) self.write(",)" if idx == 0 else ")")
27,975
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_List
(self, node: nodes.List, frame: Frame)
1,653
1,659
def visit_List(self, node: nodes.List, frame: Frame) -> None: self.write("[") for idx, item in enumerate(node.items): if idx: self.write(", ") self.visit(item, frame) self.write("]")
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1653-L1659
42
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
92.742927
7
3
100
0
def visit_List(self, node: nodes.List, frame: Frame) -> None: self.write("[") for idx, item in enumerate(node.items): if idx: self.write(", ") self.visit(item, frame) self.write("]")
27,976
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_Dict
(self, node: nodes.Dict, frame: Frame)
1,661
1,669
def visit_Dict(self, node: nodes.Dict, frame: Frame) -> None: self.write("{") for idx, item in enumerate(node.items): if idx: self.write(", ") self.visit(item.key, frame) self.write(": ") self.visit(item.value, frame) self.write("}")
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1661-L1669
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
100
[]
0
true
92.742927
9
3
100
0
def visit_Dict(self, node: nodes.Dict, frame: Frame) -> None: self.write("{") for idx, item in enumerate(node.items): if idx: self.write(", ") self.visit(item.key, frame) self.write(": ") self.visit(item.value, frame) self.write("}")
27,977
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_Concat
(self, node: nodes.Concat, frame: Frame)
1,685
1,696
def visit_Concat(self, node: nodes.Concat, frame: Frame) -> None: if frame.eval_ctx.volatile: func_name = "(markup_join if context.eval_ctx.volatile else str_join)" elif frame.eval_ctx.autoescape: func_name = "markup_join" else: func_name = "str_join" self.write(f"{func_name}((") for arg in node.nodes: self.visit(arg, frame) self.write(", ") self.write("))")
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1685-L1696
42
[ 0, 1, 3, 6, 7, 8, 9, 10, 11 ]
75
[ 2, 4 ]
16.666667
false
92.742927
12
4
83.333333
0
def visit_Concat(self, node: nodes.Concat, frame: Frame) -> None: if frame.eval_ctx.volatile: func_name = "(markup_join if context.eval_ctx.volatile else str_join)" elif frame.eval_ctx.autoescape: func_name = "markup_join" else: func_name = "str_join" self.write(f"{func_name}((") for arg in node.nodes: self.visit(arg, frame) self.write(", ") self.write("))")
27,978
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_Compare
(self, node: nodes.Compare, frame: Frame)
1,699
1,704
def visit_Compare(self, node: nodes.Compare, frame: Frame) -> None: self.write("(") self.visit(node.expr, frame) for op in node.ops: self.visit(op, frame) self.write(")")
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1699-L1704
42
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
92.742927
6
2
100
0
def visit_Compare(self, node: nodes.Compare, frame: Frame) -> None: self.write("(") self.visit(node.expr, frame) for op in node.ops: self.visit(op, frame) self.write(")")
27,979
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_Operand
(self, node: nodes.Operand, frame: Frame)
1,706
1,708
def visit_Operand(self, node: nodes.Operand, frame: Frame) -> None: self.write(f" {operators[node.op]} ") self.visit(node.expr, frame)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1706-L1708
42
[ 0, 1, 2 ]
100
[]
0
true
92.742927
3
1
100
0
def visit_Operand(self, node: nodes.Operand, frame: Frame) -> None: self.write(f" {operators[node.op]} ") self.visit(node.expr, frame)
27,980
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_Getattr
(self, node: nodes.Getattr, frame: Frame)
1,711
1,720
def visit_Getattr(self, node: nodes.Getattr, frame: Frame) -> None: if self.environment.is_async: self.write("(await auto_await(") self.write("environment.getattr(") self.visit(node.node, frame) self.write(f", {node.attr!r})") if self.environment.is_async: self.write("))")
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1711-L1720
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
100
[]
0
true
92.742927
10
3
100
0
def visit_Getattr(self, node: nodes.Getattr, frame: Frame) -> None: if self.environment.is_async: self.write("(await auto_await(") self.write("environment.getattr(") self.visit(node.node, frame) self.write(f", {node.attr!r})") if self.environment.is_async: self.write("))")
27,981
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_Getitem
(self, node: nodes.Getitem, frame: Frame)
1,723
1,741
def visit_Getitem(self, node: nodes.Getitem, frame: Frame) -> None: # slices bypass the environment getitem method. if isinstance(node.arg, nodes.Slice): self.visit(node.node, frame) self.write("[") self.visit(node.arg, frame) self.write("]") else: if self.environment.is_async: self.write("(await auto_await(") self.write("environment.getitem(") self.visit(node.node, frame) self.write(", ") self.visit(node.arg, frame) self.write(")") if self.environment.is_async: self.write("))")
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1723-L1741
42
[ 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 ]
94.736842
[]
0
false
92.742927
19
4
100
0
def visit_Getitem(self, node: nodes.Getitem, frame: Frame) -> None: # slices bypass the environment getitem method. if isinstance(node.arg, nodes.Slice): self.visit(node.node, frame) self.write("[") self.visit(node.arg, frame) self.write("]") else: if self.environment.is_async: self.write("(await auto_await(") self.write("environment.getitem(") self.visit(node.node, frame) self.write(", ") self.visit(node.arg, frame) self.write(")") if self.environment.is_async: self.write("))")
27,982
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_Slice
(self, node: nodes.Slice, frame: Frame)
1,743
1,751
def visit_Slice(self, node: nodes.Slice, frame: Frame) -> None: if node.start is not None: self.visit(node.start, frame) self.write(":") if node.stop is not None: self.visit(node.stop, frame) if node.step is not None: self.write(":") self.visit(node.step, frame)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1743-L1751
42
[ 0, 1, 2, 3, 4, 5, 6 ]
77.777778
[ 7, 8 ]
22.222222
false
92.742927
9
4
77.777778
0
def visit_Slice(self, node: nodes.Slice, frame: Frame) -> None: if node.start is not None: self.visit(node.start, frame) self.write(":") if node.stop is not None: self.visit(node.stop, frame) if node.step is not None: self.write(":") self.visit(node.step, frame)
27,983
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_Filter
(self, node: nodes.Filter, frame: Frame)
1,796
1,810
def visit_Filter(self, node: nodes.Filter, frame: Frame) -> None: with self._filter_test_common(node, frame, True): # if the filter node is None we are inside a filter block # and want to write to the current buffer if node.node is not None: self.visit(node.node, frame) elif frame.eval_ctx.volatile: self.write( f"(Markup(concat({frame.buffer}))" f" if context.eval_ctx.autoescape else concat({frame.buffer}))" ) elif frame.eval_ctx.autoescape: self.write(f"Markup(concat({frame.buffer}))") else: self.write(f"concat({frame.buffer})")
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1796-L1810
42
[ 0, 1, 2, 3, 4, 5, 6, 11, 12, 14 ]
66.666667
[ 7 ]
6.666667
false
92.742927
15
5
93.333333
0
def visit_Filter(self, node: nodes.Filter, frame: Frame) -> None: with self._filter_test_common(node, frame, True): # if the filter node is None we are inside a filter block # and want to write to the current buffer if node.node is not None: self.visit(node.node, frame) elif frame.eval_ctx.volatile: self.write( f"(Markup(concat({frame.buffer}))" f" if context.eval_ctx.autoescape else concat({frame.buffer}))" ) elif frame.eval_ctx.autoescape: self.write(f"Markup(concat({frame.buffer}))") else: self.write(f"concat({frame.buffer})")
27,984
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_CondExpr
(self, node: nodes.CondExpr, frame: Frame)
1,818
1,838
def visit_CondExpr(self, node: nodes.CondExpr, frame: Frame) -> None: frame = frame.soft() def write_expr2() -> None: if node.expr2 is not None: self.visit(node.expr2, frame) return self.write( f'cond_expr_undefined("the inline if-expression on' f" {self.position(node)} evaluated to false and no else" f' section was defined.")' ) self.write("(") self.visit(node.expr1, frame) self.write(" if ") self.visit(node.test, frame) self.write(" else ") write_expr2() self.write(")")
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1818-L1838
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 13, 14, 15, 16, 17, 18, 19, 20 ]
80.952381
[]
0
false
92.742927
21
3
100
0
def visit_CondExpr(self, node: nodes.CondExpr, frame: Frame) -> None: frame = frame.soft() def write_expr2() -> None: if node.expr2 is not None: self.visit(node.expr2, frame) return self.write( f'cond_expr_undefined("the inline if-expression on' f" {self.position(node)} evaluated to false and no else" f' section was defined.")' ) self.write("(") self.visit(node.expr1, frame) self.write(" if ") self.visit(node.test, frame) self.write(" else ") write_expr2() self.write(")")
27,985
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_Call
( self, node: nodes.Call, frame: Frame, forward_caller: bool = False )
1,841
1,861
def visit_Call( self, node: nodes.Call, frame: Frame, forward_caller: bool = False ) -> None: if self.environment.is_async: self.write("(await auto_await(") if self.environment.sandboxed: self.write("environment.call(context, ") else: self.write("context.call(") self.visit(node.node, frame) extra_kwargs = {"caller": "caller"} if forward_caller else None loop_kwargs = {"_loop_vars": "_loop_vars"} if frame.loop_frame else {} block_kwargs = {"_block_vars": "_block_vars"} if frame.block_frame else {} if extra_kwargs: extra_kwargs.update(loop_kwargs, **block_kwargs) elif loop_kwargs or block_kwargs: extra_kwargs = dict(loop_kwargs, **block_kwargs) self.signature(node, frame, extra_kwargs) self.write(")") if self.environment.is_async: self.write("))")
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1841-L1861
42
[ 0, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ]
85.714286
[]
0
false
92.742927
21
7
100
0
def visit_Call( self, node: nodes.Call, frame: Frame, forward_caller: bool = False ) -> None: if self.environment.is_async: self.write("(await auto_await(") if self.environment.sandboxed: self.write("environment.call(context, ") else: self.write("context.call(") self.visit(node.node, frame) extra_kwargs = {"caller": "caller"} if forward_caller else None loop_kwargs = {"_loop_vars": "_loop_vars"} if frame.loop_frame else {} block_kwargs = {"_block_vars": "_block_vars"} if frame.block_frame else {} if extra_kwargs: extra_kwargs.update(loop_kwargs, **block_kwargs) elif loop_kwargs or block_kwargs: extra_kwargs = dict(loop_kwargs, **block_kwargs) self.signature(node, frame, extra_kwargs) self.write(")") if self.environment.is_async: self.write("))")
27,986
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_Keyword
(self, node: nodes.Keyword, frame: Frame)
1,863
1,865
def visit_Keyword(self, node: nodes.Keyword, frame: Frame) -> None: self.write(node.key + "=") self.visit(node.value, frame)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1863-L1865
42
[ 0, 1, 2 ]
100
[]
0
true
92.742927
3
1
100
0
def visit_Keyword(self, node: nodes.Keyword, frame: Frame) -> None: self.write(node.key + "=") self.visit(node.value, frame)
27,987
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_MarkSafe
(self, node: nodes.MarkSafe, frame: Frame)
1,869
1,872
def visit_MarkSafe(self, node: nodes.MarkSafe, frame: Frame) -> None: self.write("Markup(") self.visit(node.expr, frame) self.write(")")
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1869-L1872
42
[ 0 ]
25
[ 1, 2, 3 ]
75
false
92.742927
4
1
25
0
def visit_MarkSafe(self, node: nodes.MarkSafe, frame: Frame) -> None: self.write("Markup(") self.visit(node.expr, frame) self.write(")")
27,988
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_MarkSafeIfAutoescape
( self, node: nodes.MarkSafeIfAutoescape, frame: Frame )
1,874
1,879
def visit_MarkSafeIfAutoescape( self, node: nodes.MarkSafeIfAutoescape, frame: Frame ) -> None: self.write("(Markup if context.eval_ctx.autoescape else identity)(") self.visit(node.expr, frame) self.write(")")
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1874-L1879
42
[ 0, 3, 4, 5 ]
66.666667
[]
0
false
92.742927
6
1
100
0
def visit_MarkSafeIfAutoescape( self, node: nodes.MarkSafeIfAutoescape, frame: Frame ) -> None: self.write("(Markup if context.eval_ctx.autoescape else identity)(") self.visit(node.expr, frame) self.write(")")
27,989
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_EnvironmentAttribute
( self, node: nodes.EnvironmentAttribute, frame: Frame )
1,881
1,884
def visit_EnvironmentAttribute( self, node: nodes.EnvironmentAttribute, frame: Frame ) -> None: self.write("environment." + node.name)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1881-L1884
42
[ 0, 3 ]
50
[]
0
false
92.742927
4
1
100
0
def visit_EnvironmentAttribute( self, node: nodes.EnvironmentAttribute, frame: Frame ) -> None: self.write("environment." + node.name)
27,990
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_ExtensionAttribute
( self, node: nodes.ExtensionAttribute, frame: Frame )
1,886
1,889
def visit_ExtensionAttribute( self, node: nodes.ExtensionAttribute, frame: Frame ) -> None: self.write(f"environment.extensions[{node.identifier!r}].{node.name}")
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1886-L1889
42
[ 0, 3 ]
50
[]
0
false
92.742927
4
1
100
0
def visit_ExtensionAttribute( self, node: nodes.ExtensionAttribute, frame: Frame ) -> None: self.write(f"environment.extensions[{node.identifier!r}].{node.name}")
27,991
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_ImportedName
(self, node: nodes.ImportedName, frame: Frame)
1,891
1,892
def visit_ImportedName(self, node: nodes.ImportedName, frame: Frame) -> None: self.write(self.import_aliases[node.importname])
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1891-L1892
42
[ 0, 1 ]
100
[]
0
true
92.742927
2
1
100
0
def visit_ImportedName(self, node: nodes.ImportedName, frame: Frame) -> None: self.write(self.import_aliases[node.importname])
27,992
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_InternalName
(self, node: nodes.InternalName, frame: Frame)
1,894
1,895
def visit_InternalName(self, node: nodes.InternalName, frame: Frame) -> None: self.write(node.name)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1894-L1895
42
[ 0 ]
50
[ 1 ]
50
false
92.742927
2
1
50
0
def visit_InternalName(self, node: nodes.InternalName, frame: Frame) -> None: self.write(node.name)
27,993
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_ContextReference
( self, node: nodes.ContextReference, frame: Frame )
1,897
1,900
def visit_ContextReference( self, node: nodes.ContextReference, frame: Frame ) -> None: self.write("context")
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1897-L1900
42
[ 0, 3 ]
50
[]
0
false
92.742927
4
1
100
0
def visit_ContextReference( self, node: nodes.ContextReference, frame: Frame ) -> None: self.write("context")
27,994
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_DerivedContextReference
( self, node: nodes.DerivedContextReference, frame: Frame )
1,902
1,905
def visit_DerivedContextReference( self, node: nodes.DerivedContextReference, frame: Frame ) -> None: self.write(self.derive_context(frame))
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1902-L1905
42
[ 0, 3 ]
50
[]
0
false
92.742927
4
1
100
0
def visit_DerivedContextReference( self, node: nodes.DerivedContextReference, frame: Frame ) -> None: self.write(self.derive_context(frame))
27,995
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_Continue
(self, node: nodes.Continue, frame: Frame)
1,907
1,908
def visit_Continue(self, node: nodes.Continue, frame: Frame) -> None: self.writeline("continue", node)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1907-L1908
42
[ 0, 1 ]
100
[]
0
true
92.742927
2
1
100
0
def visit_Continue(self, node: nodes.Continue, frame: Frame) -> None: self.writeline("continue", node)
27,996
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_Break
(self, node: nodes.Break, frame: Frame)
1,910
1,911
def visit_Break(self, node: nodes.Break, frame: Frame) -> None: self.writeline("break", node)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1910-L1911
42
[ 0, 1 ]
100
[]
0
true
92.742927
2
1
100
0
def visit_Break(self, node: nodes.Break, frame: Frame) -> None: self.writeline("break", node)
27,997
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_Scope
(self, node: nodes.Scope, frame: Frame)
1,913
1,918
def visit_Scope(self, node: nodes.Scope, frame: Frame) -> None: scope_frame = frame.inner() scope_frame.symbols.analyze_node(node) self.enter_frame(scope_frame) self.blockvisit(node.body, scope_frame) self.leave_frame(scope_frame)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1913-L1918
42
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
92.742927
6
1
100
0
def visit_Scope(self, node: nodes.Scope, frame: Frame) -> None: scope_frame = frame.inner() scope_frame.symbols.analyze_node(node) self.enter_frame(scope_frame) self.blockvisit(node.body, scope_frame) self.leave_frame(scope_frame)
27,998
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_OverlayScope
(self, node: nodes.OverlayScope, frame: Frame)
1,920
1,932
def visit_OverlayScope(self, node: nodes.OverlayScope, frame: Frame) -> None: ctx = self.temporary_identifier() self.writeline(f"{ctx} = {self.derive_context(frame)}") self.writeline(f"{ctx}.vars = ") self.visit(node.context, frame) self.push_context_reference(ctx) scope_frame = frame.inner(isolated=True) scope_frame.symbols.analyze_node(node) self.enter_frame(scope_frame) self.blockvisit(node.body, scope_frame) self.leave_frame(scope_frame) self.pop_context_reference()
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1920-L1932
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]
100
[]
0
true
92.742927
13
1
100
0
def visit_OverlayScope(self, node: nodes.OverlayScope, frame: Frame) -> None: ctx = self.temporary_identifier() self.writeline(f"{ctx} = {self.derive_context(frame)}") self.writeline(f"{ctx}.vars = ") self.visit(node.context, frame) self.push_context_reference(ctx) scope_frame = frame.inner(isolated=True) scope_frame.symbols.analyze_node(node) self.enter_frame(scope_frame) self.blockvisit(node.body, scope_frame) self.leave_frame(scope_frame) self.pop_context_reference()
27,999
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_EvalContextModifier
( self, node: nodes.EvalContextModifier, frame: Frame )
1,934
1,945
def visit_EvalContextModifier( self, node: nodes.EvalContextModifier, frame: Frame ) -> None: for keyword in node.options: self.writeline(f"context.eval_ctx.{keyword.key} = ") self.visit(keyword.value, frame) try: val = keyword.value.as_const(frame.eval_ctx) except nodes.Impossible: frame.eval_ctx.volatile = True else: setattr(frame.eval_ctx, keyword.key, val)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1934-L1945
42
[ 0, 3, 4, 5, 6, 7, 8, 9, 11 ]
75
[]
0
false
92.742927
12
3
100
0
def visit_EvalContextModifier( self, node: nodes.EvalContextModifier, frame: Frame ) -> None: for keyword in node.options: self.writeline(f"context.eval_ctx.{keyword.key} = ") self.visit(keyword.value, frame) try: val = keyword.value.as_const(frame.eval_ctx) except nodes.Impossible: frame.eval_ctx.volatile = True else: setattr(frame.eval_ctx, keyword.key, val)
28,000
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/compiler.py
CodeGenerator.visit_ScopedEvalContextModifier
( self, node: nodes.ScopedEvalContextModifier, frame: Frame )
1,947
1,957
def visit_ScopedEvalContextModifier( self, node: nodes.ScopedEvalContextModifier, frame: Frame ) -> None: old_ctx_name = self.temporary_identifier() saved_ctx = frame.eval_ctx.save() self.writeline(f"{old_ctx_name} = context.eval_ctx.save()") self.visit_EvalContextModifier(node, frame) for child in node.body: self.visit(child, frame) frame.eval_ctx.revert(saved_ctx) self.writeline(f"context.eval_ctx.revert({old_ctx_name})")
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/compiler.py#L1947-L1957
42
[ 0, 3, 4, 5, 6, 7, 8, 9, 10 ]
81.818182
[]
0
false
92.742927
11
2
100
0
def visit_ScopedEvalContextModifier( self, node: nodes.ScopedEvalContextModifier, frame: Frame ) -> None: old_ctx_name = self.temporary_identifier() saved_ctx = frame.eval_ctx.save() self.writeline(f"{old_ctx_name} = context.eval_ctx.save()") self.visit_EvalContextModifier(node, frame) for child in node.body: self.visit(child, frame) frame.eval_ctx.revert(saved_ctx) self.writeline(f"context.eval_ctx.revert({old_ctx_name})")
28,001
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
identity
(x: V)
return x
Returns its argument. Useful for certain things in the environment.
Returns its argument. Useful for certain things in the environment.
68
72
def identity(x: V) -> V: """Returns its argument. Useful for certain things in the environment. """ return x
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L68-L72
42
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
89.049919
5
1
100
2
def identity(x: V) -> V: return x
28,002
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
markup_join
(seq: t.Iterable[t.Any])
return concat(buf)
Concatenation that escapes if necessary and converts to string.
Concatenation that escapes if necessary and converts to string.
75
83
def markup_join(seq: t.Iterable[t.Any]) -> str: """Concatenation that escapes if necessary and converts to string.""" buf = [] iterator = map(soft_str, seq) for arg in iterator: buf.append(arg) if hasattr(arg, "__html__"): return Markup("").join(chain(buf, iterator)) return concat(buf)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L75-L83
42
[ 0, 1 ]
22.222222
[ 2, 3, 4, 5, 6, 7, 8 ]
77.777778
false
89.049919
9
3
22.222222
1
def markup_join(seq: t.Iterable[t.Any]) -> str: buf = [] iterator = map(soft_str, seq) for arg in iterator: buf.append(arg) if hasattr(arg, "__html__"): return Markup("").join(chain(buf, iterator)) return concat(buf)
28,003
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
str_join
(seq: t.Iterable[t.Any])
return concat(map(str, seq))
Simple args to string conversion and concatenation.
Simple args to string conversion and concatenation.
86
88
def str_join(seq: t.Iterable[t.Any]) -> str: """Simple args to string conversion and concatenation.""" return concat(map(str, seq))
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L86-L88
42
[ 0, 1, 2 ]
100
[]
0
true
89.049919
3
1
100
1
def str_join(seq: t.Iterable[t.Any]) -> str: return concat(map(str, seq))
28,004
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
new_context
( environment: "Environment", template_name: t.Optional[str], blocks: t.Dict[str, t.Callable[["Context"], t.Iterator[str]]], vars: t.Optional[t.Dict[str, t.Any]] = None, shared: bool = False, globals: t.Optional[t.MutableMapping[str, t.Any]] = None, locals: t.Optional[t.Mapping[str, t.Any]] = None, )
return environment.context_class( environment, parent, template_name, blocks, globals=globals )
Internal helper for context creation.
Internal helper for context creation.
91
117
def new_context( environment: "Environment", template_name: t.Optional[str], blocks: t.Dict[str, t.Callable[["Context"], t.Iterator[str]]], vars: t.Optional[t.Dict[str, t.Any]] = None, shared: bool = False, globals: t.Optional[t.MutableMapping[str, t.Any]] = None, locals: t.Optional[t.Mapping[str, t.Any]] = None, ) -> "Context": """Internal helper for context creation.""" if vars is None: vars = {} if shared: parent = vars else: parent = dict(globals or (), **vars) if locals: # if the parent is shared a copy should be created because # we don't want to modify the dict passed if shared: parent = dict(parent) for key, value in locals.items(): if value is not missing: parent[key] = value return environment.context_class( environment, parent, template_name, blocks, globals=globals )
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L91-L117
42
[ 0, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 ]
70.37037
[]
0
false
89.049919
27
8
100
1
def new_context( environment: "Environment", template_name: t.Optional[str], blocks: t.Dict[str, t.Callable[["Context"], t.Iterator[str]]], vars: t.Optional[t.Dict[str, t.Any]] = None, shared: bool = False, globals: t.Optional[t.MutableMapping[str, t.Any]] = None, locals: t.Optional[t.Mapping[str, t.Any]] = None, ) -> "Context": if vars is None: vars = {} if shared: parent = vars else: parent = dict(globals or (), **vars) if locals: # if the parent is shared a copy should be created because # we don't want to modify the dict passed if shared: parent = dict(parent) for key, value in locals.items(): if value is not missing: parent[key] = value return environment.context_class( environment, parent, template_name, blocks, globals=globals )
28,005
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
_dict_method_all
(dict_method: F)
return t.cast(F, f_all)
134
139
def _dict_method_all(dict_method: F) -> F: @functools.wraps(dict_method) def f_all(self: "Context") -> t.Any: return dict_method(self.get_all()) return t.cast(F, f_all)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L134-L139
42
[ 0, 1, 2, 4, 5 ]
83.333333
[ 3 ]
16.666667
false
89.049919
6
2
83.333333
0
def _dict_method_all(dict_method: F) -> F: @functools.wraps(dict_method) def f_all(self: "Context") -> t.Any: return dict_method(self.get_all()) return t.cast(F, f_all)
28,006
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
make_logging_undefined
( logger: t.Optional["logging.Logger"] = None, base: t.Type[Undefined] = Undefined )
return LoggingUndefined
Given a logger object this returns a new undefined class that will log certain failures. It will log iterations and printing. If no logger is given a default logger is created. Example:: logger = logging.getLogger(__name__) LoggingUndefined = make_logging_undefined( logger=logger, base=Undefined ) .. versionadded:: 2.8 :param logger: the logger to use. If not provided, a default logger is created. :param base: the base class to add logging functionality to. This defaults to :class:`Undefined`.
Given a logger object this returns a new undefined class that will log certain failures. It will log iterations and printing. If no logger is given a default logger is created.
901
958
def make_logging_undefined( logger: t.Optional["logging.Logger"] = None, base: t.Type[Undefined] = Undefined ) -> t.Type[Undefined]: """Given a logger object this returns a new undefined class that will log certain failures. It will log iterations and printing. If no logger is given a default logger is created. Example:: logger = logging.getLogger(__name__) LoggingUndefined = make_logging_undefined( logger=logger, base=Undefined ) .. versionadded:: 2.8 :param logger: the logger to use. If not provided, a default logger is created. :param base: the base class to add logging functionality to. This defaults to :class:`Undefined`. """ if logger is None: import logging logger = logging.getLogger(__name__) logger.addHandler(logging.StreamHandler(sys.stderr)) def _log_message(undef: Undefined) -> None: logger.warning( # type: ignore "Template variable warning: %s", undef._undefined_message ) class LoggingUndefined(base): # type: ignore __slots__ = () def _fail_with_undefined_error( # type: ignore self, *args: t.Any, **kwargs: t.Any ) -> "te.NoReturn": try: super()._fail_with_undefined_error(*args, **kwargs) except self._undefined_exception as e: logger.error("Template variable error: %s", e) # type: ignore raise e def __str__(self) -> str: _log_message(self) return super().__str__() # type: ignore def __iter__(self) -> t.Iterator[t.Any]: _log_message(self) return super().__iter__() # type: ignore def __bool__(self) -> bool: _log_message(self) return super().__bool__() # type: ignore return LoggingUndefined
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L901-L958
42
[ 0, 21, 22, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57 ]
58.62069
[ 23, 25, 26 ]
5.172414
false
89.049919
58
8
94.827586
18
def make_logging_undefined( logger: t.Optional["logging.Logger"] = None, base: t.Type[Undefined] = Undefined ) -> t.Type[Undefined]: if logger is None: import logging logger = logging.getLogger(__name__) logger.addHandler(logging.StreamHandler(sys.stderr)) def _log_message(undef: Undefined) -> None: logger.warning( # type: ignore "Template variable warning: %s", undef._undefined_message ) class LoggingUndefined(base): # type: ignore __slots__ = () def _fail_with_undefined_error( # type: ignore self, *args: t.Any, **kwargs: t.Any ) -> "te.NoReturn": try: super()._fail_with_undefined_error(*args, **kwargs) except self._undefined_exception as e: logger.error("Template variable error: %s", e) # type: ignore raise e def __str__(self) -> str: _log_message(self) return super().__str__() # type: ignore def __iter__(self) -> t.Iterator[t.Any]: _log_message(self) return super().__iter__() # type: ignore def __bool__(self) -> bool: _log_message(self) return super().__bool__() # type: ignore return LoggingUndefined
28,007
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
TemplateReference.__init__
(self, context: "Context")
123
124
def __init__(self, context: "Context") -> None: self.__context = context
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L123-L124
42
[ 0, 1 ]
100
[]
0
true
89.049919
2
1
100
0
def __init__(self, context: "Context") -> None: self.__context = context
28,008
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
TemplateReference.__getitem__
(self, name: str)
return BlockReference(name, self.__context, blocks, 0)
126
128
def __getitem__(self, name: str) -> t.Any: blocks = self.__context.blocks[name] return BlockReference(name, self.__context, blocks, 0)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L126-L128
42
[ 0, 1, 2 ]
100
[]
0
true
89.049919
3
1
100
0
def __getitem__(self, name: str) -> t.Any: blocks = self.__context.blocks[name] return BlockReference(name, self.__context, blocks, 0)
28,009
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
TemplateReference.__repr__
(self)
return f"<{type(self).__name__} {self.__context.name!r}>"
130
131
def __repr__(self) -> str: return f"<{type(self).__name__} {self.__context.name!r}>"
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L130-L131
42
[ 0 ]
50
[ 1 ]
50
false
89.049919
2
1
50
0
def __repr__(self) -> str: return f"<{type(self).__name__} {self.__context.name!r}>"
28,010
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
BlockReference.__init__
( self, name: str, context: "Context", stack: t.List[t.Callable[["Context"], t.Iterator[str]]], depth: int, )
342
352
def __init__( self, name: str, context: "Context", stack: t.List[t.Callable[["Context"], t.Iterator[str]]], depth: int, ) -> None: self.name = name self._context = context self._stack = stack self._depth = depth
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L342-L352
42
[ 0, 7, 8, 9, 10 ]
45.454545
[]
0
false
89.049919
11
1
100
0
def __init__( self, name: str, context: "Context", stack: t.List[t.Callable[["Context"], t.Iterator[str]]], depth: int, ) -> None: self.name = name self._context = context self._stack = stack self._depth = depth
28,011
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
BlockReference.super
(self)
return BlockReference(self.name, self._context, self._stack, self._depth + 1)
Super the block.
Super the block.
355
361
def super(self) -> t.Union["BlockReference", "Undefined"]: """Super the block.""" if self._depth + 1 >= len(self._stack): return self._context.environment.undefined( f"there is no parent block called {self.name!r}.", name="super" ) return BlockReference(self.name, self._context, self._stack, self._depth + 1)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L355-L361
42
[ 0, 1 ]
28.571429
[ 2, 3, 6 ]
42.857143
false
89.049919
7
2
57.142857
1
def super(self) -> t.Union["BlockReference", "Undefined"]: if self._depth + 1 >= len(self._stack): return self._context.environment.undefined( f"there is no parent block called {self.name!r}.", name="super" ) return BlockReference(self.name, self._context, self._stack, self._depth + 1)
28,012
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
BlockReference._async_call
(self)
return rv
364
372
async def _async_call(self) -> str: rv = concat( [x async for x in self._stack[self._depth](self._context)] # type: ignore ) if self._context.eval_ctx.autoescape: return Markup(rv) return rv
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L364-L372
42
[ 0, 1, 4, 5, 6, 7 ]
66.666667
[ 8 ]
11.111111
false
89.049919
9
3
88.888889
0
async def _async_call(self) -> str: rv = concat( [x async for x in self._stack[self._depth](self._context)] # type: ignore ) if self._context.eval_ctx.autoescape: return Markup(rv) return rv
28,013
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
BlockReference.__call__
(self)
return rv
375
384
def __call__(self) -> str: if self._context.environment.is_async: return self._async_call() # type: ignore rv = concat(self._stack[self._depth](self._context)) if self._context.eval_ctx.autoescape: return Markup(rv) return rv
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L375-L384
42
[ 0, 1, 2, 3, 4, 5, 6, 8, 9 ]
90
[ 7 ]
10
false
89.049919
10
3
90
0
def __call__(self) -> str: if self._context.environment.is_async: return self._async_call() # type: ignore rv = concat(self._stack[self._depth](self._context)) if self._context.eval_ctx.autoescape: return Markup(rv) return rv
28,014
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
LoopContext.__init__
( self, iterable: t.Iterable[V], undefined: t.Type["Undefined"], recurse: t.Optional["LoopRenderFunc"] = None, depth0: int = 0, )
:param iterable: Iterable to wrap. :param undefined: :class:`Undefined` class to use for next and previous items. :param recurse: The function to render the loop body when the loop is marked recursive. :param depth0: Incremented when looping recursively.
:param iterable: Iterable to wrap. :param undefined: :class:`Undefined` class to use for next and previous items. :param recurse: The function to render the loop body when the loop is marked recursive. :param depth0: Incremented when looping recursively.
401
421
def __init__( self, iterable: t.Iterable[V], undefined: t.Type["Undefined"], recurse: t.Optional["LoopRenderFunc"] = None, depth0: int = 0, ) -> None: """ :param iterable: Iterable to wrap. :param undefined: :class:`Undefined` class to use for next and previous items. :param recurse: The function to render the loop body when the loop is marked recursive. :param depth0: Incremented when looping recursively. """ self._iterable = iterable self._iterator = self._to_iterator(iterable) self._undefined = undefined self._recurse = recurse #: How many levels deep a recursive loop currently is, starting at 0. self.depth0 = depth0
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L401-L421
42
[ 0, 14, 15, 16, 17, 18, 19, 20 ]
38.095238
[]
0
false
89.049919
21
1
100
6
def __init__( self, iterable: t.Iterable[V], undefined: t.Type["Undefined"], recurse: t.Optional["LoopRenderFunc"] = None, depth0: int = 0, ) -> None: self._iterable = iterable self._iterator = self._to_iterator(iterable) self._undefined = undefined self._recurse = recurse #: How many levels deep a recursive loop currently is, starting at 0. self.depth0 = depth0
28,015
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
LoopContext._to_iterator
(iterable: t.Iterable[V])
return iter(iterable)
424
425
def _to_iterator(iterable: t.Iterable[V]) -> t.Iterator[V]: return iter(iterable)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L424-L425
42
[ 0, 1 ]
100
[]
0
true
89.049919
2
1
100
0
def _to_iterator(iterable: t.Iterable[V]) -> t.Iterator[V]: return iter(iterable)
28,016
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
LoopContext.length
(self)
return self._length
Length of the iterable. If the iterable is a generator or otherwise does not have a size, it is eagerly evaluated to get a size.
Length of the iterable.
428
444
def length(self) -> int: """Length of the iterable. If the iterable is a generator or otherwise does not have a size, it is eagerly evaluated to get a size. """ if self._length is not None: return self._length try: self._length = len(self._iterable) # type: ignore except TypeError: iterable = list(self._iterator) self._iterator = self._to_iterator(iterable) self._length = len(iterable) + self.index + (self._after is not missing) return self._length
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L428-L444
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]
100
[]
0
true
89.049919
17
3
100
4
def length(self) -> int: if self._length is not None: return self._length try: self._length = len(self._iterable) # type: ignore except TypeError: iterable = list(self._iterator) self._iterator = self._to_iterator(iterable) self._length = len(iterable) + self.index + (self._after is not missing) return self._length
28,017
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
LoopContext.__len__
(self)
return self.length
446
447
def __len__(self) -> int: return self.length
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L446-L447
42
[ 0 ]
50
[ 1 ]
50
false
89.049919
2
1
50
0
def __len__(self) -> int: return self.length
28,018
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
LoopContext.depth
(self)
return self.depth0 + 1
How many levels deep a recursive loop currently is, starting at 1.
How many levels deep a recursive loop currently is, starting at 1.
450
452
def depth(self) -> int: """How many levels deep a recursive loop currently is, starting at 1.""" return self.depth0 + 1
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L450-L452
42
[ 0, 1, 2 ]
100
[]
0
true
89.049919
3
1
100
1
def depth(self) -> int: return self.depth0 + 1
28,019
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
LoopContext.index
(self)
return self.index0 + 1
Current iteration of the loop, starting at 1.
Current iteration of the loop, starting at 1.
455
457
def index(self) -> int: """Current iteration of the loop, starting at 1.""" return self.index0 + 1
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L455-L457
42
[ 0, 1, 2 ]
100
[]
0
true
89.049919
3
1
100
1
def index(self) -> int: return self.index0 + 1
28,020
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
LoopContext.revindex0
(self)
return self.length - self.index
Number of iterations from the end of the loop, ending at 0. Requires calculating :attr:`length`.
Number of iterations from the end of the loop, ending at 0.
460
465
def revindex0(self) -> int: """Number of iterations from the end of the loop, ending at 0. Requires calculating :attr:`length`. """ return self.length - self.index
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L460-L465
42
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
89.049919
6
1
100
3
def revindex0(self) -> int: return self.length - self.index
28,021
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
LoopContext.revindex
(self)
return self.length - self.index0
Number of iterations from the end of the loop, ending at 1. Requires calculating :attr:`length`.
Number of iterations from the end of the loop, ending at 1.
468
473
def revindex(self) -> int: """Number of iterations from the end of the loop, ending at 1. Requires calculating :attr:`length`. """ return self.length - self.index0
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L468-L473
42
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
89.049919
6
1
100
3
def revindex(self) -> int: return self.length - self.index0
28,022
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
LoopContext.first
(self)
return self.index0 == 0
Whether this is the first iteration of the loop.
Whether this is the first iteration of the loop.
476
478
def first(self) -> bool: """Whether this is the first iteration of the loop.""" return self.index0 == 0
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L476-L478
42
[ 0, 1, 2 ]
100
[]
0
true
89.049919
3
1
100
1
def first(self) -> bool: return self.index0 == 0
28,023
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
LoopContext._peek_next
(self)
return self._after
Return the next element in the iterable, or :data:`missing` if the iterable is exhausted. Only peeks one item ahead, caching the result in :attr:`_last` for use in subsequent checks. The cache is reset when :meth:`__next__` is called.
Return the next element in the iterable, or :data:`missing` if the iterable is exhausted. Only peeks one item ahead, caching the result in :attr:`_last` for use in subsequent checks. The cache is reset when :meth:`__next__` is called.
480
490
def _peek_next(self) -> t.Any: """Return the next element in the iterable, or :data:`missing` if the iterable is exhausted. Only peeks one item ahead, caching the result in :attr:`_last` for use in subsequent checks. The cache is reset when :meth:`__next__` is called. """ if self._after is not missing: return self._after self._after = next(self._iterator, missing) return self._after
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L480-L490
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
100
[]
0
true
89.049919
11
2
100
4
def _peek_next(self) -> t.Any: if self._after is not missing: return self._after self._after = next(self._iterator, missing) return self._after
28,024
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
LoopContext.last
(self)
return self._peek_next() is missing
Whether this is the last iteration of the loop. Causes the iterable to advance early. See :func:`itertools.groupby` for issues this can cause. The :func:`groupby` filter avoids that issue.
Whether this is the last iteration of the loop.
493
500
def last(self) -> bool: """Whether this is the last iteration of the loop. Causes the iterable to advance early. See :func:`itertools.groupby` for issues this can cause. The :func:`groupby` filter avoids that issue. """ return self._peek_next() is missing
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L493-L500
42
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
89.049919
8
1
100
5
def last(self) -> bool: return self._peek_next() is missing
28,025
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
LoopContext.previtem
(self)
return self._before
The item in the previous iteration. Undefined during the first iteration.
The item in the previous iteration. Undefined during the first iteration.
503
510
def previtem(self) -> t.Union[t.Any, "Undefined"]: """The item in the previous iteration. Undefined during the first iteration. """ if self.first: return self._undefined("there is no previous item") return self._before
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L503-L510
42
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
89.049919
8
2
100
2
def previtem(self) -> t.Union[t.Any, "Undefined"]: if self.first: return self._undefined("there is no previous item") return self._before
28,026
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
LoopContext.nextitem
(self)
return rv
The item in the next iteration. Undefined during the last iteration. Causes the iterable to advance early. See :func:`itertools.groupby` for issues this can cause. The :func:`jinja-filters.groupby` filter avoids that issue.
The item in the next iteration. Undefined during the last iteration.
513
526
def nextitem(self) -> t.Union[t.Any, "Undefined"]: """The item in the next iteration. Undefined during the last iteration. Causes the iterable to advance early. See :func:`itertools.groupby` for issues this can cause. The :func:`jinja-filters.groupby` filter avoids that issue. """ rv = self._peek_next() if rv is missing: return self._undefined("there is no next item") return rv
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L513-L526
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]
100
[]
0
true
89.049919
14
2
100
6
def nextitem(self) -> t.Union[t.Any, "Undefined"]: rv = self._peek_next() if rv is missing: return self._undefined("there is no next item") return rv
28,027
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
LoopContext.cycle
(self, *args: V)
return args[self.index0 % len(args)]
Return a value from the given args, cycling through based on the current :attr:`index0`. :param args: One or more values to cycle through.
Return a value from the given args, cycling through based on the current :attr:`index0`.
528
537
def cycle(self, *args: V) -> V: """Return a value from the given args, cycling through based on the current :attr:`index0`. :param args: One or more values to cycle through. """ if not args: raise TypeError("no items for cycling given") return args[self.index0 % len(args)]
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L528-L537
42
[ 0, 1, 2, 3, 4, 5, 6, 8, 9 ]
90
[ 7 ]
10
false
89.049919
10
2
90
4
def cycle(self, *args: V) -> V: if not args: raise TypeError("no items for cycling given") return args[self.index0 % len(args)]
28,028
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
LoopContext.changed
(self, *value: t.Any)
return False
Return ``True`` if previously called with a different value (including when called for the first time). :param value: One or more values to compare to the last call.
Return ``True`` if previously called with a different value (including when called for the first time).
539
549
def changed(self, *value: t.Any) -> bool: """Return ``True`` if previously called with a different value (including when called for the first time). :param value: One or more values to compare to the last call. """ if self._last_changed_value != value: self._last_changed_value = value return True return False
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L539-L549
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
100
[]
0
true
89.049919
11
2
100
4
def changed(self, *value: t.Any) -> bool: if self._last_changed_value != value: self._last_changed_value = value return True return False
28,029
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
LoopContext.__iter__
(self)
return self
551
552
def __iter__(self) -> "LoopContext": return self
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L551-L552
42
[ 0, 1 ]
100
[]
0
true
89.049919
2
1
100
0
def __iter__(self) -> "LoopContext": return self
28,030
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
LoopContext.__next__
(self)
return rv, self
554
564
def __next__(self) -> t.Tuple[t.Any, "LoopContext"]: if self._after is not missing: rv = self._after self._after = missing else: rv = next(self._iterator) self.index0 += 1 self._before = self._current self._current = rv return rv, self
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L554-L564
42
[ 0, 1, 2, 3, 5, 6, 7, 8, 9, 10 ]
90.909091
[]
0
false
89.049919
11
2
100
0
def __next__(self) -> t.Tuple[t.Any, "LoopContext"]: if self._after is not missing: rv = self._after self._after = missing else: rv = next(self._iterator) self.index0 += 1 self._before = self._current self._current = rv return rv, self
28,031
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
LoopContext.__call__
(self, iterable: t.Iterable[V])
return self._recurse(iterable, self._recurse, depth=self.depth)
When iterating over nested data, render the body of the loop recursively with the given inner iterable data. The loop must have the ``recursive`` marker for this to work.
When iterating over nested data, render the body of the loop recursively with the given inner iterable data.
567
578
def __call__(self, iterable: t.Iterable[V]) -> str: """When iterating over nested data, render the body of the loop recursively with the given inner iterable data. The loop must have the ``recursive`` marker for this to work. """ if self._recurse is None: raise TypeError( "The loop must have the 'recursive' marker to be called recursively." ) return self._recurse(iterable, self._recurse, depth=self.depth)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L567-L578
42
[ 0, 1, 2, 3, 4, 5, 6, 10, 11 ]
75
[ 7 ]
8.333333
false
89.049919
12
2
91.666667
4
def __call__(self, iterable: t.Iterable[V]) -> str: if self._recurse is None: raise TypeError( "The loop must have the 'recursive' marker to be called recursively." ) return self._recurse(iterable, self._recurse, depth=self.depth)
28,032
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
LoopContext.__repr__
(self)
return f"<{type(self).__name__} {self.index}/{self.length}>"
580
581
def __repr__(self) -> str: return f"<{type(self).__name__} {self.index}/{self.length}>"
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L580-L581
42
[ 0 ]
50
[ 1 ]
50
false
89.049919
2
1
50
0
def __repr__(self) -> str: return f"<{type(self).__name__} {self.index}/{self.length}>"
28,033
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
AsyncLoopContext._to_iterator
( # type: ignore iterable: t.Union[t.Iterable[V], t.AsyncIterable[V]] )
return auto_aiter(iterable)
588
591
def _to_iterator( # type: ignore iterable: t.Union[t.Iterable[V], t.AsyncIterable[V]] ) -> t.AsyncIterator[V]: return auto_aiter(iterable)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L588-L591
42
[ 0, 3 ]
50
[]
0
false
89.049919
4
1
100
0
def _to_iterator( # type: ignore iterable: t.Union[t.Iterable[V], t.AsyncIterable[V]] ) -> t.AsyncIterator[V]: return auto_aiter(iterable)
28,034
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
AsyncLoopContext.length
(self)
return self._length
594
605
async def length(self) -> int: # type: ignore if self._length is not None: return self._length try: self._length = len(self._iterable) # type: ignore except TypeError: iterable = [x async for x in self._iterator] self._iterator = self._to_iterator(iterable) self._length = len(iterable) + self.index + (self._after is not missing) return self._length
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L594-L605
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
100
[]
0
true
89.049919
12
4
100
0
async def length(self) -> int: # type: ignore if self._length is not None: return self._length try: self._length = len(self._iterable) # type: ignore except TypeError: iterable = [x async for x in self._iterator] self._iterator = self._to_iterator(iterable) self._length = len(iterable) + self.index + (self._after is not missing) return self._length
28,035
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
AsyncLoopContext.revindex0
(self)
return await self.length - self.index
608
609
async def revindex0(self) -> int: # type: ignore return await self.length - self.index
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L608-L609
42
[ 0, 1 ]
100
[]
0
true
89.049919
2
1
100
0
async def revindex0(self) -> int: # type: ignore return await self.length - self.index
28,036
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
AsyncLoopContext.revindex
(self)
return await self.length - self.index0
612
613
async def revindex(self) -> int: # type: ignore return await self.length - self.index0
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L612-L613
42
[ 0, 1 ]
100
[]
0
true
89.049919
2
1
100
0
async def revindex(self) -> int: # type: ignore return await self.length - self.index0
28,037
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
AsyncLoopContext._peek_next
(self)
return self._after
615
624
async def _peek_next(self) -> t.Any: if self._after is not missing: return self._after try: self._after = await self._iterator.__anext__() except StopAsyncIteration: self._after = missing return self._after
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L615-L624
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
100
[]
0
true
89.049919
10
3
100
0
async def _peek_next(self) -> t.Any: if self._after is not missing: return self._after try: self._after = await self._iterator.__anext__() except StopAsyncIteration: self._after = missing return self._after
28,038
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
AsyncLoopContext.last
(self)
return await self._peek_next() is missing
627
628
async def last(self) -> bool: # type: ignore return await self._peek_next() is missing
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L627-L628
42
[ 0, 1 ]
100
[]
0
true
89.049919
2
1
100
0
async def last(self) -> bool: # type: ignore return await self._peek_next() is missing
28,039
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
AsyncLoopContext.nextitem
(self)
return rv
631
637
async def nextitem(self) -> t.Union[t.Any, "Undefined"]: rv = await self._peek_next() if rv is missing: return self._undefined("there is no next item") return rv
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L631-L637
42
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
89.049919
7
2
100
0
async def nextitem(self) -> t.Union[t.Any, "Undefined"]: rv = await self._peek_next() if rv is missing: return self._undefined("there is no next item") return rv
28,040
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
AsyncLoopContext.__aiter__
(self)
return self
639
640
def __aiter__(self) -> "AsyncLoopContext": return self
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L639-L640
42
[ 0, 1 ]
100
[]
0
true
89.049919
2
1
100
0
def __aiter__(self) -> "AsyncLoopContext": return self
28,041
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
AsyncLoopContext.__anext__
(self)
return rv, self
642
652
async def __anext__(self) -> t.Tuple[t.Any, "AsyncLoopContext"]: if self._after is not missing: rv = self._after self._after = missing else: rv = await self._iterator.__anext__() self.index0 += 1 self._before = self._current self._current = rv return rv, self
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L642-L652
42
[ 0, 1, 2, 3, 5, 6, 7, 8, 9, 10 ]
90.909091
[]
0
false
89.049919
11
2
100
0
async def __anext__(self) -> t.Tuple[t.Any, "AsyncLoopContext"]: if self._after is not missing: rv = self._after self._after = missing else: rv = await self._iterator.__anext__() self.index0 += 1 self._before = self._current self._current = rv return rv, self
28,042
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
Macro.__init__
( self, environment: "Environment", func: t.Callable[..., str], name: str, arguments: t.List[str], catch_kwargs: bool, catch_varargs: bool, caller: bool, default_autoescape: t.Optional[bool] = None, )
658
685
def __init__( self, environment: "Environment", func: t.Callable[..., str], name: str, arguments: t.List[str], catch_kwargs: bool, catch_varargs: bool, caller: bool, default_autoescape: t.Optional[bool] = None, ): self._environment = environment self._func = func self._argument_count = len(arguments) self.name = name self.arguments = arguments self.catch_kwargs = catch_kwargs self.catch_varargs = catch_varargs self.caller = caller self.explicit_caller = "caller" in arguments if default_autoescape is None: if callable(environment.autoescape): default_autoescape = environment.autoescape(None) else: default_autoescape = environment.autoescape self._default_autoescape = default_autoescape
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L658-L685
42
[ 0, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 26, 27 ]
50
[ 22, 23, 25 ]
10.714286
false
89.049919
28
3
89.285714
0
def __init__( self, environment: "Environment", func: t.Callable[..., str], name: str, arguments: t.List[str], catch_kwargs: bool, catch_varargs: bool, caller: bool, default_autoescape: t.Optional[bool] = None, ): self._environment = environment self._func = func self._argument_count = len(arguments) self.name = name self.arguments = arguments self.catch_kwargs = catch_kwargs self.catch_varargs = catch_varargs self.caller = caller self.explicit_caller = "caller" in arguments if default_autoescape is None: if callable(environment.autoescape): default_autoescape = environment.autoescape(None) else: default_autoescape = environment.autoescape self._default_autoescape = default_autoescape
28,043
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
Macro.__call__
(self, *args: t.Any, **kwargs: t.Any)
return self._invoke(arguments, autoescape)
689
763
def __call__(self, *args: t.Any, **kwargs: t.Any) -> str: # This requires a bit of explanation, In the past we used to # decide largely based on compile-time information if a macro is # safe or unsafe. While there was a volatile mode it was largely # unused for deciding on escaping. This turns out to be # problematic for macros because whether a macro is safe depends not # on the escape mode when it was defined, but rather when it was used. # # Because however we export macros from the module system and # there are historic callers that do not pass an eval context (and # will continue to not pass one), we need to perform an instance # check here. # # This is considered safe because an eval context is not a valid # argument to callables otherwise anyway. Worst case here is # that if no eval context is passed we fall back to the compile # time autoescape flag. if args and isinstance(args[0], EvalContext): autoescape = args[0].autoescape args = args[1:] else: autoescape = self._default_autoescape # try to consume the positional arguments arguments = list(args[: self._argument_count]) off = len(arguments) # For information why this is necessary refer to the handling # of caller in the `macro_body` handler in the compiler. found_caller = False # if the number of arguments consumed is not the number of # arguments expected we start filling in keyword arguments # and defaults. if off != self._argument_count: for name in self.arguments[len(arguments) :]: try: value = kwargs.pop(name) except KeyError: value = missing if name == "caller": found_caller = True arguments.append(value) else: found_caller = self.explicit_caller # it's important that the order of these arguments does not change # if not also changed in the compiler's `function_scoping` method. # the order is caller, keyword arguments, positional arguments! if self.caller and not found_caller: caller = kwargs.pop("caller", None) if caller is None: caller = self._environment.undefined("No caller defined", name="caller") arguments.append(caller) if self.catch_kwargs: arguments.append(kwargs) elif kwargs: if "caller" in kwargs: raise TypeError( f"macro {self.name!r} was invoked with two values for the special" " caller argument. This is most likely a bug." ) raise TypeError( f"macro {self.name!r} takes no keyword argument {next(iter(kwargs))!r}" ) if self.catch_varargs: arguments.append(args[self._argument_count :]) elif len(args) > self._argument_count: raise TypeError( f"macro {self.name!r} takes not more than" f" {len(self.arguments)} argument(s)" ) return self._invoke(arguments, autoescape)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L689-L763
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 57, 58, 59, 66, 67, 68, 73, 74 ]
82.666667
[ 56, 63, 69 ]
4
false
89.049919
75
15
96
0
def __call__(self, *args: t.Any, **kwargs: t.Any) -> str: # This requires a bit of explanation, In the past we used to # decide largely based on compile-time information if a macro is # safe or unsafe. While there was a volatile mode it was largely # unused for deciding on escaping. This turns out to be # problematic for macros because whether a macro is safe depends not # on the escape mode when it was defined, but rather when it was used. # # Because however we export macros from the module system and # there are historic callers that do not pass an eval context (and # will continue to not pass one), we need to perform an instance # check here. # # This is considered safe because an eval context is not a valid # argument to callables otherwise anyway. Worst case here is # that if no eval context is passed we fall back to the compile # time autoescape flag. if args and isinstance(args[0], EvalContext): autoescape = args[0].autoescape args = args[1:] else: autoescape = self._default_autoescape # try to consume the positional arguments arguments = list(args[: self._argument_count]) off = len(arguments) # For information why this is necessary refer to the handling # of caller in the `macro_body` handler in the compiler. found_caller = False # if the number of arguments consumed is not the number of # arguments expected we start filling in keyword arguments # and defaults. if off != self._argument_count: for name in self.arguments[len(arguments) :]: try: value = kwargs.pop(name) except KeyError: value = missing if name == "caller": found_caller = True arguments.append(value) else: found_caller = self.explicit_caller # it's important that the order of these arguments does not change # if not also changed in the compiler's `function_scoping` method. # the order is caller, keyword arguments, positional arguments! if self.caller and not found_caller: caller = kwargs.pop("caller", None) if caller is None: caller = self._environment.undefined("No caller defined", name="caller") arguments.append(caller) if self.catch_kwargs: arguments.append(kwargs) elif kwargs: if "caller" in kwargs: raise TypeError( f"macro {self.name!r} was invoked with two values for the special" " caller argument. This is most likely a bug." ) raise TypeError( f"macro {self.name!r} takes no keyword argument {next(iter(kwargs))!r}" ) if self.catch_varargs: arguments.append(args[self._argument_count :]) elif len(args) > self._argument_count: raise TypeError( f"macro {self.name!r} takes not more than" f" {len(self.arguments)} argument(s)" ) return self._invoke(arguments, autoescape)
28,044
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
Macro._async_invoke
(self, arguments: t.List[t.Any], autoescape: bool)
return rv
765
771
async def _async_invoke(self, arguments: t.List[t.Any], autoescape: bool) -> str: rv = await self._func(*arguments) # type: ignore if autoescape: return Markup(rv) return rv
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L765-L771
42
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
89.049919
7
2
100
0
async def _async_invoke(self, arguments: t.List[t.Any], autoescape: bool) -> str: rv = await self._func(*arguments) # type: ignore if autoescape: return Markup(rv) return rv
28,045
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
Macro._invoke
(self, arguments: t.List[t.Any], autoescape: bool)
return rv
773
782
def _invoke(self, arguments: t.List[t.Any], autoescape: bool) -> str: if self._environment.is_async: return self._async_invoke(arguments, autoescape) # type: ignore rv = self._func(*arguments) if autoescape: rv = Markup(rv) return rv
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L773-L782
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
100
[]
0
true
89.049919
10
3
100
0
def _invoke(self, arguments: t.List[t.Any], autoescape: bool) -> str: if self._environment.is_async: return self._async_invoke(arguments, autoescape) # type: ignore rv = self._func(*arguments) if autoescape: rv = Markup(rv) return rv
28,046
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
Macro.__repr__
(self)
return f"<{type(self).__name__} {name}>"
784
786
def __repr__(self) -> str: name = "anonymous" if self.name is None else repr(self.name) return f"<{type(self).__name__} {name}>"
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L784-L786
42
[ 0 ]
33.333333
[ 1, 2 ]
66.666667
false
89.049919
3
1
33.333333
0
def __repr__(self) -> str: name = "anonymous" if self.name is None else repr(self.name) return f"<{type(self).__name__} {name}>"
28,047
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
Undefined.__init__
( self, hint: t.Optional[str] = None, obj: t.Any = missing, name: t.Optional[str] = None, exc: t.Type[TemplateRuntimeError] = UndefinedError, )
811
821
def __init__( self, hint: t.Optional[str] = None, obj: t.Any = missing, name: t.Optional[str] = None, exc: t.Type[TemplateRuntimeError] = UndefinedError, ) -> None: self._undefined_hint = hint self._undefined_obj = obj self._undefined_name = name self._undefined_exception = exc
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L811-L821
42
[ 0, 7, 8, 9, 10 ]
45.454545
[]
0
false
89.049919
11
1
100
0
def __init__( self, hint: t.Optional[str] = None, obj: t.Any = missing, name: t.Optional[str] = None, exc: t.Type[TemplateRuntimeError] = UndefinedError, ) -> None: self._undefined_hint = hint self._undefined_obj = obj self._undefined_name = name self._undefined_exception = exc
28,048
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
Undefined._undefined_message
(self)
return ( f"{object_type_repr(self._undefined_obj)!r} has no" f" attribute {self._undefined_name!r}" )
Build a message about the undefined value based on how it was accessed.
Build a message about the undefined value based on how it was accessed.
824
843
def _undefined_message(self) -> str: """Build a message about the undefined value based on how it was accessed. """ if self._undefined_hint: return self._undefined_hint if self._undefined_obj is missing: return f"{self._undefined_name!r} is undefined" if not isinstance(self._undefined_name, str): return ( f"{object_type_repr(self._undefined_obj)} has no" f" element {self._undefined_name!r}" ) return ( f"{object_type_repr(self._undefined_obj)!r} has no" f" attribute {self._undefined_name!r}" )
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L824-L843
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ]
100
[]
0
true
89.049919
20
4
100
2
def _undefined_message(self) -> str: if self._undefined_hint: return self._undefined_hint if self._undefined_obj is missing: return f"{self._undefined_name!r} is undefined" if not isinstance(self._undefined_name, str): return ( f"{object_type_repr(self._undefined_obj)} has no" f" element {self._undefined_name!r}" ) return ( f"{object_type_repr(self._undefined_obj)!r} has no" f" attribute {self._undefined_name!r}" )
28,049
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
Undefined._fail_with_undefined_error
( self, *args: t.Any, **kwargs: t.Any )
Raise an :exc:`UndefinedError` when operations are performed on the undefined value.
Raise an :exc:`UndefinedError` when operations are performed on the undefined value.
846
852
def _fail_with_undefined_error( self, *args: t.Any, **kwargs: t.Any ) -> "te.NoReturn": """Raise an :exc:`UndefinedError` when operations are performed on the undefined value. """ raise self._undefined_exception(self._undefined_message)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L846-L852
42
[ 0, 5, 6 ]
42.857143
[]
0
false
89.049919
7
1
100
2
def _fail_with_undefined_error( self, *args: t.Any, **kwargs: t.Any ) -> "te.NoReturn": raise self._undefined_exception(self._undefined_message)
28,050
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
Undefined.__getattr__
(self, name: str)
return self._fail_with_undefined_error()
855
859
def __getattr__(self, name: str) -> t.Any: if name[:2] == "__": raise AttributeError(name) return self._fail_with_undefined_error()
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L855-L859
42
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
89.049919
5
2
100
0
def __getattr__(self, name: str) -> t.Any: if name[:2] == "__": raise AttributeError(name) return self._fail_with_undefined_error()
28,051
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
Undefined.__eq__
(self, other: t.Any)
return type(self) is type(other)
872
873
def __eq__(self, other: t.Any) -> bool: return type(self) is type(other)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L872-L873
42
[ 0, 1 ]
100
[]
0
true
89.049919
2
1
100
0
def __eq__(self, other: t.Any) -> bool: return type(self) is type(other)
28,052
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
Undefined.__ne__
(self, other: t.Any)
return not self.__eq__(other)
875
876
def __ne__(self, other: t.Any) -> bool: return not self.__eq__(other)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L875-L876
42
[ 0, 1 ]
100
[]
0
true
89.049919
2
1
100
0
def __ne__(self, other: t.Any) -> bool: return not self.__eq__(other)
28,053
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
Undefined.__hash__
(self)
return id(type(self))
878
879
def __hash__(self) -> int: return id(type(self))
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L878-L879
42
[ 0, 1 ]
100
[]
0
true
89.049919
2
1
100
0
def __hash__(self) -> int: return id(type(self))
28,054
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
Undefined.__str__
(self)
return ""
881
882
def __str__(self) -> str: return ""
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L881-L882
42
[ 0, 1 ]
100
[]
0
true
89.049919
2
1
100
0
def __str__(self) -> str: return ""
28,055
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
Undefined.__len__
(self)
return 0
884
885
def __len__(self) -> int: return 0
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L884-L885
42
[ 0, 1 ]
100
[]
0
true
89.049919
2
1
100
0
def __len__(self) -> int: return 0
28,056
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
Undefined.__iter__
(self)
887
888
def __iter__(self) -> t.Iterator[t.Any]: yield from ()
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L887-L888
42
[ 0, 1 ]
100
[]
0
true
89.049919
2
1
100
0
def __iter__(self) -> t.Iterator[t.Any]: yield from ()
28,057
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
Undefined.__aiter__
(self)
890
892
async def __aiter__(self) -> t.AsyncIterator[t.Any]: for _ in (): yield
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L890-L892
42
[ 0, 1 ]
66.666667
[ 2 ]
33.333333
false
89.049919
3
2
66.666667
0
async def __aiter__(self) -> t.AsyncIterator[t.Any]: for _ in (): yield
28,058
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
Undefined.__bool__
(self)
return False
894
895
def __bool__(self) -> bool: return False
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L894-L895
42
[ 0, 1 ]
100
[]
0
true
89.049919
2
1
100
0
def __bool__(self) -> bool: return False
28,059
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/runtime.py
Undefined.__repr__
(self)
return "Undefined"
897
898
def __repr__(self) -> str: return "Undefined"
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/runtime.py#L897-L898
42
[ 0 ]
50
[ 1 ]
50
false
89.049919
2
1
50
0
def __repr__(self) -> str: return "Undefined"
28,060