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/lexer.py
TokenStream.skip_if
(self, expr: str)
return self.next_if(expr) is not None
Like :meth:`next_if` but only returns `True` or `False`.
Like :meth:`next_if` but only returns `True` or `False`.
374
376
def skip_if(self, expr: str) -> bool: """Like :meth:`next_if` but only returns `True` or `False`.""" return self.next_if(expr) is not None
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/lexer.py#L374-L376
42
[ 0, 1, 2 ]
100
[]
0
true
93.501048
3
1
100
1
def skip_if(self, expr: str) -> bool: return self.next_if(expr) is not None
27,761
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/lexer.py
TokenStream.__next__
(self)
return rv
Go one token ahead and return the old one. Use the built-in :func:`next` instead of calling this directly.
Go one token ahead and return the old one.
378
393
def __next__(self) -> Token: """Go one token ahead and return the old one. Use the built-in :func:`next` instead of calling this directly. """ rv = self.current if self._pushed: self.current = self._pushed.popleft() elif self.current.type is not TOKEN_EOF: try: self.current = next(self._iter) except StopIteration: self.close() return rv
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/lexer.py#L378-L393
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ]
100
[]
0
true
93.501048
16
4
100
3
def __next__(self) -> Token: rv = self.current if self._pushed: self.current = self._pushed.popleft() elif self.current.type is not TOKEN_EOF: try: self.current = next(self._iter) except StopIteration: self.close() return rv
27,762
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/lexer.py
TokenStream.close
(self)
Close the stream.
Close the stream.
395
399
def close(self) -> None: """Close the stream.""" self.current = Token(self.current.lineno, TOKEN_EOF, "") self._iter = iter(()) self.closed = True
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/lexer.py#L395-L399
42
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
93.501048
5
1
100
1
def close(self) -> None: self.current = Token(self.current.lineno, TOKEN_EOF, "") self._iter = iter(()) self.closed = True
27,763
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/lexer.py
TokenStream.expect
(self, expr: str)
return next(self)
Expect a given token type and return it. This accepts the same argument as :meth:`jinja2.lexer.Token.test`.
Expect a given token type and return it. This accepts the same argument as :meth:`jinja2.lexer.Token.test`.
401
423
def expect(self, expr: str) -> Token: """Expect a given token type and return it. This accepts the same argument as :meth:`jinja2.lexer.Token.test`. """ if not self.current.test(expr): expr = describe_token_expr(expr) if self.current.type is TOKEN_EOF: raise TemplateSyntaxError( f"unexpected end of template, expected {expr!r}.", self.current.lineno, self.name, self.filename, ) raise TemplateSyntaxError( f"expected token {expr!r}, got {describe_token(self.current)!r}", self.current.lineno, self.name, self.filename, ) return next(self)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/lexer.py#L401-L423
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 14, 15, 16, 17, 18, 19, 20, 21, 22 ]
73.913043
[ 8 ]
4.347826
false
93.501048
23
3
95.652174
2
def expect(self, expr: str) -> Token: if not self.current.test(expr): expr = describe_token_expr(expr) if self.current.type is TOKEN_EOF: raise TemplateSyntaxError( f"unexpected end of template, expected {expr!r}.", self.current.lineno, self.name, self.filename, ) raise TemplateSyntaxError( f"expected token {expr!r}, got {describe_token(self.current)!r}", self.current.lineno, self.name, self.filename, ) return next(self)
27,764
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/lexer.py
OptionalLStrip.__new__
(cls, *members, **kwargs)
return super().__new__(cls, members)
459
460
def __new__(cls, *members, **kwargs): # type: ignore return super().__new__(cls, members)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/lexer.py#L459-L460
42
[ 0, 1 ]
100
[]
0
true
93.501048
2
1
100
0
def __new__(cls, *members, **kwargs): # type: ignore return super().__new__(cls, members)
27,765
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/lexer.py
Lexer.__init__
(self, environment: "Environment")
477
594
def __init__(self, environment: "Environment") -> None: # shortcuts e = re.escape def c(x: str) -> t.Pattern[str]: return re.compile(x, re.M | re.S) # lexing rules for tags tag_rules: t.List[_Rule] = [ _Rule(whitespace_re, TOKEN_WHITESPACE, None), _Rule(float_re, TOKEN_FLOAT, None), _Rule(integer_re, TOKEN_INTEGER, None), _Rule(name_re, TOKEN_NAME, None), _Rule(string_re, TOKEN_STRING, None), _Rule(operator_re, TOKEN_OPERATOR, None), ] # assemble the root lexing rule. because "|" is ungreedy # we have to sort by length so that the lexer continues working # as expected when we have parsing rules like <% for block and # <%= for variables. (if someone wants asp like syntax) # variables are just part of the rules if variable processing # is required. root_tag_rules = compile_rules(environment) block_start_re = e(environment.block_start_string) block_end_re = e(environment.block_end_string) comment_end_re = e(environment.comment_end_string) variable_end_re = e(environment.variable_end_string) # block suffix if trimming is enabled block_suffix_re = "\\n?" if environment.trim_blocks else "" self.lstrip_blocks = environment.lstrip_blocks self.newline_sequence = environment.newline_sequence self.keep_trailing_newline = environment.keep_trailing_newline root_raw_re = ( rf"(?P<raw_begin>{block_start_re}(\-|\+|)\s*raw\s*" rf"(?:\-{block_end_re}\s*|{block_end_re}))" ) root_parts_re = "|".join( [root_raw_re] + [rf"(?P<{n}>{r}(\-|\+|))" for n, r in root_tag_rules] ) # global lexing rules self.rules: t.Dict[str, t.List[_Rule]] = { "root": [ # directives _Rule( c(rf"(.*?)(?:{root_parts_re})"), OptionalLStrip(TOKEN_DATA, "#bygroup"), # type: ignore "#bygroup", ), # data _Rule(c(".+"), TOKEN_DATA, None), ], # comments TOKEN_COMMENT_BEGIN: [ _Rule( c( rf"(.*?)((?:\+{comment_end_re}|\-{comment_end_re}\s*" rf"|{comment_end_re}{block_suffix_re}))" ), (TOKEN_COMMENT, TOKEN_COMMENT_END), "#pop", ), _Rule(c(r"(.)"), (Failure("Missing end of comment tag"),), None), ], # blocks TOKEN_BLOCK_BEGIN: [ _Rule( c( rf"(?:\+{block_end_re}|\-{block_end_re}\s*" rf"|{block_end_re}{block_suffix_re})" ), TOKEN_BLOCK_END, "#pop", ), ] + tag_rules, # variables TOKEN_VARIABLE_BEGIN: [ _Rule( c(rf"\-{variable_end_re}\s*|{variable_end_re}"), TOKEN_VARIABLE_END, "#pop", ) ] + tag_rules, # raw block TOKEN_RAW_BEGIN: [ _Rule( c( rf"(.*?)((?:{block_start_re}(\-|\+|))\s*endraw\s*" rf"(?:\+{block_end_re}|\-{block_end_re}\s*" rf"|{block_end_re}{block_suffix_re}))" ), OptionalLStrip(TOKEN_DATA, TOKEN_RAW_END), # type: ignore "#pop", ), _Rule(c(r"(.)"), (Failure("Missing end of raw directive"),), None), ], # line statements TOKEN_LINESTATEMENT_BEGIN: [ _Rule(c(r"\s*(\n|$)"), TOKEN_LINESTATEMENT_END, "#pop") ] + tag_rules, # line comments TOKEN_LINECOMMENT_BEGIN: [ _Rule( c(r"(.*?)()(?=\n|$)"), (TOKEN_LINECOMMENT, TOKEN_LINECOMMENT_END), "#pop", ) ], }
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/lexer.py#L477-L594
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 42, 46, 47 ]
24.576271
[]
0
false
93.501048
118
3
100
0
def __init__(self, environment: "Environment") -> None: # shortcuts e = re.escape def c(x: str) -> t.Pattern[str]: return re.compile(x, re.M | re.S) # lexing rules for tags tag_rules: t.List[_Rule] = [ _Rule(whitespace_re, TOKEN_WHITESPACE, None), _Rule(float_re, TOKEN_FLOAT, None), _Rule(integer_re, TOKEN_INTEGER, None), _Rule(name_re, TOKEN_NAME, None), _Rule(string_re, TOKEN_STRING, None), _Rule(operator_re, TOKEN_OPERATOR, None), ] # assemble the root lexing rule. because "|" is ungreedy # we have to sort by length so that the lexer continues working # as expected when we have parsing rules like <% for block and # <%= for variables. (if someone wants asp like syntax) # variables are just part of the rules if variable processing # is required. root_tag_rules = compile_rules(environment) block_start_re = e(environment.block_start_string) block_end_re = e(environment.block_end_string) comment_end_re = e(environment.comment_end_string) variable_end_re = e(environment.variable_end_string) # block suffix if trimming is enabled block_suffix_re = "\\n?" if environment.trim_blocks else "" self.lstrip_blocks = environment.lstrip_blocks self.newline_sequence = environment.newline_sequence self.keep_trailing_newline = environment.keep_trailing_newline root_raw_re = ( rf"(?P<raw_begin>{block_start_re}(\-|\+|)\s*raw\s*" rf"(?:\-{block_end_re}\s*|{block_end_re}))" ) root_parts_re = "|".join( [root_raw_re] + [rf"(?P<{n}>{r}(\-|\+|))" for n, r in root_tag_rules] ) # global lexing rules self.rules: t.Dict[str, t.List[_Rule]] = { "root": [ # directives _Rule( c(rf"(.*?)(?:{root_parts_re})"), OptionalLStrip(TOKEN_DATA, "#bygroup"), # type: ignore "#bygroup", ), # data _Rule(c(".+"), TOKEN_DATA, None), ], # comments TOKEN_COMMENT_BEGIN: [ _Rule( c( rf"(.*?)((?:\+{comment_end_re}|\-{comment_end_re}\s*" rf"|{comment_end_re}{block_suffix_re}))" ), (TOKEN_COMMENT, TOKEN_COMMENT_END), "#pop", ), _Rule(c(r"(.)"), (Failure("Missing end of comment tag"),), None), ], # blocks TOKEN_BLOCK_BEGIN: [ _Rule( c( rf"(?:\+{block_end_re}|\-{block_end_re}\s*" rf"|{block_end_re}{block_suffix_re})" ), TOKEN_BLOCK_END, "#pop", ), ] + tag_rules, # variables TOKEN_VARIABLE_BEGIN: [ _Rule( c(rf"\-{variable_end_re}\s*|{variable_end_re}"), TOKEN_VARIABLE_END, "#pop", ) ] + tag_rules, # raw block TOKEN_RAW_BEGIN: [ _Rule( c( rf"(.*?)((?:{block_start_re}(\-|\+|))\s*endraw\s*" rf"(?:\+{block_end_re}|\-{block_end_re}\s*" rf"|{block_end_re}{block_suffix_re}))" ), OptionalLStrip(TOKEN_DATA, TOKEN_RAW_END), # type: ignore "#pop", ), _Rule(c(r"(.)"), (Failure("Missing end of raw directive"),), None), ], # line statements TOKEN_LINESTATEMENT_BEGIN: [ _Rule(c(r"\s*(\n|$)"), TOKEN_LINESTATEMENT_END, "#pop") ] + tag_rules, # line comments TOKEN_LINECOMMENT_BEGIN: [ _Rule( c(r"(.*?)()(?=\n|$)"), (TOKEN_LINECOMMENT, TOKEN_LINECOMMENT_END), "#pop", ) ], }
27,766
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/lexer.py
Lexer._normalize_newlines
(self, value: str)
return newline_re.sub(self.newline_sequence, value)
Replace all newlines with the configured sequence in strings and template data.
Replace all newlines with the configured sequence in strings and template data.
596
600
def _normalize_newlines(self, value: str) -> str: """Replace all newlines with the configured sequence in strings and template data. """ return newline_re.sub(self.newline_sequence, value)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/lexer.py#L596-L600
42
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
93.501048
5
1
100
2
def _normalize_newlines(self, value: str) -> str: return newline_re.sub(self.newline_sequence, value)
27,767
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/lexer.py
Lexer.tokenize
( self, source: str, name: t.Optional[str] = None, filename: t.Optional[str] = None, state: t.Optional[str] = None, )
return TokenStream(self.wrap(stream, name, filename), name, filename)
Calls tokeniter + tokenize and wraps it in a token stream.
Calls tokeniter + tokenize and wraps it in a token stream.
602
611
def tokenize( self, source: str, name: t.Optional[str] = None, filename: t.Optional[str] = None, state: t.Optional[str] = None, ) -> TokenStream: """Calls tokeniter + tokenize and wraps it in a token stream.""" stream = self.tokeniter(source, name, filename, state) return TokenStream(self.wrap(stream, name, filename), name, filename)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/lexer.py#L602-L611
42
[ 0, 7, 8, 9 ]
40
[]
0
false
93.501048
10
1
100
1
def tokenize( self, source: str, name: t.Optional[str] = None, filename: t.Optional[str] = None, state: t.Optional[str] = None, ) -> TokenStream: stream = self.tokeniter(source, name, filename, state) return TokenStream(self.wrap(stream, name, filename), name, filename)
27,768
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/lexer.py
Lexer.wrap
( self, stream: t.Iterable[t.Tuple[int, str, str]], name: t.Optional[str] = None, filename: t.Optional[str] = None, )
This is called with the stream as returned by `tokenize` and wraps every token in a :class:`Token` and converts the value.
This is called with the stream as returned by `tokenize` and wraps every token in a :class:`Token` and converts the value.
613
665
def wrap( self, stream: t.Iterable[t.Tuple[int, str, str]], name: t.Optional[str] = None, filename: t.Optional[str] = None, ) -> t.Iterator[Token]: """This is called with the stream as returned by `tokenize` and wraps every token in a :class:`Token` and converts the value. """ for lineno, token, value_str in stream: if token in ignored_tokens: continue value: t.Any = value_str if token == TOKEN_LINESTATEMENT_BEGIN: token = TOKEN_BLOCK_BEGIN elif token == TOKEN_LINESTATEMENT_END: token = TOKEN_BLOCK_END # we are not interested in those tokens in the parser elif token in (TOKEN_RAW_BEGIN, TOKEN_RAW_END): continue elif token == TOKEN_DATA: value = self._normalize_newlines(value_str) elif token == "keyword": token = value_str elif token == TOKEN_NAME: value = value_str if not value.isidentifier(): raise TemplateSyntaxError( "Invalid character in identifier", lineno, name, filename ) elif token == TOKEN_STRING: # try to unescape string try: value = ( self._normalize_newlines(value_str[1:-1]) .encode("ascii", "backslashreplace") .decode("unicode-escape") ) except Exception as e: msg = str(e).split(":")[-1].strip() raise TemplateSyntaxError(msg, lineno, name, filename) from e elif token == TOKEN_INTEGER: value = int(value_str.replace("_", ""), 0) elif token == TOKEN_FLOAT: # remove all "_" first to support more Python versions value = literal_eval(value_str.replace("_", "")) elif token == TOKEN_OPERATOR: token = operators[value_str] yield Token(lineno, token, value)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/lexer.py#L613-L665
42
[ 0, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 44, 45, 46, 47, 48, 49, 50, 51, 52 ]
79.245283
[ 25, 41, 42, 43 ]
7.54717
false
93.501048
53
15
92.45283
2
def wrap( self, stream: t.Iterable[t.Tuple[int, str, str]], name: t.Optional[str] = None, filename: t.Optional[str] = None, ) -> t.Iterator[Token]: for lineno, token, value_str in stream: if token in ignored_tokens: continue value: t.Any = value_str if token == TOKEN_LINESTATEMENT_BEGIN: token = TOKEN_BLOCK_BEGIN elif token == TOKEN_LINESTATEMENT_END: token = TOKEN_BLOCK_END # we are not interested in those tokens in the parser elif token in (TOKEN_RAW_BEGIN, TOKEN_RAW_END): continue elif token == TOKEN_DATA: value = self._normalize_newlines(value_str) elif token == "keyword": token = value_str elif token == TOKEN_NAME: value = value_str if not value.isidentifier(): raise TemplateSyntaxError( "Invalid character in identifier", lineno, name, filename ) elif token == TOKEN_STRING: # try to unescape string try: value = ( self._normalize_newlines(value_str[1:-1]) .encode("ascii", "backslashreplace") .decode("unicode-escape") ) except Exception as e: msg = str(e).split(":")[-1].strip() raise TemplateSyntaxError(msg, lineno, name, filename) from e elif token == TOKEN_INTEGER: value = int(value_str.replace("_", ""), 0) elif token == TOKEN_FLOAT: # remove all "_" first to support more Python versions value = literal_eval(value_str.replace("_", "")) elif token == TOKEN_OPERATOR: token = operators[value_str] yield Token(lineno, token, value)
27,769
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/lexer.py
Lexer.tokeniter
( self, source: str, name: t.Optional[str], filename: t.Optional[str] = None, state: t.Optional[str] = None, )
This method tokenizes the text and returns the tokens in a generator. Use this method if you just want to tokenize a template. .. versionchanged:: 3.0 Only ``\\n``, ``\\r\\n`` and ``\\r`` are treated as line breaks.
This method tokenizes the text and returns the tokens in a generator. Use this method if you just want to tokenize a template.
667
866
def tokeniter( self, source: str, name: t.Optional[str], filename: t.Optional[str] = None, state: t.Optional[str] = None, ) -> t.Iterator[t.Tuple[int, str, str]]: """This method tokenizes the text and returns the tokens in a generator. Use this method if you just want to tokenize a template. .. versionchanged:: 3.0 Only ``\\n``, ``\\r\\n`` and ``\\r`` are treated as line breaks. """ lines = newline_re.split(source)[::2] if not self.keep_trailing_newline and lines[-1] == "": del lines[-1] source = "\n".join(lines) pos = 0 lineno = 1 stack = ["root"] if state is not None and state != "root": assert state in ("variable", "block"), "invalid state" stack.append(state + "_begin") statetokens = self.rules[stack[-1]] source_length = len(source) balancing_stack: t.List[str] = [] newlines_stripped = 0 line_starting = True while True: # tokenizer loop for regex, tokens, new_state in statetokens: m = regex.match(source, pos) # if no match we try again with the next rule if m is None: continue # we only match blocks and variables if braces / parentheses # are balanced. continue parsing with the lower rule which # is the operator rule. do this only if the end tags look # like operators if balancing_stack and tokens in ( TOKEN_VARIABLE_END, TOKEN_BLOCK_END, TOKEN_LINESTATEMENT_END, ): continue # tuples support more options if isinstance(tokens, tuple): groups: t.Sequence[str] = m.groups() if isinstance(tokens, OptionalLStrip): # Rule supports lstrip. Match will look like # text, block type, whitespace control, type, control, ... text = groups[0] # Skipping the text and first type, every other group is the # whitespace control for each type. One of the groups will be # -, +, or empty string instead of None. strip_sign = next(g for g in groups[2::2] if g is not None) if strip_sign == "-": # Strip all whitespace between the text and the tag. stripped = text.rstrip() newlines_stripped = text[len(stripped) :].count("\n") groups = [stripped, *groups[1:]] elif ( # Not marked for preserving whitespace. strip_sign != "+" # lstrip is enabled. and self.lstrip_blocks # Not a variable expression. and not m.groupdict().get(TOKEN_VARIABLE_BEGIN) ): # The start of text between the last newline and the tag. l_pos = text.rfind("\n") + 1 if l_pos > 0 or line_starting: # If there's only whitespace between the newline and the # tag, strip it. if whitespace_re.fullmatch(text, l_pos): groups = [text[:l_pos], *groups[1:]] for idx, token in enumerate(tokens): # failure group if token.__class__ is Failure: raise token(lineno, filename) # bygroup is a bit more complex, in that case we # yield for the current token the first named # group that matched elif token == "#bygroup": for key, value in m.groupdict().items(): if value is not None: yield lineno, key, value lineno += value.count("\n") break else: raise RuntimeError( f"{regex!r} wanted to resolve the token dynamically" " but no group matched" ) # normal group else: data = groups[idx] if data or token not in ignore_if_empty: yield lineno, token, data lineno += data.count("\n") + newlines_stripped newlines_stripped = 0 # strings as token just are yielded as it. else: data = m.group() # update brace/parentheses balance if tokens == TOKEN_OPERATOR: if data == "{": balancing_stack.append("}") elif data == "(": balancing_stack.append(")") elif data == "[": balancing_stack.append("]") elif data in ("}", ")", "]"): if not balancing_stack: raise TemplateSyntaxError( f"unexpected '{data}'", lineno, name, filename ) expected_op = balancing_stack.pop() if expected_op != data: raise TemplateSyntaxError( f"unexpected '{data}', expected '{expected_op}'", lineno, name, filename, ) # yield items if data or tokens not in ignore_if_empty: yield lineno, tokens, data lineno += data.count("\n") line_starting = m.group()[-1:] == "\n" # fetch new position into new variable so that we can check # if there is a internal parsing error which would result # in an infinite loop pos2 = m.end() # handle state changes if new_state is not None: # remove the uppermost state if new_state == "#pop": stack.pop() # resolve the new state by group checking elif new_state == "#bygroup": for key, value in m.groupdict().items(): if value is not None: stack.append(key) break else: raise RuntimeError( f"{regex!r} wanted to resolve the new state dynamically" f" but no group matched" ) # direct state name given else: stack.append(new_state) statetokens = self.rules[stack[-1]] # we are still at the same position and no stack change. # this means a loop without break condition, avoid that and # raise error elif pos2 == pos: raise RuntimeError( f"{regex!r} yielded empty string without stack change" ) # publish new function and start again pos = pos2 break # if loop terminated without break we haven't found a single match # either we are at the end of the file or we have a problem else: # end of text if pos >= source_length: return # something went wrong raise TemplateSyntaxError( f"unexpected char {source[pos]!r} at {pos}", lineno, name, filename )
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/lexer.py#L667-L866
42
[ 0, 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, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 95, 96, 97, 98, 99, 100, 101, 102, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 134, 135, 136, 137, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 176, 177, 178, 179, 180, 181, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199 ]
79.5
[ 92, 103, 131, 138, 169, 175, 182 ]
3.5
false
93.501048
200
43
96.5
6
def tokeniter( self, source: str, name: t.Optional[str], filename: t.Optional[str] = None, state: t.Optional[str] = None, ) -> t.Iterator[t.Tuple[int, str, str]]: lines = newline_re.split(source)[::2] if not self.keep_trailing_newline and lines[-1] == "": del lines[-1] source = "\n".join(lines) pos = 0 lineno = 1 stack = ["root"] if state is not None and state != "root": assert state in ("variable", "block"), "invalid state" stack.append(state + "_begin") statetokens = self.rules[stack[-1]] source_length = len(source) balancing_stack: t.List[str] = [] newlines_stripped = 0 line_starting = True while True: # tokenizer loop for regex, tokens, new_state in statetokens: m = regex.match(source, pos) # if no match we try again with the next rule if m is None: continue # we only match blocks and variables if braces / parentheses # are balanced. continue parsing with the lower rule which # is the operator rule. do this only if the end tags look # like operators if balancing_stack and tokens in ( TOKEN_VARIABLE_END, TOKEN_BLOCK_END, TOKEN_LINESTATEMENT_END, ): continue # tuples support more options if isinstance(tokens, tuple): groups: t.Sequence[str] = m.groups() if isinstance(tokens, OptionalLStrip): # Rule supports lstrip. Match will look like # text, block type, whitespace control, type, control, ... text = groups[0] # Skipping the text and first type, every other group is the # whitespace control for each type. One of the groups will be # -, +, or empty string instead of None. strip_sign = next(g for g in groups[2::2] if g is not None) if strip_sign == "-": # Strip all whitespace between the text and the tag. stripped = text.rstrip() newlines_stripped = text[len(stripped) :].count("\n") groups = [stripped, *groups[1:]] elif ( # Not marked for preserving whitespace. strip_sign != "+" # lstrip is enabled. and self.lstrip_blocks # Not a variable expression. and not m.groupdict().get(TOKEN_VARIABLE_BEGIN) ): # The start of text between the last newline and the tag. l_pos = text.rfind("\n") + 1 if l_pos > 0 or line_starting: # If there's only whitespace between the newline and the # tag, strip it. if whitespace_re.fullmatch(text, l_pos): groups = [text[:l_pos], *groups[1:]] for idx, token in enumerate(tokens): # failure group if token.__class__ is Failure: raise token(lineno, filename) # bygroup is a bit more complex, in that case we # yield for the current token the first named # group that matched elif token == "#bygroup": for key, value in m.groupdict().items(): if value is not None: yield lineno, key, value lineno += value.count("\n") break else: raise RuntimeError( f"{regex!r} wanted to resolve the token dynamically" " but no group matched" ) # normal group else: data = groups[idx] if data or token not in ignore_if_empty: yield lineno, token, data lineno += data.count("\n") + newlines_stripped newlines_stripped = 0 # strings as token just are yielded as it. else: data = m.group() # update brace/parentheses balance if tokens == TOKEN_OPERATOR: if data == "{": balancing_stack.append("}") elif data == "(": balancing_stack.append(")") elif data == "[": balancing_stack.append("]") elif data in ("}", ")", "]"): if not balancing_stack: raise TemplateSyntaxError( f"unexpected '{data}'", lineno, name, filename ) expected_op = balancing_stack.pop() if expected_op != data: raise TemplateSyntaxError( f"unexpected '{data}', expected '{expected_op}'", lineno, name, filename, ) # yield items if data or tokens not in ignore_if_empty: yield lineno, tokens, data lineno += data.count("\n") line_starting = m.group()[-1:] == "\n" # fetch new position into new variable so that we can check # if there is a internal parsing error which would result # in an infinite loop pos2 = m.end() # handle state changes if new_state is not None: # remove the uppermost state if new_state == "#pop": stack.pop() # resolve the new state by group checking elif new_state == "#bygroup": for key, value in m.groupdict().items(): if value is not None: stack.append(key) break else: raise RuntimeError( f"{regex!r} wanted to resolve the new state dynamically" f" but no group matched" ) # direct state name given else: stack.append(new_state) statetokens = self.rules[stack[-1]] # we are still at the same position and no stack change. # this means a loop without break condition, avoid that and # raise error elif pos2 == pos: raise RuntimeError( f"{regex!r} yielded empty string without stack change" ) # publish new function and start again pos = pos2 break # if loop terminated without break we haven't found a single match # either we are at the end of the file or we have a problem else: # end of text if pos >= source_length: return # something went wrong raise TemplateSyntaxError( f"unexpected char {source[pos]!r} at {pos}", lineno, name, filename )
27,770
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.__init__
( self, environment: "Environment", source: str, name: t.Optional[str] = None, filename: t.Optional[str] = None, state: t.Optional[str] = None, )
51
72
def __init__( self, environment: "Environment", source: str, name: t.Optional[str] = None, filename: t.Optional[str] = None, state: t.Optional[str] = None, ) -> None: self.environment = environment self.stream = environment._tokenize(source, name, filename, state) self.name = name self.filename = filename self.closed = False self.extensions: t.Dict[ str, t.Callable[["Parser"], t.Union[nodes.Node, t.List[nodes.Node]]] ] = {} for extension in environment.iter_extensions(): for tag in extension.tags: self.extensions[tag] = extension.parse self._last_identifier = 0 self._tag_stack: t.List[str] = [] self._end_token_stack: t.List[t.Tuple[str, ...]] = []
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L51-L72
42
[ 0, 8, 9, 10, 11, 12, 13, 16, 17, 18, 19, 20, 21 ]
59.090909
[]
0
false
95.881732
22
3
100
0
def __init__( self, environment: "Environment", source: str, name: t.Optional[str] = None, filename: t.Optional[str] = None, state: t.Optional[str] = None, ) -> None: self.environment = environment self.stream = environment._tokenize(source, name, filename, state) self.name = name self.filename = filename self.closed = False self.extensions: t.Dict[ str, t.Callable[["Parser"], t.Union[nodes.Node, t.List[nodes.Node]]] ] = {} for extension in environment.iter_extensions(): for tag in extension.tags: self.extensions[tag] = extension.parse self._last_identifier = 0 self._tag_stack: t.List[str] = [] self._end_token_stack: t.List[t.Tuple[str, ...]] = []
27,771
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.fail
( self, msg: str, lineno: t.Optional[int] = None, exc: t.Type[TemplateSyntaxError] = TemplateSyntaxError, )
Convenience method that raises `exc` with the message, passed line number or last line number as well as the current name and filename.
Convenience method that raises `exc` with the message, passed line number or last line number as well as the current name and filename.
74
86
def fail( self, msg: str, lineno: t.Optional[int] = None, exc: t.Type[TemplateSyntaxError] = TemplateSyntaxError, ) -> "te.NoReturn": """Convenience method that raises `exc` with the message, passed line number or last line number as well as the current name and filename. """ if lineno is None: lineno = self.stream.current.lineno raise exc(msg, lineno, self.name, self.filename)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L74-L86
42
[ 0, 9, 10, 11, 12 ]
38.461538
[]
0
false
95.881732
13
2
100
3
def fail( self, msg: str, lineno: t.Optional[int] = None, exc: t.Type[TemplateSyntaxError] = TemplateSyntaxError, ) -> "te.NoReturn": if lineno is None: lineno = self.stream.current.lineno raise exc(msg, lineno, self.name, self.filename)
27,772
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser._fail_ut_eof
( self, name: t.Optional[str], end_token_stack: t.List[t.Tuple[str, ...]], lineno: t.Optional[int], )
88
126
def _fail_ut_eof( self, name: t.Optional[str], end_token_stack: t.List[t.Tuple[str, ...]], lineno: t.Optional[int], ) -> "te.NoReturn": expected: t.Set[str] = set() for exprs in end_token_stack: expected.update(map(describe_token_expr, exprs)) if end_token_stack: currently_looking: t.Optional[str] = " or ".join( map(repr, map(describe_token_expr, end_token_stack[-1])) ) else: currently_looking = None if name is None: message = ["Unexpected end of template."] else: message = [f"Encountered unknown tag {name!r}."] if currently_looking: if name is not None and name in expected: message.append( "You probably made a nesting mistake. Jinja is expecting this tag," f" but currently looking for {currently_looking}." ) else: message.append( f"Jinja was looking for the following tags: {currently_looking}." ) if self._tag_stack: message.append( "The innermost block that needs to be closed is" f" {self._tag_stack[-1]!r}." ) self.fail(" ".join(message), lineno)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L88-L126
42
[ 0, 6, 7, 8, 9, 10, 14, 15, 16, 17, 19, 20, 21, 22, 28, 31, 32, 33, 37, 38 ]
51.282051
[ 23 ]
2.564103
false
95.881732
39
8
97.435897
0
def _fail_ut_eof( self, name: t.Optional[str], end_token_stack: t.List[t.Tuple[str, ...]], lineno: t.Optional[int], ) -> "te.NoReturn": expected: t.Set[str] = set() for exprs in end_token_stack: expected.update(map(describe_token_expr, exprs)) if end_token_stack: currently_looking: t.Optional[str] = " or ".join( map(repr, map(describe_token_expr, end_token_stack[-1])) ) else: currently_looking = None if name is None: message = ["Unexpected end of template."] else: message = [f"Encountered unknown tag {name!r}."] if currently_looking: if name is not None and name in expected: message.append( "You probably made a nesting mistake. Jinja is expecting this tag," f" but currently looking for {currently_looking}." ) else: message.append( f"Jinja was looking for the following tags: {currently_looking}." ) if self._tag_stack: message.append( "The innermost block that needs to be closed is" f" {self._tag_stack[-1]!r}." ) self.fail(" ".join(message), lineno)
27,773
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.fail_unknown_tag
( self, name: str, lineno: t.Optional[int] = None )
Called if the parser encounters an unknown tag. Tries to fail with a human readable error message that could help to identify the problem.
Called if the parser encounters an unknown tag. Tries to fail with a human readable error message that could help to identify the problem.
128
135
def fail_unknown_tag( self, name: str, lineno: t.Optional[int] = None ) -> "te.NoReturn": """Called if the parser encounters an unknown tag. Tries to fail with a human readable error message that could help to identify the problem. """ self._fail_ut_eof(name, self._end_token_stack, lineno)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L128-L135
42
[ 0, 6, 7 ]
37.5
[]
0
false
95.881732
8
1
100
3
def fail_unknown_tag( self, name: str, lineno: t.Optional[int] = None ) -> "te.NoReturn": self._fail_ut_eof(name, self._end_token_stack, lineno)
27,774
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.fail_eof
( self, end_tokens: t.Optional[t.Tuple[str, ...]] = None, lineno: t.Optional[int] = None, )
Like fail_unknown_tag but for end of template situations.
Like fail_unknown_tag but for end of template situations.
137
146
def fail_eof( self, end_tokens: t.Optional[t.Tuple[str, ...]] = None, lineno: t.Optional[int] = None, ) -> "te.NoReturn": """Like fail_unknown_tag but for end of template situations.""" stack = list(self._end_token_stack) if end_tokens is not None: stack.append(end_tokens) self._fail_ut_eof(None, stack, lineno)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L137-L146
42
[ 0, 5, 6, 7, 8, 9 ]
60
[]
0
false
95.881732
10
2
100
1
def fail_eof( self, end_tokens: t.Optional[t.Tuple[str, ...]] = None, lineno: t.Optional[int] = None, ) -> "te.NoReturn": stack = list(self._end_token_stack) if end_tokens is not None: stack.append(end_tokens) self._fail_ut_eof(None, stack, lineno)
27,775
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.is_tuple_end
( self, extra_end_rules: t.Optional[t.Tuple[str, ...]] = None )
return False
Are we at the end of a tuple?
Are we at the end of a tuple?
148
156
def is_tuple_end( self, extra_end_rules: t.Optional[t.Tuple[str, ...]] = None ) -> bool: """Are we at the end of a tuple?""" if self.stream.current.type in ("variable_end", "block_end", "rparen"): return True elif extra_end_rules is not None: return self.stream.current.test_any(extra_end_rules) # type: ignore return False
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L148-L156
42
[ 0, 3, 4, 5, 6, 7, 8 ]
77.777778
[]
0
false
95.881732
9
3
100
1
def is_tuple_end( self, extra_end_rules: t.Optional[t.Tuple[str, ...]] = None ) -> bool: if self.stream.current.type in ("variable_end", "block_end", "rparen"): return True elif extra_end_rules is not None: return self.stream.current.test_any(extra_end_rules) # type: ignore return False
27,776
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.free_identifier
(self, lineno: t.Optional[int] = None)
return rv
Return a new free identifier as :class:`~jinja2.nodes.InternalName`.
Return a new free identifier as :class:`~jinja2.nodes.InternalName`.
158
163
def free_identifier(self, lineno: t.Optional[int] = None) -> nodes.InternalName: """Return a new free identifier as :class:`~jinja2.nodes.InternalName`.""" self._last_identifier += 1 rv = object.__new__(nodes.InternalName) nodes.Node.__init__(rv, f"fi{self._last_identifier}", lineno=lineno) return rv
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L158-L163
42
[ 0, 1 ]
33.333333
[ 2, 3, 4, 5 ]
66.666667
false
95.881732
6
1
33.333333
1
def free_identifier(self, lineno: t.Optional[int] = None) -> nodes.InternalName: self._last_identifier += 1 rv = object.__new__(nodes.InternalName) nodes.Node.__init__(rv, f"fi{self._last_identifier}", lineno=lineno) return rv
27,777
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_statement
(self)
Parse a single statement.
Parse a single statement.
165
192
def parse_statement(self) -> t.Union[nodes.Node, t.List[nodes.Node]]: """Parse a single statement.""" token = self.stream.current if token.type != "name": self.fail("tag name expected", token.lineno) self._tag_stack.append(token.value) pop_tag = True try: if token.value in _statement_keywords: f = getattr(self, f"parse_{self.stream.current.value}") return f() # type: ignore if token.value == "call": return self.parse_call_block() if token.value == "filter": return self.parse_filter_block() ext = self.extensions.get(token.value) if ext is not None: return ext(self) # did not work out, remove the token we pushed by accident # from the stack so that the unknown tag fail function can # produce a proper error message. self._tag_stack.pop() pop_tag = False self.fail_unknown_tag(token.value, token.lineno) finally: if pop_tag: self._tag_stack.pop()
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L165-L192
42
[ 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27 ]
96.428571
[ 4 ]
3.571429
false
95.881732
28
7
96.428571
1
def parse_statement(self) -> t.Union[nodes.Node, t.List[nodes.Node]]: token = self.stream.current if token.type != "name": self.fail("tag name expected", token.lineno) self._tag_stack.append(token.value) pop_tag = True try: if token.value in _statement_keywords: f = getattr(self, f"parse_{self.stream.current.value}") return f() # type: ignore if token.value == "call": return self.parse_call_block() if token.value == "filter": return self.parse_filter_block() ext = self.extensions.get(token.value) if ext is not None: return ext(self) # did not work out, remove the token we pushed by accident # from the stack so that the unknown tag fail function can # produce a proper error message. self._tag_stack.pop() pop_tag = False self.fail_unknown_tag(token.value, token.lineno) finally: if pop_tag: self._tag_stack.pop()
27,778
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_statements
( self, end_tokens: t.Tuple[str, ...], drop_needle: bool = False )
return result
Parse multiple statements into a list until one of the end tokens is reached. This is used to parse the body of statements as it also parses template data if appropriate. The parser checks first if the current token is a colon and skips it if there is one. Then it checks for the block end and parses until if one of the `end_tokens` is reached. Per default the active token in the stream at the end of the call is the matched end token. If this is not wanted `drop_needle` can be set to `True` and the end token is removed.
Parse multiple statements into a list until one of the end tokens is reached. This is used to parse the body of statements as it also parses template data if appropriate. The parser checks first if the current token is a colon and skips it if there is one. Then it checks for the block end and parses until if one of the `end_tokens` is reached. Per default the active token in the stream at the end of the call is the matched end token. If this is not wanted `drop_needle` can be set to `True` and the end token is removed.
194
221
def parse_statements( self, end_tokens: t.Tuple[str, ...], drop_needle: bool = False ) -> t.List[nodes.Node]: """Parse multiple statements into a list until one of the end tokens is reached. This is used to parse the body of statements as it also parses template data if appropriate. The parser checks first if the current token is a colon and skips it if there is one. Then it checks for the block end and parses until if one of the `end_tokens` is reached. Per default the active token in the stream at the end of the call is the matched end token. If this is not wanted `drop_needle` can be set to `True` and the end token is removed. """ # the first token may be a colon for python compatibility self.stream.skip_if("colon") # in the future it would be possible to add whole code sections # by adding some sort of end of statement token and parsing those here. self.stream.expect("block_end") result = self.subparse(end_tokens) # we reached the end of the template too early, the subparser # does not check for this, so we do that now if self.stream.current.type == "eof": self.fail_eof(end_tokens) if drop_needle: next(self.stream) return result
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L194-L221
42
[ 0, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27 ]
60.714286
[]
0
false
95.881732
28
3
100
8
def parse_statements( self, end_tokens: t.Tuple[str, ...], drop_needle: bool = False ) -> t.List[nodes.Node]: # the first token may be a colon for python compatibility self.stream.skip_if("colon") # in the future it would be possible to add whole code sections # by adding some sort of end of statement token and parsing those here. self.stream.expect("block_end") result = self.subparse(end_tokens) # we reached the end of the template too early, the subparser # does not check for this, so we do that now if self.stream.current.type == "eof": self.fail_eof(end_tokens) if drop_needle: next(self.stream) return result
27,779
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_set
(self)
return nodes.AssignBlock(target, filter_node, body, lineno=lineno)
Parse an assign statement.
Parse an assign statement.
223
232
def parse_set(self) -> t.Union[nodes.Assign, nodes.AssignBlock]: """Parse an assign statement.""" lineno = next(self.stream).lineno target = self.parse_assign_target(with_namespace=True) if self.stream.skip_if("assign"): expr = self.parse_tuple() return nodes.Assign(target, expr, lineno=lineno) filter_node = self.parse_filter(None) body = self.parse_statements(("name:endset",), drop_needle=True) return nodes.AssignBlock(target, filter_node, body, lineno=lineno)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L223-L232
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
100
[]
0
true
95.881732
10
2
100
1
def parse_set(self) -> t.Union[nodes.Assign, nodes.AssignBlock]: lineno = next(self.stream).lineno target = self.parse_assign_target(with_namespace=True) if self.stream.skip_if("assign"): expr = self.parse_tuple() return nodes.Assign(target, expr, lineno=lineno) filter_node = self.parse_filter(None) body = self.parse_statements(("name:endset",), drop_needle=True) return nodes.AssignBlock(target, filter_node, body, lineno=lineno)
27,780
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_for
(self)
return nodes.For(target, iter, body, else_, test, recursive, lineno=lineno)
Parse a for loop.
Parse a for loop.
234
251
def parse_for(self) -> nodes.For: """Parse a for loop.""" lineno = self.stream.expect("name:for").lineno target = self.parse_assign_target(extra_end_rules=("name:in",)) self.stream.expect("name:in") iter = self.parse_tuple( with_condexpr=False, extra_end_rules=("name:recursive",) ) test = None if self.stream.skip_if("name:if"): test = self.parse_expression() recursive = self.stream.skip_if("name:recursive") body = self.parse_statements(("name:endfor", "name:else")) if next(self.stream).value == "endfor": else_ = [] else: else_ = self.parse_statements(("name:endfor",), drop_needle=True) return nodes.For(target, iter, body, else_, test, recursive, lineno=lineno)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L234-L251
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 ]
100
[]
0
true
95.881732
18
3
100
1
def parse_for(self) -> nodes.For: lineno = self.stream.expect("name:for").lineno target = self.parse_assign_target(extra_end_rules=("name:in",)) self.stream.expect("name:in") iter = self.parse_tuple( with_condexpr=False, extra_end_rules=("name:recursive",) ) test = None if self.stream.skip_if("name:if"): test = self.parse_expression() recursive = self.stream.skip_if("name:recursive") body = self.parse_statements(("name:endfor", "name:else")) if next(self.stream).value == "endfor": else_ = [] else: else_ = self.parse_statements(("name:endfor",), drop_needle=True) return nodes.For(target, iter, body, else_, test, recursive, lineno=lineno)
27,781
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_if
(self)
return result
Parse an if construct.
Parse an if construct.
253
269
def parse_if(self) -> nodes.If: """Parse an if construct.""" node = result = nodes.If(lineno=self.stream.expect("name:if").lineno) while True: node.test = self.parse_tuple(with_condexpr=False) node.body = self.parse_statements(("name:elif", "name:else", "name:endif")) node.elif_ = [] node.else_ = [] token = next(self.stream) if token.test("name:elif"): node = nodes.If(lineno=self.stream.current.lineno) result.elif_.append(node) continue elif token.test("name:else"): result.else_ = self.parse_statements(("name:endif",), drop_needle=True) break return result
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L253-L269
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]
100
[]
0
true
95.881732
17
4
100
1
def parse_if(self) -> nodes.If: node = result = nodes.If(lineno=self.stream.expect("name:if").lineno) while True: node.test = self.parse_tuple(with_condexpr=False) node.body = self.parse_statements(("name:elif", "name:else", "name:endif")) node.elif_ = [] node.else_ = [] token = next(self.stream) if token.test("name:elif"): node = nodes.If(lineno=self.stream.current.lineno) result.elif_.append(node) continue elif token.test("name:else"): result.else_ = self.parse_statements(("name:endif",), drop_needle=True) break return result
27,782
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_with
(self)
return node
271
286
def parse_with(self) -> nodes.With: node = nodes.With(lineno=next(self.stream).lineno) targets: t.List[nodes.Expr] = [] values: t.List[nodes.Expr] = [] while self.stream.current.type != "block_end": if targets: self.stream.expect("comma") target = self.parse_assign_target() target.set_ctx("param") targets.append(target) self.stream.expect("assign") values.append(self.parse_expression()) node.targets = targets node.values = values node.body = self.parse_statements(("name:endwith",), drop_needle=True) return node
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L271-L286
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ]
100
[]
0
true
95.881732
16
3
100
0
def parse_with(self) -> nodes.With: node = nodes.With(lineno=next(self.stream).lineno) targets: t.List[nodes.Expr] = [] values: t.List[nodes.Expr] = [] while self.stream.current.type != "block_end": if targets: self.stream.expect("comma") target = self.parse_assign_target() target.set_ctx("param") targets.append(target) self.stream.expect("assign") values.append(self.parse_expression()) node.targets = targets node.values = values node.body = self.parse_statements(("name:endwith",), drop_needle=True) return node
27,783
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_autoescape
(self)
return nodes.Scope([node])
288
292
def parse_autoescape(self) -> nodes.Scope: node = nodes.ScopedEvalContextModifier(lineno=next(self.stream).lineno) node.options = [nodes.Keyword("autoescape", self.parse_expression())] node.body = self.parse_statements(("name:endautoescape",), drop_needle=True) return nodes.Scope([node])
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L288-L292
42
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
95.881732
5
1
100
0
def parse_autoescape(self) -> nodes.Scope: node = nodes.ScopedEvalContextModifier(lineno=next(self.stream).lineno) node.options = [nodes.Keyword("autoescape", self.parse_expression())] node.body = self.parse_statements(("name:endautoescape",), drop_needle=True) return nodes.Scope([node])
27,784
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_block
(self)
return node
294
322
def parse_block(self) -> nodes.Block: node = nodes.Block(lineno=next(self.stream).lineno) node.name = self.stream.expect("name").value node.scoped = self.stream.skip_if("name:scoped") node.required = self.stream.skip_if("name:required") # common problem people encounter when switching from django # to jinja. we do not support hyphens in block names, so let's # raise a nicer error message in that case. if self.stream.current.type == "sub": self.fail( "Block names in Jinja have to be valid Python identifiers and may not" " contain hyphens, use an underscore instead." ) node.body = self.parse_statements(("name:endblock",), drop_needle=True) # enforce that required blocks only contain whitespace or comments # by asserting that the body, if not empty, is just TemplateData nodes # with whitespace data if node.required and not all( isinstance(child, nodes.TemplateData) and child.data.isspace() for body in node.body for child in body.nodes # type: ignore ): self.fail("Required blocks can only contain comments or whitespace") self.stream.skip_if("name:" + node.name) return node
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L294-L322
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 14, 15, 16, 17, 18, 19, 20, 25, 26, 27, 28 ]
75.862069
[]
0
false
95.881732
29
5
100
0
def parse_block(self) -> nodes.Block: node = nodes.Block(lineno=next(self.stream).lineno) node.name = self.stream.expect("name").value node.scoped = self.stream.skip_if("name:scoped") node.required = self.stream.skip_if("name:required") # common problem people encounter when switching from django # to jinja. we do not support hyphens in block names, so let's # raise a nicer error message in that case. if self.stream.current.type == "sub": self.fail( "Block names in Jinja have to be valid Python identifiers and may not" " contain hyphens, use an underscore instead." ) node.body = self.parse_statements(("name:endblock",), drop_needle=True) # enforce that required blocks only contain whitespace or comments # by asserting that the body, if not empty, is just TemplateData nodes # with whitespace data if node.required and not all( isinstance(child, nodes.TemplateData) and child.data.isspace() for body in node.body for child in body.nodes # type: ignore ): self.fail("Required blocks can only contain comments or whitespace") self.stream.skip_if("name:" + node.name) return node
27,785
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_extends
(self)
return node
324
327
def parse_extends(self) -> nodes.Extends: node = nodes.Extends(lineno=next(self.stream).lineno) node.template = self.parse_expression() return node
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L324-L327
42
[ 0, 1, 2, 3 ]
100
[]
0
true
95.881732
4
1
100
0
def parse_extends(self) -> nodes.Extends: node = nodes.Extends(lineno=next(self.stream).lineno) node.template = self.parse_expression() return node
27,786
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_import_context
( self, node: _ImportInclude, default: bool )
return node
329
339
def parse_import_context( self, node: _ImportInclude, default: bool ) -> _ImportInclude: if self.stream.current.test_any( "name:with", "name:without" ) and self.stream.look().test("name:context"): node.with_context = next(self.stream).value == "with" self.stream.skip() else: node.with_context = default return node
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L329-L339
42
[ 0, 3, 6, 7, 9, 10 ]
54.545455
[]
0
false
95.881732
11
3
100
0
def parse_import_context( self, node: _ImportInclude, default: bool ) -> _ImportInclude: if self.stream.current.test_any( "name:with", "name:without" ) and self.stream.look().test("name:context"): node.with_context = next(self.stream).value == "with" self.stream.skip() else: node.with_context = default return node
27,787
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_include
(self)
return self.parse_import_context(node, True)
341
351
def parse_include(self) -> nodes.Include: node = nodes.Include(lineno=next(self.stream).lineno) node.template = self.parse_expression() if self.stream.current.test("name:ignore") and self.stream.look().test( "name:missing" ): node.ignore_missing = True self.stream.skip(2) else: node.ignore_missing = False return self.parse_import_context(node, True)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L341-L351
42
[ 0, 1, 2, 3, 6, 7, 9, 10 ]
72.727273
[]
0
false
95.881732
11
3
100
0
def parse_include(self) -> nodes.Include: node = nodes.Include(lineno=next(self.stream).lineno) node.template = self.parse_expression() if self.stream.current.test("name:ignore") and self.stream.look().test( "name:missing" ): node.ignore_missing = True self.stream.skip(2) else: node.ignore_missing = False return self.parse_import_context(node, True)
27,788
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_import
(self)
return self.parse_import_context(node, False)
353
358
def parse_import(self) -> nodes.Import: node = nodes.Import(lineno=next(self.stream).lineno) node.template = self.parse_expression() self.stream.expect("name:as") node.target = self.parse_assign_target(name_only=True).name return self.parse_import_context(node, False)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L353-L358
42
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
95.881732
6
1
100
0
def parse_import(self) -> nodes.Import: node = nodes.Import(lineno=next(self.stream).lineno) node.template = self.parse_expression() self.stream.expect("name:as") node.target = self.parse_assign_target(name_only=True).name return self.parse_import_context(node, False)
27,789
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_from
(self)
return node
360
400
def parse_from(self) -> nodes.FromImport: node = nodes.FromImport(lineno=next(self.stream).lineno) node.template = self.parse_expression() self.stream.expect("name:import") node.names = [] def parse_context() -> bool: if self.stream.current.value in { "with", "without", } and self.stream.look().test("name:context"): node.with_context = next(self.stream).value == "with" self.stream.skip() return True return False while True: if node.names: self.stream.expect("comma") if self.stream.current.type == "name": if parse_context(): break target = self.parse_assign_target(name_only=True) if target.name.startswith("_"): self.fail( "names starting with an underline can not be imported", target.lineno, exc=TemplateAssertionError, ) if self.stream.skip_if("name:as"): alias = self.parse_assign_target(name_only=True) node.names.append((target.name, alias.name)) else: node.names.append(target.name) if parse_context() or self.stream.current.type != "comma": break else: self.stream.expect("name") if not hasattr(node, "with_context"): node.with_context = False return node
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L360-L400
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 29, 30, 31, 33, 34, 35, 37, 38, 39, 40 ]
75.609756
[ 24 ]
2.439024
false
95.881732
41
13
97.560976
0
def parse_from(self) -> nodes.FromImport: node = nodes.FromImport(lineno=next(self.stream).lineno) node.template = self.parse_expression() self.stream.expect("name:import") node.names = [] def parse_context() -> bool: if self.stream.current.value in { "with", "without", } and self.stream.look().test("name:context"): node.with_context = next(self.stream).value == "with" self.stream.skip() return True return False while True: if node.names: self.stream.expect("comma") if self.stream.current.type == "name": if parse_context(): break target = self.parse_assign_target(name_only=True) if target.name.startswith("_"): self.fail( "names starting with an underline can not be imported", target.lineno, exc=TemplateAssertionError, ) if self.stream.skip_if("name:as"): alias = self.parse_assign_target(name_only=True) node.names.append((target.name, alias.name)) else: node.names.append(target.name) if parse_context() or self.stream.current.type != "comma": break else: self.stream.expect("name") if not hasattr(node, "with_context"): node.with_context = False return node
27,790
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_signature
(self, node: _MacroCall)
402
416
def parse_signature(self, node: _MacroCall) -> None: args = node.args = [] defaults = node.defaults = [] self.stream.expect("lparen") while self.stream.current.type != "rparen": if args: self.stream.expect("comma") arg = self.parse_assign_target(name_only=True) arg.set_ctx("param") if self.stream.skip_if("assign"): defaults.append(self.parse_expression()) elif defaults: self.fail("non-default argument follows default argument") args.append(arg) self.stream.expect("rparen")
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L402-L416
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ]
100
[]
0
true
95.881732
15
5
100
0
def parse_signature(self, node: _MacroCall) -> None: args = node.args = [] defaults = node.defaults = [] self.stream.expect("lparen") while self.stream.current.type != "rparen": if args: self.stream.expect("comma") arg = self.parse_assign_target(name_only=True) arg.set_ctx("param") if self.stream.skip_if("assign"): defaults.append(self.parse_expression()) elif defaults: self.fail("non-default argument follows default argument") args.append(arg) self.stream.expect("rparen")
27,791
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_call_block
(self)
return node
418
431
def parse_call_block(self) -> nodes.CallBlock: node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == "lparen": self.parse_signature(node) else: node.args = [] node.defaults = [] call_node = self.parse_expression() if not isinstance(call_node, nodes.Call): self.fail("expected call", node.lineno) node.call = call_node node.body = self.parse_statements(("name:endcall",), drop_needle=True) return node
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L418-L431
42
[ 0, 1, 2, 3, 5, 6, 7, 8, 9, 11, 12, 13 ]
85.714286
[ 10 ]
7.142857
false
95.881732
14
3
92.857143
0
def parse_call_block(self) -> nodes.CallBlock: node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == "lparen": self.parse_signature(node) else: node.args = [] node.defaults = [] call_node = self.parse_expression() if not isinstance(call_node, nodes.Call): self.fail("expected call", node.lineno) node.call = call_node node.body = self.parse_statements(("name:endcall",), drop_needle=True) return node
27,792
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_filter_block
(self)
return node
433
437
def parse_filter_block(self) -> nodes.FilterBlock: node = nodes.FilterBlock(lineno=next(self.stream).lineno) node.filter = self.parse_filter(None, start_inline=True) # type: ignore node.body = self.parse_statements(("name:endfilter",), drop_needle=True) return node
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L433-L437
42
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
95.881732
5
1
100
0
def parse_filter_block(self) -> nodes.FilterBlock: node = nodes.FilterBlock(lineno=next(self.stream).lineno) node.filter = self.parse_filter(None, start_inline=True) # type: ignore node.body = self.parse_statements(("name:endfilter",), drop_needle=True) return node
27,793
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_macro
(self)
return node
439
444
def parse_macro(self) -> nodes.Macro: node = nodes.Macro(lineno=next(self.stream).lineno) node.name = self.parse_assign_target(name_only=True).name self.parse_signature(node) node.body = self.parse_statements(("name:endmacro",), drop_needle=True) return node
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L439-L444
42
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
95.881732
6
1
100
0
def parse_macro(self) -> nodes.Macro: node = nodes.Macro(lineno=next(self.stream).lineno) node.name = self.parse_assign_target(name_only=True).name self.parse_signature(node) node.body = self.parse_statements(("name:endmacro",), drop_needle=True) return node
27,794
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_print
(self)
return node
446
453
def parse_print(self) -> nodes.Output: node = nodes.Output(lineno=next(self.stream).lineno) node.nodes = [] while self.stream.current.type != "block_end": if node.nodes: self.stream.expect("comma") node.nodes.append(self.parse_expression()) return node
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L446-L453
42
[ 0, 1, 2, 3, 4, 6, 7 ]
87.5
[ 5 ]
12.5
false
95.881732
8
3
87.5
0
def parse_print(self) -> nodes.Output: node = nodes.Output(lineno=next(self.stream).lineno) node.nodes = [] while self.stream.current.type != "block_end": if node.nodes: self.stream.expect("comma") node.nodes.append(self.parse_expression()) return node
27,795
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_assign_target
( self, with_tuple: bool = ..., name_only: "te.Literal[True]" = ... )
456
459
def parse_assign_target( self, with_tuple: bool = ..., name_only: "te.Literal[True]" = ... ) -> nodes.Name: ...
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L456-L459
42
[ 0 ]
25
[ 3 ]
25
false
95.881732
4
1
75
0
def parse_assign_target( self, with_tuple: bool = ..., name_only: "te.Literal[True]" = ... ) -> nodes.Name: ...
27,796
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_assign_target
( self, with_tuple: bool = True, name_only: bool = False, extra_end_rules: t.Optional[t.Tuple[str, ...]] = None, with_namespace: bool = False, )
462
469
def parse_assign_target( self, with_tuple: bool = True, name_only: bool = False, extra_end_rules: t.Optional[t.Tuple[str, ...]] = None, with_namespace: bool = False, ) -> t.Union[nodes.NSRef, nodes.Name, nodes.Tuple]: ...
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L462-L469
42
[ 0 ]
12.5
[ 7 ]
12.5
false
95.881732
8
1
87.5
0
def parse_assign_target( self, with_tuple: bool = True, name_only: bool = False, extra_end_rules: t.Optional[t.Tuple[str, ...]] = None, with_namespace: bool = False, ) -> t.Union[nodes.NSRef, nodes.Name, nodes.Tuple]: ...
27,797
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_assign_target
( self, with_tuple: bool = True, name_only: bool = False, extra_end_rules: t.Optional[t.Tuple[str, ...]] = None, with_namespace: bool = False, )
return target
Parse an assignment target. As Jinja allows assignments to tuples, this function can parse all allowed assignment targets. Per default assignments to tuples are parsed, that can be disable however by setting `with_tuple` to `False`. If only assignments to names are wanted `name_only` can be set to `True`. The `extra_end_rules` parameter is forwarded to the tuple parsing function. If `with_namespace` is enabled, a namespace assignment may be parsed.
Parse an assignment target. As Jinja allows assignments to tuples, this function can parse all allowed assignment targets. Per default assignments to tuples are parsed, that can be disable however by setting `with_tuple` to `False`. If only assignments to names are wanted `name_only` can be set to `True`. The `extra_end_rules` parameter is forwarded to the tuple parsing function. If `with_namespace` is enabled, a namespace assignment may be parsed.
471
511
def parse_assign_target( self, with_tuple: bool = True, name_only: bool = False, extra_end_rules: t.Optional[t.Tuple[str, ...]] = None, with_namespace: bool = False, ) -> t.Union[nodes.NSRef, nodes.Name, nodes.Tuple]: """Parse an assignment target. As Jinja allows assignments to tuples, this function can parse all allowed assignment targets. Per default assignments to tuples are parsed, that can be disable however by setting `with_tuple` to `False`. If only assignments to names are wanted `name_only` can be set to `True`. The `extra_end_rules` parameter is forwarded to the tuple parsing function. If `with_namespace` is enabled, a namespace assignment may be parsed. """ target: nodes.Expr if with_namespace and self.stream.look().type == "dot": token = self.stream.expect("name") next(self.stream) # dot attr = self.stream.expect("name") target = nodes.NSRef(token.value, attr.value, lineno=token.lineno) elif name_only: token = self.stream.expect("name") target = nodes.Name(token.value, "store", lineno=token.lineno) else: if with_tuple: target = self.parse_tuple( simplified=True, extra_end_rules=extra_end_rules ) else: target = self.parse_primary() target.set_ctx("store") if not target.can_assign(): self.fail( f"can't assign to {type(target).__name__.lower()!r}", target.lineno ) return target
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L471-L511
42
[ 0, 16, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27, 32, 33, 34, 35, 36, 39, 40 ]
46.341463
[ 31 ]
2.439024
false
95.881732
41
6
97.560976
7
def parse_assign_target( self, with_tuple: bool = True, name_only: bool = False, extra_end_rules: t.Optional[t.Tuple[str, ...]] = None, with_namespace: bool = False, ) -> t.Union[nodes.NSRef, nodes.Name, nodes.Tuple]: target: nodes.Expr if with_namespace and self.stream.look().type == "dot": token = self.stream.expect("name") next(self.stream) # dot attr = self.stream.expect("name") target = nodes.NSRef(token.value, attr.value, lineno=token.lineno) elif name_only: token = self.stream.expect("name") target = nodes.Name(token.value, "store", lineno=token.lineno) else: if with_tuple: target = self.parse_tuple( simplified=True, extra_end_rules=extra_end_rules ) else: target = self.parse_primary() target.set_ctx("store") if not target.can_assign(): self.fail( f"can't assign to {type(target).__name__.lower()!r}", target.lineno ) return target
27,798
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_expression
(self, with_condexpr: bool = True)
return self.parse_or()
Parse an expression. Per default all expressions are parsed, if the optional `with_condexpr` parameter is set to `False` conditional expressions are not parsed.
Parse an expression. Per default all expressions are parsed, if the optional `with_condexpr` parameter is set to `False` conditional expressions are not parsed.
513
520
def parse_expression(self, with_condexpr: bool = True) -> nodes.Expr: """Parse an expression. Per default all expressions are parsed, if the optional `with_condexpr` parameter is set to `False` conditional expressions are not parsed. """ if with_condexpr: return self.parse_condexpr() return self.parse_or()
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L513-L520
42
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
95.881732
8
2
100
3
def parse_expression(self, with_condexpr: bool = True) -> nodes.Expr: if with_condexpr: return self.parse_condexpr() return self.parse_or()
27,799
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_condexpr
(self)
return expr1
522
535
def parse_condexpr(self) -> nodes.Expr: lineno = self.stream.current.lineno expr1 = self.parse_or() expr3: t.Optional[nodes.Expr] while self.stream.skip_if("name:if"): expr2 = self.parse_or() if self.stream.skip_if("name:else"): expr3 = self.parse_condexpr() else: expr3 = None expr1 = nodes.CondExpr(expr2, expr1, expr3, lineno=lineno) lineno = self.stream.current.lineno return expr1
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L522-L535
42
[ 0, 1, 2, 4, 5, 6, 7, 8, 10, 11, 12, 13 ]
85.714286
[]
0
false
95.881732
14
3
100
0
def parse_condexpr(self) -> nodes.Expr: lineno = self.stream.current.lineno expr1 = self.parse_or() expr3: t.Optional[nodes.Expr] while self.stream.skip_if("name:if"): expr2 = self.parse_or() if self.stream.skip_if("name:else"): expr3 = self.parse_condexpr() else: expr3 = None expr1 = nodes.CondExpr(expr2, expr1, expr3, lineno=lineno) lineno = self.stream.current.lineno return expr1
27,800
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_or
(self)
return left
537
544
def parse_or(self) -> nodes.Expr: lineno = self.stream.current.lineno left = self.parse_and() while self.stream.skip_if("name:or"): right = self.parse_and() left = nodes.Or(left, right, lineno=lineno) lineno = self.stream.current.lineno return left
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L537-L544
42
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
95.881732
8
2
100
0
def parse_or(self) -> nodes.Expr: lineno = self.stream.current.lineno left = self.parse_and() while self.stream.skip_if("name:or"): right = self.parse_and() left = nodes.Or(left, right, lineno=lineno) lineno = self.stream.current.lineno return left
27,801
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_and
(self)
return left
546
553
def parse_and(self) -> nodes.Expr: lineno = self.stream.current.lineno left = self.parse_not() while self.stream.skip_if("name:and"): right = self.parse_not() left = nodes.And(left, right, lineno=lineno) lineno = self.stream.current.lineno return left
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L546-L553
42
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
95.881732
8
2
100
0
def parse_and(self) -> nodes.Expr: lineno = self.stream.current.lineno left = self.parse_not() while self.stream.skip_if("name:and"): right = self.parse_not() left = nodes.And(left, right, lineno=lineno) lineno = self.stream.current.lineno return left
27,802
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_not
(self)
return self.parse_compare()
555
559
def parse_not(self) -> nodes.Expr: if self.stream.current.test("name:not"): lineno = next(self.stream).lineno return nodes.Not(self.parse_not(), lineno=lineno) return self.parse_compare()
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L555-L559
42
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
95.881732
5
2
100
0
def parse_not(self) -> nodes.Expr: if self.stream.current.test("name:not"): lineno = next(self.stream).lineno return nodes.Not(self.parse_not(), lineno=lineno) return self.parse_compare()
27,803
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_compare
(self)
return nodes.Compare(expr, ops, lineno=lineno)
561
582
def parse_compare(self) -> nodes.Expr: lineno = self.stream.current.lineno expr = self.parse_math1() ops = [] while True: token_type = self.stream.current.type if token_type in _compare_operators: next(self.stream) ops.append(nodes.Operand(token_type, self.parse_math1())) elif self.stream.skip_if("name:in"): ops.append(nodes.Operand("in", self.parse_math1())) elif self.stream.current.test("name:not") and self.stream.look().test( "name:in" ): self.stream.skip(2) ops.append(nodes.Operand("notin", self.parse_math1())) else: break lineno = self.stream.current.lineno if not ops: return expr return nodes.Compare(expr, ops, lineno=lineno)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L561-L582
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 14, 15, 17, 18, 19, 20, 21 ]
86.363636
[]
0
false
95.881732
22
7
100
0
def parse_compare(self) -> nodes.Expr: lineno = self.stream.current.lineno expr = self.parse_math1() ops = [] while True: token_type = self.stream.current.type if token_type in _compare_operators: next(self.stream) ops.append(nodes.Operand(token_type, self.parse_math1())) elif self.stream.skip_if("name:in"): ops.append(nodes.Operand("in", self.parse_math1())) elif self.stream.current.test("name:not") and self.stream.look().test( "name:in" ): self.stream.skip(2) ops.append(nodes.Operand("notin", self.parse_math1())) else: break lineno = self.stream.current.lineno if not ops: return expr return nodes.Compare(expr, ops, lineno=lineno)
27,804
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_math1
(self)
return left
584
593
def parse_math1(self) -> nodes.Expr: lineno = self.stream.current.lineno left = self.parse_concat() while self.stream.current.type in ("add", "sub"): cls = _math_nodes[self.stream.current.type] next(self.stream) right = self.parse_concat() left = cls(left, right, lineno=lineno) lineno = self.stream.current.lineno return left
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L584-L593
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
100
[]
0
true
95.881732
10
2
100
0
def parse_math1(self) -> nodes.Expr: lineno = self.stream.current.lineno left = self.parse_concat() while self.stream.current.type in ("add", "sub"): cls = _math_nodes[self.stream.current.type] next(self.stream) right = self.parse_concat() left = cls(left, right, lineno=lineno) lineno = self.stream.current.lineno return left
27,805
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_concat
(self)
return nodes.Concat(args, lineno=lineno)
595
603
def parse_concat(self) -> nodes.Expr: lineno = self.stream.current.lineno args = [self.parse_math2()] while self.stream.current.type == "tilde": next(self.stream) args.append(self.parse_math2()) if len(args) == 1: return args[0] return nodes.Concat(args, lineno=lineno)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L595-L603
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
100
[]
0
true
95.881732
9
3
100
0
def parse_concat(self) -> nodes.Expr: lineno = self.stream.current.lineno args = [self.parse_math2()] while self.stream.current.type == "tilde": next(self.stream) args.append(self.parse_math2()) if len(args) == 1: return args[0] return nodes.Concat(args, lineno=lineno)
27,806
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_math2
(self)
return left
605
614
def parse_math2(self) -> nodes.Expr: lineno = self.stream.current.lineno left = self.parse_pow() while self.stream.current.type in ("mul", "div", "floordiv", "mod"): cls = _math_nodes[self.stream.current.type] next(self.stream) right = self.parse_pow() left = cls(left, right, lineno=lineno) lineno = self.stream.current.lineno return left
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L605-L614
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
100
[]
0
true
95.881732
10
2
100
0
def parse_math2(self) -> nodes.Expr: lineno = self.stream.current.lineno left = self.parse_pow() while self.stream.current.type in ("mul", "div", "floordiv", "mod"): cls = _math_nodes[self.stream.current.type] next(self.stream) right = self.parse_pow() left = cls(left, right, lineno=lineno) lineno = self.stream.current.lineno return left
27,807
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_pow
(self)
return left
616
624
def parse_pow(self) -> nodes.Expr: lineno = self.stream.current.lineno left = self.parse_unary() while self.stream.current.type == "pow": next(self.stream) right = self.parse_unary() left = nodes.Pow(left, right, lineno=lineno) lineno = self.stream.current.lineno return left
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L616-L624
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
100
[]
0
true
95.881732
9
2
100
0
def parse_pow(self) -> nodes.Expr: lineno = self.stream.current.lineno left = self.parse_unary() while self.stream.current.type == "pow": next(self.stream) right = self.parse_unary() left = nodes.Pow(left, right, lineno=lineno) lineno = self.stream.current.lineno return left
27,808
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_unary
(self, with_filter: bool = True)
return node
626
642
def parse_unary(self, with_filter: bool = True) -> nodes.Expr: token_type = self.stream.current.type lineno = self.stream.current.lineno node: nodes.Expr if token_type == "sub": next(self.stream) node = nodes.Neg(self.parse_unary(False), lineno=lineno) elif token_type == "add": next(self.stream) node = nodes.Pos(self.parse_unary(False), lineno=lineno) else: node = self.parse_primary() node = self.parse_postfix(node) if with_filter: node = self.parse_filter_expr(node) return node
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L626-L642
42
[ 0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16 ]
88.235294
[]
0
false
95.881732
17
4
100
0
def parse_unary(self, with_filter: bool = True) -> nodes.Expr: token_type = self.stream.current.type lineno = self.stream.current.lineno node: nodes.Expr if token_type == "sub": next(self.stream) node = nodes.Neg(self.parse_unary(False), lineno=lineno) elif token_type == "add": next(self.stream) node = nodes.Pos(self.parse_unary(False), lineno=lineno) else: node = self.parse_primary() node = self.parse_postfix(node) if with_filter: node = self.parse_filter_expr(node) return node
27,809
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_primary
(self)
return node
644
676
def parse_primary(self) -> nodes.Expr: token = self.stream.current node: nodes.Expr if token.type == "name": if token.value in ("true", "false", "True", "False"): node = nodes.Const(token.value in ("true", "True"), lineno=token.lineno) elif token.value in ("none", "None"): node = nodes.Const(None, lineno=token.lineno) else: node = nodes.Name(token.value, "load", lineno=token.lineno) next(self.stream) elif token.type == "string": next(self.stream) buf = [token.value] lineno = token.lineno while self.stream.current.type == "string": buf.append(self.stream.current.value) next(self.stream) node = nodes.Const("".join(buf), lineno=lineno) elif token.type in ("integer", "float"): next(self.stream) node = nodes.Const(token.value, lineno=token.lineno) elif token.type == "lparen": next(self.stream) node = self.parse_tuple(explicit_parentheses=True) self.stream.expect("rparen") elif token.type == "lbracket": node = self.parse_list() elif token.type == "lbrace": node = self.parse_dict() else: self.fail(f"unexpected {describe_token(token)!r}", token.lineno) return node
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L644-L676
42
[ 0, 1, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 32 ]
90.909091
[]
0
false
95.881732
33
10
100
0
def parse_primary(self) -> nodes.Expr: token = self.stream.current node: nodes.Expr if token.type == "name": if token.value in ("true", "false", "True", "False"): node = nodes.Const(token.value in ("true", "True"), lineno=token.lineno) elif token.value in ("none", "None"): node = nodes.Const(None, lineno=token.lineno) else: node = nodes.Name(token.value, "load", lineno=token.lineno) next(self.stream) elif token.type == "string": next(self.stream) buf = [token.value] lineno = token.lineno while self.stream.current.type == "string": buf.append(self.stream.current.value) next(self.stream) node = nodes.Const("".join(buf), lineno=lineno) elif token.type in ("integer", "float"): next(self.stream) node = nodes.Const(token.value, lineno=token.lineno) elif token.type == "lparen": next(self.stream) node = self.parse_tuple(explicit_parentheses=True) self.stream.expect("rparen") elif token.type == "lbracket": node = self.parse_list() elif token.type == "lbrace": node = self.parse_dict() else: self.fail(f"unexpected {describe_token(token)!r}", token.lineno) return node
27,810
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_tuple
( self, simplified: bool = False, with_condexpr: bool = True, extra_end_rules: t.Optional[t.Tuple[str, ...]] = None, explicit_parentheses: bool = False, )
return nodes.Tuple(args, "load", lineno=lineno)
Works like `parse_expression` but if multiple expressions are delimited by a comma a :class:`~jinja2.nodes.Tuple` node is created. This method could also return a regular expression instead of a tuple if no commas where found. The default parsing mode is a full tuple. If `simplified` is `True` only names and literals are parsed. The `no_condexpr` parameter is forwarded to :meth:`parse_expression`. Because tuples do not require delimiters and may end in a bogus comma an extra hint is needed that marks the end of a tuple. For example for loops support tuples between `for` and `in`. In that case the `extra_end_rules` is set to ``['name:in']``. `explicit_parentheses` is true if the parsing was triggered by an expression in parentheses. This is used to figure out if an empty tuple is a valid expression or not.
Works like `parse_expression` but if multiple expressions are delimited by a comma a :class:`~jinja2.nodes.Tuple` node is created. This method could also return a regular expression instead of a tuple if no commas where found.
678
742
def parse_tuple( self, simplified: bool = False, with_condexpr: bool = True, extra_end_rules: t.Optional[t.Tuple[str, ...]] = None, explicit_parentheses: bool = False, ) -> t.Union[nodes.Tuple, nodes.Expr]: """Works like `parse_expression` but if multiple expressions are delimited by a comma a :class:`~jinja2.nodes.Tuple` node is created. This method could also return a regular expression instead of a tuple if no commas where found. The default parsing mode is a full tuple. If `simplified` is `True` only names and literals are parsed. The `no_condexpr` parameter is forwarded to :meth:`parse_expression`. Because tuples do not require delimiters and may end in a bogus comma an extra hint is needed that marks the end of a tuple. For example for loops support tuples between `for` and `in`. In that case the `extra_end_rules` is set to ``['name:in']``. `explicit_parentheses` is true if the parsing was triggered by an expression in parentheses. This is used to figure out if an empty tuple is a valid expression or not. """ lineno = self.stream.current.lineno if simplified: parse = self.parse_primary elif with_condexpr: parse = self.parse_expression else: def parse() -> nodes.Expr: return self.parse_expression(with_condexpr=False) args: t.List[nodes.Expr] = [] is_tuple = False while True: if args: self.stream.expect("comma") if self.is_tuple_end(extra_end_rules): break args.append(parse()) if self.stream.current.type == "comma": is_tuple = True else: break lineno = self.stream.current.lineno if not is_tuple: if args: return args[0] # if we don't have explicit parentheses, an empty tuple is # not a valid expression. This would mean nothing (literally # nothing) in the spot of an expression would be an empty # tuple. if not explicit_parentheses: self.fail( "Expected an expression," f" got {describe_token(self.stream.current)!r}" ) return nodes.Tuple(args, "load", lineno=lineno)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L678-L742
42
[ 0, 24, 25, 26, 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, 59, 60, 61, 62, 63, 64 ]
64.615385
[]
0
false
95.881732
65
11
100
17
def parse_tuple( self, simplified: bool = False, with_condexpr: bool = True, extra_end_rules: t.Optional[t.Tuple[str, ...]] = None, explicit_parentheses: bool = False, ) -> t.Union[nodes.Tuple, nodes.Expr]: lineno = self.stream.current.lineno if simplified: parse = self.parse_primary elif with_condexpr: parse = self.parse_expression else: def parse() -> nodes.Expr: return self.parse_expression(with_condexpr=False) args: t.List[nodes.Expr] = [] is_tuple = False while True: if args: self.stream.expect("comma") if self.is_tuple_end(extra_end_rules): break args.append(parse()) if self.stream.current.type == "comma": is_tuple = True else: break lineno = self.stream.current.lineno if not is_tuple: if args: return args[0] # if we don't have explicit parentheses, an empty tuple is # not a valid expression. This would mean nothing (literally # nothing) in the spot of an expression would be an empty # tuple. if not explicit_parentheses: self.fail( "Expected an expression," f" got {describe_token(self.stream.current)!r}" ) return nodes.Tuple(args, "load", lineno=lineno)
27,811
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_list
(self)
return nodes.List(items, lineno=token.lineno)
744
754
def parse_list(self) -> nodes.List: token = self.stream.expect("lbracket") items: t.List[nodes.Expr] = [] while self.stream.current.type != "rbracket": if items: self.stream.expect("comma") if self.stream.current.type == "rbracket": break items.append(self.parse_expression()) self.stream.expect("rbracket") return nodes.List(items, lineno=token.lineno)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L744-L754
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
100
[]
0
true
95.881732
11
4
100
0
def parse_list(self) -> nodes.List: token = self.stream.expect("lbracket") items: t.List[nodes.Expr] = [] while self.stream.current.type != "rbracket": if items: self.stream.expect("comma") if self.stream.current.type == "rbracket": break items.append(self.parse_expression()) self.stream.expect("rbracket") return nodes.List(items, lineno=token.lineno)
27,812
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_dict
(self)
return nodes.Dict(items, lineno=token.lineno)
756
769
def parse_dict(self) -> nodes.Dict: token = self.stream.expect("lbrace") items: t.List[nodes.Pair] = [] while self.stream.current.type != "rbrace": if items: self.stream.expect("comma") if self.stream.current.type == "rbrace": break key = self.parse_expression() self.stream.expect("colon") value = self.parse_expression() items.append(nodes.Pair(key, value, lineno=key.lineno)) self.stream.expect("rbrace") return nodes.Dict(items, lineno=token.lineno)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L756-L769
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]
100
[]
0
true
95.881732
14
4
100
0
def parse_dict(self) -> nodes.Dict: token = self.stream.expect("lbrace") items: t.List[nodes.Pair] = [] while self.stream.current.type != "rbrace": if items: self.stream.expect("comma") if self.stream.current.type == "rbrace": break key = self.parse_expression() self.stream.expect("colon") value = self.parse_expression() items.append(nodes.Pair(key, value, lineno=key.lineno)) self.stream.expect("rbrace") return nodes.Dict(items, lineno=token.lineno)
27,813
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_postfix
(self, node: nodes.Expr)
return node
771
782
def parse_postfix(self, node: nodes.Expr) -> nodes.Expr: while True: token_type = self.stream.current.type if token_type == "dot" or token_type == "lbracket": node = self.parse_subscript(node) # calls are valid both after postfix expressions (getattr # and getitem) as well as filters and tests elif token_type == "lparen": node = self.parse_call(node) else: break return node
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L771-L782
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11 ]
91.666667
[]
0
false
95.881732
12
5
100
0
def parse_postfix(self, node: nodes.Expr) -> nodes.Expr: while True: token_type = self.stream.current.type if token_type == "dot" or token_type == "lbracket": node = self.parse_subscript(node) # calls are valid both after postfix expressions (getattr # and getitem) as well as filters and tests elif token_type == "lparen": node = self.parse_call(node) else: break return node
27,814
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_filter_expr
(self, node: nodes.Expr)
return node
784
797
def parse_filter_expr(self, node: nodes.Expr) -> nodes.Expr: while True: token_type = self.stream.current.type if token_type == "pipe": node = self.parse_filter(node) # type: ignore elif token_type == "name" and self.stream.current.value == "is": node = self.parse_test(node) # calls are valid both after postfix expressions (getattr # and getitem) as well as filters and tests elif token_type == "lparen": node = self.parse_call(node) else: break return node
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L784-L797
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13 ]
92.857143
[]
0
false
95.881732
14
6
100
0
def parse_filter_expr(self, node: nodes.Expr) -> nodes.Expr: while True: token_type = self.stream.current.type if token_type == "pipe": node = self.parse_filter(node) # type: ignore elif token_type == "name" and self.stream.current.value == "is": node = self.parse_test(node) # calls are valid both after postfix expressions (getattr # and getitem) as well as filters and tests elif token_type == "lparen": node = self.parse_call(node) else: break return node
27,815
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_subscript
( self, node: nodes.Expr )
799
828
def parse_subscript( self, node: nodes.Expr ) -> t.Union[nodes.Getattr, nodes.Getitem]: token = next(self.stream) arg: nodes.Expr if token.type == "dot": attr_token = self.stream.current next(self.stream) if attr_token.type == "name": return nodes.Getattr( node, attr_token.value, "load", lineno=token.lineno ) elif attr_token.type != "integer": self.fail("expected name or number", attr_token.lineno) arg = nodes.Const(attr_token.value, lineno=attr_token.lineno) return nodes.Getitem(node, arg, "load", lineno=token.lineno) if token.type == "lbracket": args: t.List[nodes.Expr] = [] while self.stream.current.type != "rbracket": if args: self.stream.expect("comma") args.append(self.parse_subscribed()) self.stream.expect("rbracket") if len(args) == 1: arg = args[0] else: arg = nodes.Tuple(args, "load", lineno=token.lineno) return nodes.Getitem(node, arg, "load", lineno=token.lineno) self.fail("expected subscript expression", token.lineno)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L799-L828
42
[ 0, 3, 5, 6, 7, 8, 9, 10, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 28 ]
73.333333
[ 14, 29 ]
6.666667
false
95.881732
30
8
93.333333
0
def parse_subscript( self, node: nodes.Expr ) -> t.Union[nodes.Getattr, nodes.Getitem]: token = next(self.stream) arg: nodes.Expr if token.type == "dot": attr_token = self.stream.current next(self.stream) if attr_token.type == "name": return nodes.Getattr( node, attr_token.value, "load", lineno=token.lineno ) elif attr_token.type != "integer": self.fail("expected name or number", attr_token.lineno) arg = nodes.Const(attr_token.value, lineno=attr_token.lineno) return nodes.Getitem(node, arg, "load", lineno=token.lineno) if token.type == "lbracket": args: t.List[nodes.Expr] = [] while self.stream.current.type != "rbracket": if args: self.stream.expect("comma") args.append(self.parse_subscribed()) self.stream.expect("rbracket") if len(args) == 1: arg = args[0] else: arg = nodes.Tuple(args, "load", lineno=token.lineno) return nodes.Getitem(node, arg, "load", lineno=token.lineno) self.fail("expected subscript expression", token.lineno)
27,816
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_subscribed
(self)
return nodes.Slice(lineno=lineno, *args)
830
860
def parse_subscribed(self) -> nodes.Expr: lineno = self.stream.current.lineno args: t.List[t.Optional[nodes.Expr]] if self.stream.current.type == "colon": next(self.stream) args = [None] else: node = self.parse_expression() if self.stream.current.type != "colon": return node next(self.stream) args = [node] if self.stream.current.type == "colon": args.append(None) elif self.stream.current.type not in ("rbracket", "comma"): args.append(self.parse_expression()) else: args.append(None) if self.stream.current.type == "colon": next(self.stream) if self.stream.current.type not in ("rbracket", "comma"): args.append(self.parse_expression()) else: args.append(None) else: args.append(None) return nodes.Slice(lineno=lineno, *args)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L830-L860
42
[ 0, 1, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 20, 21, 22, 23, 24, 28, 29, 30 ]
80.645161
[ 26 ]
3.225806
false
95.881732
31
7
96.774194
0
def parse_subscribed(self) -> nodes.Expr: lineno = self.stream.current.lineno args: t.List[t.Optional[nodes.Expr]] if self.stream.current.type == "colon": next(self.stream) args = [None] else: node = self.parse_expression() if self.stream.current.type != "colon": return node next(self.stream) args = [node] if self.stream.current.type == "colon": args.append(None) elif self.stream.current.type not in ("rbracket", "comma"): args.append(self.parse_expression()) else: args.append(None) if self.stream.current.type == "colon": next(self.stream) if self.stream.current.type not in ("rbracket", "comma"): args.append(self.parse_expression()) else: args.append(None) else: args.append(None) return nodes.Slice(lineno=lineno, *args)
27,817
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_call_args
(self)
return args, kwargs, dyn_args, dyn_kwargs
862
909
def parse_call_args(self) -> t.Tuple: token = self.stream.expect("lparen") args = [] kwargs = [] dyn_args = None dyn_kwargs = None require_comma = False def ensure(expr: bool) -> None: if not expr: self.fail("invalid syntax for function call expression", token.lineno) while self.stream.current.type != "rparen": if require_comma: self.stream.expect("comma") # support for trailing comma if self.stream.current.type == "rparen": break if self.stream.current.type == "mul": ensure(dyn_args is None and dyn_kwargs is None) next(self.stream) dyn_args = self.parse_expression() elif self.stream.current.type == "pow": ensure(dyn_kwargs is None) next(self.stream) dyn_kwargs = self.parse_expression() else: if ( self.stream.current.type == "name" and self.stream.look().type == "assign" ): # Parsing a kwarg ensure(dyn_kwargs is None) key = self.stream.current.value self.stream.skip(2) value = self.parse_expression() kwargs.append(nodes.Keyword(key, value, lineno=value.lineno)) else: # Parsing an arg ensure(dyn_args is None and dyn_kwargs is None and not kwargs) args.append(self.parse_expression()) require_comma = True self.stream.expect("rparen") return args, kwargs, dyn_args, dyn_kwargs
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L862-L909
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 33, 34, 35, 36, 37, 38, 40, 41, 42, 43, 44, 45, 46, 47 ]
87.5
[ 18 ]
2.083333
false
95.881732
48
13
97.916667
0
def parse_call_args(self) -> t.Tuple: token = self.stream.expect("lparen") args = [] kwargs = [] dyn_args = None dyn_kwargs = None require_comma = False def ensure(expr: bool) -> None: if not expr: self.fail("invalid syntax for function call expression", token.lineno) while self.stream.current.type != "rparen": if require_comma: self.stream.expect("comma") # support for trailing comma if self.stream.current.type == "rparen": break if self.stream.current.type == "mul": ensure(dyn_args is None and dyn_kwargs is None) next(self.stream) dyn_args = self.parse_expression() elif self.stream.current.type == "pow": ensure(dyn_kwargs is None) next(self.stream) dyn_kwargs = self.parse_expression() else: if ( self.stream.current.type == "name" and self.stream.look().type == "assign" ): # Parsing a kwarg ensure(dyn_kwargs is None) key = self.stream.current.value self.stream.skip(2) value = self.parse_expression() kwargs.append(nodes.Keyword(key, value, lineno=value.lineno)) else: # Parsing an arg ensure(dyn_args is None and dyn_kwargs is None and not kwargs) args.append(self.parse_expression()) require_comma = True self.stream.expect("rparen") return args, kwargs, dyn_args, dyn_kwargs
27,818
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_call
(self, node: nodes.Expr)
return nodes.Call(node, args, kwargs, dyn_args, dyn_kwargs, lineno=token.lineno)
911
916
def parse_call(self, node: nodes.Expr) -> nodes.Call: # The lparen will be expected in parse_call_args, but the lineno # needs to be recorded before the stream is advanced. token = self.stream.current args, kwargs, dyn_args, dyn_kwargs = self.parse_call_args() return nodes.Call(node, args, kwargs, dyn_args, dyn_kwargs, lineno=token.lineno)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L911-L916
42
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
95.881732
6
1
100
0
def parse_call(self, node: nodes.Expr) -> nodes.Call: # The lparen will be expected in parse_call_args, but the lineno # needs to be recorded before the stream is advanced. token = self.stream.current args, kwargs, dyn_args, dyn_kwargs = self.parse_call_args() return nodes.Call(node, args, kwargs, dyn_args, dyn_kwargs, lineno=token.lineno)
27,819
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse_filter
( self, node: t.Optional[nodes.Expr], start_inline: bool = False )
return node
918
939
def parse_filter( self, node: t.Optional[nodes.Expr], start_inline: bool = False ) -> t.Optional[nodes.Expr]: while self.stream.current.type == "pipe" or start_inline: if not start_inline: next(self.stream) token = self.stream.expect("name") name = token.value while self.stream.current.type == "dot": next(self.stream) name += "." + self.stream.expect("name").value if self.stream.current.type == "lparen": args, kwargs, dyn_args, dyn_kwargs = self.parse_call_args() else: args = [] kwargs = [] dyn_args = dyn_kwargs = None node = nodes.Filter( node, name, args, kwargs, dyn_args, dyn_kwargs, lineno=token.lineno ) start_inline = False return node
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L918-L939
42
[ 0, 3, 4, 5, 6, 7, 8, 11, 12, 14, 15, 16, 17, 20, 21 ]
68.181818
[ 9, 10 ]
9.090909
false
95.881732
22
6
90.909091
0
def parse_filter( self, node: t.Optional[nodes.Expr], start_inline: bool = False ) -> t.Optional[nodes.Expr]: while self.stream.current.type == "pipe" or start_inline: if not start_inline: next(self.stream) token = self.stream.expect("name") name = token.value while self.stream.current.type == "dot": next(self.stream) name += "." + self.stream.expect("name").value if self.stream.current.type == "lparen": args, kwargs, dyn_args, dyn_kwargs = self.parse_call_args() else: args = [] kwargs = [] dyn_args = dyn_kwargs = None node = nodes.Filter( node, name, args, kwargs, dyn_args, dyn_kwargs, lineno=token.lineno ) start_inline = False return node
27,820
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.subparse
( self, end_tokens: t.Optional[t.Tuple[str, ...]] = None )
return body
979
1,026
def subparse( self, end_tokens: t.Optional[t.Tuple[str, ...]] = None ) -> t.List[nodes.Node]: body: t.List[nodes.Node] = [] data_buffer: t.List[nodes.Node] = [] add_data = data_buffer.append if end_tokens is not None: self._end_token_stack.append(end_tokens) def flush_data() -> None: if data_buffer: lineno = data_buffer[0].lineno body.append(nodes.Output(data_buffer[:], lineno=lineno)) del data_buffer[:] try: while self.stream: token = self.stream.current if token.type == "data": if token.value: add_data(nodes.TemplateData(token.value, lineno=token.lineno)) next(self.stream) elif token.type == "variable_begin": next(self.stream) add_data(self.parse_tuple(with_condexpr=True)) self.stream.expect("variable_end") elif token.type == "block_begin": flush_data() next(self.stream) if end_tokens is not None and self.stream.current.test_any( *end_tokens ): return body rv = self.parse_statement() if isinstance(rv, list): body.extend(rv) else: body.append(rv) self.stream.expect("block_end") else: raise AssertionError("internal parsing error") flush_data() finally: if end_tokens is not None: self._end_token_stack.pop() return body
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L979-L1026
42
[ 0, 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, 33, 34, 35, 36, 38, 39, 42, 43, 45, 46, 47 ]
83.333333
[ 41 ]
2.083333
false
95.881732
48
13
97.916667
0
def subparse( self, end_tokens: t.Optional[t.Tuple[str, ...]] = None ) -> t.List[nodes.Node]: body: t.List[nodes.Node] = [] data_buffer: t.List[nodes.Node] = [] add_data = data_buffer.append if end_tokens is not None: self._end_token_stack.append(end_tokens) def flush_data() -> None: if data_buffer: lineno = data_buffer[0].lineno body.append(nodes.Output(data_buffer[:], lineno=lineno)) del data_buffer[:] try: while self.stream: token = self.stream.current if token.type == "data": if token.value: add_data(nodes.TemplateData(token.value, lineno=token.lineno)) next(self.stream) elif token.type == "variable_begin": next(self.stream) add_data(self.parse_tuple(with_condexpr=True)) self.stream.expect("variable_end") elif token.type == "block_begin": flush_data() next(self.stream) if end_tokens is not None and self.stream.current.test_any( *end_tokens ): return body rv = self.parse_statement() if isinstance(rv, list): body.extend(rv) else: body.append(rv) self.stream.expect("block_end") else: raise AssertionError("internal parsing error") flush_data() finally: if end_tokens is not None: self._end_token_stack.pop() return body
27,821
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/parser.py
Parser.parse
(self)
return result
Parse the whole template into a `Template` node.
Parse the whole template into a `Template` node.
1,028
1,032
def parse(self) -> nodes.Template: """Parse the whole template into a `Template` node.""" result = nodes.Template(self.subparse(), lineno=1) result.set_environment(self.environment) return result
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/parser.py#L1028-L1032
42
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
95.881732
5
1
100
1
def parse(self) -> nodes.Template: result = nodes.Template(self.subparse(), lineno=1) result.set_environment(self.environment) return result
27,822
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
find_symbols
( nodes: t.Iterable[nodes.Node], parent_symbols: t.Optional["Symbols"] = None )
return sym
12
19
def find_symbols( nodes: t.Iterable[nodes.Node], parent_symbols: t.Optional["Symbols"] = None ) -> "Symbols": sym = Symbols(parent=parent_symbols) visitor = FrameSymbolVisitor(sym) for node in nodes: visitor.visit(node) return sym
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L12-L19
42
[ 0 ]
12.5
[ 3, 4, 5, 6, 7 ]
62.5
false
93.114754
8
2
37.5
0
def find_symbols( nodes: t.Iterable[nodes.Node], parent_symbols: t.Optional["Symbols"] = None ) -> "Symbols": sym = Symbols(parent=parent_symbols) visitor = FrameSymbolVisitor(sym) for node in nodes: visitor.visit(node) return sym
27,823
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
symbols_for_node
( node: nodes.Node, parent_symbols: t.Optional["Symbols"] = None )
return sym
22
27
def symbols_for_node( node: nodes.Node, parent_symbols: t.Optional["Symbols"] = None ) -> "Symbols": sym = Symbols(parent=parent_symbols) sym.analyze_node(node) return sym
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L22-L27
42
[ 0, 3, 4, 5 ]
66.666667
[]
0
false
93.114754
6
1
100
0
def symbols_for_node( node: nodes.Node, parent_symbols: t.Optional["Symbols"] = None ) -> "Symbols": sym = Symbols(parent=parent_symbols) sym.analyze_node(node) return sym
27,824
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
Symbols.__init__
( self, parent: t.Optional["Symbols"] = None, level: t.Optional[int] = None )
31
44
def __init__( self, parent: t.Optional["Symbols"] = None, level: t.Optional[int] = None ) -> None: if level is None: if parent is None: level = 0 else: level = parent.level + 1 self.level: int = level self.parent = parent self.refs: t.Dict[str, str] = {} self.loads: t.Dict[str, t.Any] = {} self.stores: t.Set[str] = set()
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L31-L44
42
[ 0, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13 ]
78.571429
[]
0
false
93.114754
14
3
100
0
def __init__( self, parent: t.Optional["Symbols"] = None, level: t.Optional[int] = None ) -> None: if level is None: if parent is None: level = 0 else: level = parent.level + 1 self.level: int = level self.parent = parent self.refs: t.Dict[str, str] = {} self.loads: t.Dict[str, t.Any] = {} self.stores: t.Set[str] = set()
27,825
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
Symbols.analyze_node
(self, node: nodes.Node, **kwargs: t.Any)
46
48
def analyze_node(self, node: nodes.Node, **kwargs: t.Any) -> None: visitor = RootVisitor(self) visitor.visit(node, **kwargs)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L46-L48
42
[ 0, 1, 2 ]
100
[]
0
true
93.114754
3
1
100
0
def analyze_node(self, node: nodes.Node, **kwargs: t.Any) -> None: visitor = RootVisitor(self) visitor.visit(node, **kwargs)
27,826
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
Symbols._define_ref
( self, name: str, load: t.Optional[t.Tuple[str, t.Optional[str]]] = None )
return ident
50
57
def _define_ref( self, name: str, load: t.Optional[t.Tuple[str, t.Optional[str]]] = None ) -> str: ident = f"l_{self.level}_{name}" self.refs[name] = ident if load is not None: self.loads[ident] = load return ident
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L50-L57
42
[ 0, 3, 4, 5, 6, 7 ]
75
[]
0
false
93.114754
8
2
100
0
def _define_ref( self, name: str, load: t.Optional[t.Tuple[str, t.Optional[str]]] = None ) -> str: ident = f"l_{self.level}_{name}" self.refs[name] = ident if load is not None: self.loads[ident] = load return ident
27,827
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
Symbols.find_load
(self, target: str)
return None
59
66
def find_load(self, target: str) -> t.Optional[t.Any]: if target in self.loads: return self.loads[target] if self.parent is not None: return self.parent.find_load(target) return None
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L59-L66
42
[ 0, 1, 2, 3, 4, 5, 6 ]
87.5
[ 7 ]
12.5
false
93.114754
8
3
87.5
0
def find_load(self, target: str) -> t.Optional[t.Any]: if target in self.loads: return self.loads[target] if self.parent is not None: return self.parent.find_load(target) return None
27,828
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
Symbols.find_ref
(self, name: str)
return None
68
75
def find_ref(self, name: str) -> t.Optional[str]: if name in self.refs: return self.refs[name] if self.parent is not None: return self.parent.find_ref(name) return None
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L68-L75
42
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
93.114754
8
3
100
0
def find_ref(self, name: str) -> t.Optional[str]: if name in self.refs: return self.refs[name] if self.parent is not None: return self.parent.find_ref(name) return None
27,829
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
Symbols.ref
(self, name: str)
return rv
77
84
def ref(self, name: str) -> str: rv = self.find_ref(name) if rv is None: raise AssertionError( "Tried to resolve a name to a reference that was" f" unknown to the frame ({name!r})" ) return rv
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L77-L84
42
[ 0, 1, 2, 7 ]
50
[ 3 ]
12.5
false
93.114754
8
2
87.5
0
def ref(self, name: str) -> str: rv = self.find_ref(name) if rv is None: raise AssertionError( "Tried to resolve a name to a reference that was" f" unknown to the frame ({name!r})" ) return rv
27,830
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
Symbols.copy
(self)
return rv
86
92
def copy(self) -> "Symbols": rv = object.__new__(self.__class__) rv.__dict__.update(self.__dict__) rv.refs = self.refs.copy() rv.loads = self.loads.copy() rv.stores = self.stores.copy() return rv
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L86-L92
42
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
93.114754
7
1
100
0
def copy(self) -> "Symbols": rv = object.__new__(self.__class__) rv.__dict__.update(self.__dict__) rv.refs = self.refs.copy() rv.loads = self.loads.copy() rv.stores = self.stores.copy() return rv
27,831
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
Symbols.store
(self, name: str)
94
110
def store(self, name: str) -> None: self.stores.add(name) # If we have not see the name referenced yet, we need to figure # out what to set it to. if name not in self.refs: # If there is a parent scope we check if the name has a # reference there. If it does it means we might have to alias # to a variable there. if self.parent is not None: outer_ref = self.parent.find_ref(name) if outer_ref is not None: self._define_ref(name, load=(VAR_LOAD_ALIAS, outer_ref)) return # Otherwise we can just set it to undefined. self._define_ref(name, load=(VAR_LOAD_UNDEFINED, None))
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L94-L110
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]
100
[]
0
true
93.114754
17
4
100
0
def store(self, name: str) -> None: self.stores.add(name) # If we have not see the name referenced yet, we need to figure # out what to set it to. if name not in self.refs: # If there is a parent scope we check if the name has a # reference there. If it does it means we might have to alias # to a variable there. if self.parent is not None: outer_ref = self.parent.find_ref(name) if outer_ref is not None: self._define_ref(name, load=(VAR_LOAD_ALIAS, outer_ref)) return # Otherwise we can just set it to undefined. self._define_ref(name, load=(VAR_LOAD_UNDEFINED, None))
27,832
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
Symbols.declare_parameter
(self, name: str)
return self._define_ref(name, load=(VAR_LOAD_PARAMETER, None))
112
114
def declare_parameter(self, name: str) -> str: self.stores.add(name) return self._define_ref(name, load=(VAR_LOAD_PARAMETER, None))
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L112-L114
42
[ 0, 1, 2 ]
100
[]
0
true
93.114754
3
1
100
0
def declare_parameter(self, name: str) -> str: self.stores.add(name) return self._define_ref(name, load=(VAR_LOAD_PARAMETER, None))
27,833
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
Symbols.load
(self, name: str)
116
118
def load(self, name: str) -> None: if self.find_ref(name) is None: self._define_ref(name, load=(VAR_LOAD_RESOLVE, name))
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L116-L118
42
[ 0, 1, 2 ]
100
[]
0
true
93.114754
3
2
100
0
def load(self, name: str) -> None: if self.find_ref(name) is None: self._define_ref(name, load=(VAR_LOAD_RESOLVE, name))
27,834
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
Symbols.branch_update
(self, branch_symbols: t.Sequence["Symbols"])
120
145
def branch_update(self, branch_symbols: t.Sequence["Symbols"]) -> None: stores: t.Dict[str, int] = {} for branch in branch_symbols: for target in branch.stores: if target in self.stores: continue stores[target] = stores.get(target, 0) + 1 for sym in branch_symbols: self.refs.update(sym.refs) self.loads.update(sym.loads) self.stores.update(sym.stores) for name, branch_count in stores.items(): if branch_count == len(branch_symbols): continue target = self.find_ref(name) # type: ignore assert target is not None, "should not happen" if self.parent is not None: outer_target = self.parent.find_ref(name) if outer_target is not None: self.loads[target] = (VAR_LOAD_ALIAS, outer_target) continue self.loads[target] = (VAR_LOAD_RESOLVE, name)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L120-L145
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ]
96.153846
[ 15 ]
3.846154
false
93.114754
26
10
96.153846
0
def branch_update(self, branch_symbols: t.Sequence["Symbols"]) -> None: stores: t.Dict[str, int] = {} for branch in branch_symbols: for target in branch.stores: if target in self.stores: continue stores[target] = stores.get(target, 0) + 1 for sym in branch_symbols: self.refs.update(sym.refs) self.loads.update(sym.loads) self.stores.update(sym.stores) for name, branch_count in stores.items(): if branch_count == len(branch_symbols): continue target = self.find_ref(name) # type: ignore assert target is not None, "should not happen" if self.parent is not None: outer_target = self.parent.find_ref(name) if outer_target is not None: self.loads[target] = (VAR_LOAD_ALIAS, outer_target) continue self.loads[target] = (VAR_LOAD_RESOLVE, name)
27,835
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
Symbols.dump_stores
(self)
return rv
147
158
def dump_stores(self) -> t.Dict[str, str]: rv: t.Dict[str, str] = {} node: t.Optional["Symbols"] = self while node is not None: for name in sorted(node.stores): if name not in rv: rv[name] = self.find_ref(name) # type: ignore node = node.parent return rv
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L147-L158
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
100
[]
0
true
93.114754
12
4
100
0
def dump_stores(self) -> t.Dict[str, str]: rv: t.Dict[str, str] = {} node: t.Optional["Symbols"] = self while node is not None: for name in sorted(node.stores): if name not in rv: rv[name] = self.find_ref(name) # type: ignore node = node.parent return rv
27,836
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
Symbols.dump_param_targets
(self)
return rv
160
171
def dump_param_targets(self) -> t.Set[str]: rv = set() node: t.Optional["Symbols"] = self while node is not None: for target, (instr, _) in self.loads.items(): if instr == VAR_LOAD_PARAMETER: rv.add(target) node = node.parent return rv
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L160-L171
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
100
[]
0
true
93.114754
12
4
100
0
def dump_param_targets(self) -> t.Set[str]: rv = set() node: t.Optional["Symbols"] = self while node is not None: for target, (instr, _) in self.loads.items(): if instr == VAR_LOAD_PARAMETER: rv.add(target) node = node.parent return rv
27,837
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
RootVisitor.__init__
(self, symbols: "Symbols")
175
176
def __init__(self, symbols: "Symbols") -> None: self.sym_visitor = FrameSymbolVisitor(symbols)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L175-L176
42
[ 0, 1 ]
100
[]
0
true
93.114754
2
1
100
0
def __init__(self, symbols: "Symbols") -> None: self.sym_visitor = FrameSymbolVisitor(symbols)
27,838
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
RootVisitor._simple_visit
(self, node: nodes.Node, **kwargs: t.Any)
178
180
def _simple_visit(self, node: nodes.Node, **kwargs: t.Any) -> None: for child in node.iter_child_nodes(): self.sym_visitor.visit(child)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L178-L180
42
[ 0, 1, 2 ]
100
[]
0
true
93.114754
3
2
100
0
def _simple_visit(self, node: nodes.Node, **kwargs: t.Any) -> None: for child in node.iter_child_nodes(): self.sym_visitor.visit(child)
27,839
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
RootVisitor.visit_AssignBlock
(self, node: nodes.AssignBlock, **kwargs: t.Any)
190
192
def visit_AssignBlock(self, node: nodes.AssignBlock, **kwargs: t.Any) -> None: for child in node.body: self.sym_visitor.visit(child)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L190-L192
42
[ 0, 1, 2 ]
100
[]
0
true
93.114754
3
2
100
0
def visit_AssignBlock(self, node: nodes.AssignBlock, **kwargs: t.Any) -> None: for child in node.body: self.sym_visitor.visit(child)
27,840
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
RootVisitor.visit_CallBlock
(self, node: nodes.CallBlock, **kwargs: t.Any)
194
196
def visit_CallBlock(self, node: nodes.CallBlock, **kwargs: t.Any) -> None: for child in node.iter_child_nodes(exclude=("call",)): self.sym_visitor.visit(child)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L194-L196
42
[ 0, 1, 2 ]
100
[]
0
true
93.114754
3
2
100
0
def visit_CallBlock(self, node: nodes.CallBlock, **kwargs: t.Any) -> None: for child in node.iter_child_nodes(exclude=("call",)): self.sym_visitor.visit(child)
27,841
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
RootVisitor.visit_OverlayScope
(self, node: nodes.OverlayScope, **kwargs: t.Any)
198
200
def visit_OverlayScope(self, node: nodes.OverlayScope, **kwargs: t.Any) -> None: for child in node.body: self.sym_visitor.visit(child)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L198-L200
42
[ 0, 1, 2 ]
100
[]
0
true
93.114754
3
2
100
0
def visit_OverlayScope(self, node: nodes.OverlayScope, **kwargs: t.Any) -> None: for child in node.body: self.sym_visitor.visit(child)
27,842
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
RootVisitor.visit_For
( self, node: nodes.For, for_branch: str = "body", **kwargs: t.Any )
202
220
def visit_For( self, node: nodes.For, for_branch: str = "body", **kwargs: t.Any ) -> None: if for_branch == "body": self.sym_visitor.visit(node.target, store_as_param=True) branch = node.body elif for_branch == "else": branch = node.else_ elif for_branch == "test": self.sym_visitor.visit(node.target, store_as_param=True) if node.test is not None: self.sym_visitor.visit(node.test) return else: raise RuntimeError("Unknown for branch") if branch: for item in branch: self.sym_visitor.visit(item)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L202-L220
42
[ 0, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 15, 16, 17, 18 ]
78.947368
[ 14 ]
5.263158
false
93.114754
19
7
94.736842
0
def visit_For( self, node: nodes.For, for_branch: str = "body", **kwargs: t.Any ) -> None: if for_branch == "body": self.sym_visitor.visit(node.target, store_as_param=True) branch = node.body elif for_branch == "else": branch = node.else_ elif for_branch == "test": self.sym_visitor.visit(node.target, store_as_param=True) if node.test is not None: self.sym_visitor.visit(node.test) return else: raise RuntimeError("Unknown for branch") if branch: for item in branch: self.sym_visitor.visit(item)
27,843
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
RootVisitor.visit_With
(self, node: nodes.With, **kwargs: t.Any)
222
226
def visit_With(self, node: nodes.With, **kwargs: t.Any) -> None: for target in node.targets: self.sym_visitor.visit(target) for child in node.body: self.sym_visitor.visit(child)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L222-L226
42
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
93.114754
5
3
100
0
def visit_With(self, node: nodes.With, **kwargs: t.Any) -> None: for target in node.targets: self.sym_visitor.visit(target) for child in node.body: self.sym_visitor.visit(child)
27,844
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
FrameSymbolVisitor.__init__
(self, symbols: "Symbols")
235
236
def __init__(self, symbols: "Symbols") -> None: self.symbols = symbols
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L235-L236
42
[ 0, 1 ]
100
[]
0
true
93.114754
2
1
100
0
def __init__(self, symbols: "Symbols") -> None: self.symbols = symbols
27,845
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
FrameSymbolVisitor.visit_Name
( self, node: nodes.Name, store_as_param: bool = False, **kwargs: t.Any )
All assignments to names go through this function.
All assignments to names go through this function.
238
247
def visit_Name( self, node: nodes.Name, store_as_param: bool = False, **kwargs: t.Any ) -> None: """All assignments to names go through this function.""" if store_as_param or node.ctx == "param": self.symbols.declare_parameter(node.name) elif node.ctx == "store": self.symbols.store(node.name) elif node.ctx == "load": self.symbols.load(node.name)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L238-L247
42
[ 0, 3, 4, 5, 6, 7, 8, 9 ]
80
[]
0
false
93.114754
10
5
100
1
def visit_Name( self, node: nodes.Name, store_as_param: bool = False, **kwargs: t.Any ) -> None: if store_as_param or node.ctx == "param": self.symbols.declare_parameter(node.name) elif node.ctx == "store": self.symbols.store(node.name) elif node.ctx == "load": self.symbols.load(node.name)
27,846
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
FrameSymbolVisitor.visit_NSRef
(self, node: nodes.NSRef, **kwargs: t.Any)
249
250
def visit_NSRef(self, node: nodes.NSRef, **kwargs: t.Any) -> None: self.symbols.load(node.name)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L249-L250
42
[ 0, 1 ]
100
[]
0
true
93.114754
2
1
100
0
def visit_NSRef(self, node: nodes.NSRef, **kwargs: t.Any) -> None: self.symbols.load(node.name)
27,847
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
FrameSymbolVisitor.visit_If
(self, node: nodes.If, **kwargs: t.Any)
252
268
def visit_If(self, node: nodes.If, **kwargs: t.Any) -> None: self.visit(node.test, **kwargs) original_symbols = self.symbols def inner_visit(nodes: t.Iterable[nodes.Node]) -> "Symbols": self.symbols = rv = original_symbols.copy() for subnode in nodes: self.visit(subnode, **kwargs) self.symbols = original_symbols return rv body_symbols = inner_visit(node.body) elif_symbols = inner_visit(node.elif_) else_symbols = inner_visit(node.else_ or ()) self.symbols.branch_update([body_symbols, elif_symbols, else_symbols])
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L252-L268
42
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]
100
[]
0
true
93.114754
17
4
100
0
def visit_If(self, node: nodes.If, **kwargs: t.Any) -> None: self.visit(node.test, **kwargs) original_symbols = self.symbols def inner_visit(nodes: t.Iterable[nodes.Node]) -> "Symbols": self.symbols = rv = original_symbols.copy() for subnode in nodes: self.visit(subnode, **kwargs) self.symbols = original_symbols return rv body_symbols = inner_visit(node.body) elif_symbols = inner_visit(node.elif_) else_symbols = inner_visit(node.else_ or ()) self.symbols.branch_update([body_symbols, elif_symbols, else_symbols])
27,848
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
FrameSymbolVisitor.visit_Macro
(self, node: nodes.Macro, **kwargs: t.Any)
270
271
def visit_Macro(self, node: nodes.Macro, **kwargs: t.Any) -> None: self.symbols.store(node.name)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L270-L271
42
[ 0, 1 ]
100
[]
0
true
93.114754
2
1
100
0
def visit_Macro(self, node: nodes.Macro, **kwargs: t.Any) -> None: self.symbols.store(node.name)
27,849
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
FrameSymbolVisitor.visit_Import
(self, node: nodes.Import, **kwargs: t.Any)
273
275
def visit_Import(self, node: nodes.Import, **kwargs: t.Any) -> None: self.generic_visit(node, **kwargs) self.symbols.store(node.target)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L273-L275
42
[ 0, 1, 2 ]
100
[]
0
true
93.114754
3
1
100
0
def visit_Import(self, node: nodes.Import, **kwargs: t.Any) -> None: self.generic_visit(node, **kwargs) self.symbols.store(node.target)
27,850
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
FrameSymbolVisitor.visit_FromImport
(self, node: nodes.FromImport, **kwargs: t.Any)
277
284
def visit_FromImport(self, node: nodes.FromImport, **kwargs: t.Any) -> None: self.generic_visit(node, **kwargs) for name in node.names: if isinstance(name, tuple): self.symbols.store(name[1]) else: self.symbols.store(name)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L277-L284
42
[ 0, 1, 2, 3, 4, 7 ]
75
[ 5 ]
12.5
false
93.114754
8
3
87.5
0
def visit_FromImport(self, node: nodes.FromImport, **kwargs: t.Any) -> None: self.generic_visit(node, **kwargs) for name in node.names: if isinstance(name, tuple): self.symbols.store(name[1]) else: self.symbols.store(name)
27,851
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
FrameSymbolVisitor.visit_Assign
(self, node: nodes.Assign, **kwargs: t.Any)
Visit assignments in the correct order.
Visit assignments in the correct order.
286
289
def visit_Assign(self, node: nodes.Assign, **kwargs: t.Any) -> None: """Visit assignments in the correct order.""" self.visit(node.node, **kwargs) self.visit(node.target, **kwargs)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L286-L289
42
[ 0, 1, 2, 3 ]
100
[]
0
true
93.114754
4
1
100
1
def visit_Assign(self, node: nodes.Assign, **kwargs: t.Any) -> None: self.visit(node.node, **kwargs) self.visit(node.target, **kwargs)
27,852
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
FrameSymbolVisitor.visit_For
(self, node: nodes.For, **kwargs: t.Any)
Visiting stops at for blocks. However the block sequence is visited as part of the outer scope.
Visiting stops at for blocks. However the block sequence is visited as part of the outer scope.
291
295
def visit_For(self, node: nodes.For, **kwargs: t.Any) -> None: """Visiting stops at for blocks. However the block sequence is visited as part of the outer scope. """ self.visit(node.iter, **kwargs)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L291-L295
42
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
93.114754
5
1
100
2
def visit_For(self, node: nodes.For, **kwargs: t.Any) -> None: self.visit(node.iter, **kwargs)
27,853
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
FrameSymbolVisitor.visit_CallBlock
(self, node: nodes.CallBlock, **kwargs: t.Any)
297
298
def visit_CallBlock(self, node: nodes.CallBlock, **kwargs: t.Any) -> None: self.visit(node.call, **kwargs)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L297-L298
42
[ 0, 1 ]
100
[]
0
true
93.114754
2
1
100
0
def visit_CallBlock(self, node: nodes.CallBlock, **kwargs: t.Any) -> None: self.visit(node.call, **kwargs)
27,854
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
FrameSymbolVisitor.visit_FilterBlock
(self, node: nodes.FilterBlock, **kwargs: t.Any)
300
301
def visit_FilterBlock(self, node: nodes.FilterBlock, **kwargs: t.Any) -> None: self.visit(node.filter, **kwargs)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L300-L301
42
[ 0, 1 ]
100
[]
0
true
93.114754
2
1
100
0
def visit_FilterBlock(self, node: nodes.FilterBlock, **kwargs: t.Any) -> None: self.visit(node.filter, **kwargs)
27,855
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
FrameSymbolVisitor.visit_With
(self, node: nodes.With, **kwargs: t.Any)
303
305
def visit_With(self, node: nodes.With, **kwargs: t.Any) -> None: for target in node.values: self.visit(target)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L303-L305
42
[ 0, 1, 2 ]
100
[]
0
true
93.114754
3
2
100
0
def visit_With(self, node: nodes.With, **kwargs: t.Any) -> None: for target in node.values: self.visit(target)
27,856
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
FrameSymbolVisitor.visit_AssignBlock
(self, node: nodes.AssignBlock, **kwargs: t.Any)
Stop visiting at block assigns.
Stop visiting at block assigns.
307
309
def visit_AssignBlock(self, node: nodes.AssignBlock, **kwargs: t.Any) -> None: """Stop visiting at block assigns.""" self.visit(node.target, **kwargs)
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L307-L309
42
[ 0, 1, 2 ]
100
[]
0
true
93.114754
3
1
100
1
def visit_AssignBlock(self, node: nodes.AssignBlock, **kwargs: t.Any) -> None: self.visit(node.target, **kwargs)
27,857
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
FrameSymbolVisitor.visit_Scope
(self, node: nodes.Scope, **kwargs: t.Any)
Stop visiting at scopes.
Stop visiting at scopes.
311
312
def visit_Scope(self, node: nodes.Scope, **kwargs: t.Any) -> None: """Stop visiting at scopes."""
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L311-L312
42
[ 0, 1 ]
100
[]
0
true
93.114754
2
1
100
1
def visit_Scope(self, node: nodes.Scope, **kwargs: t.Any) -> None:
27,858
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
FrameSymbolVisitor.visit_Block
(self, node: nodes.Block, **kwargs: t.Any)
Stop visiting at blocks.
Stop visiting at blocks.
314
315
def visit_Block(self, node: nodes.Block, **kwargs: t.Any) -> None: """Stop visiting at blocks."""
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L314-L315
42
[ 0, 1 ]
100
[]
0
true
93.114754
2
1
100
1
def visit_Block(self, node: nodes.Block, **kwargs: t.Any) -> None:
27,859
pallets/jinja
89eec1c5ee5022342f05c121dccb0e7b8b0ac523
src/jinja2/idtracking.py
FrameSymbolVisitor.visit_OverlayScope
(self, node: nodes.OverlayScope, **kwargs: t.Any)
Do not visit into overlay scopes.
Do not visit into overlay scopes.
317
318
def visit_OverlayScope(self, node: nodes.OverlayScope, **kwargs: t.Any) -> None: """Do not visit into overlay scopes."""
https://github.com/pallets/jinja/blob/89eec1c5ee5022342f05c121dccb0e7b8b0ac523/project42/src/jinja2/idtracking.py#L317-L318
42
[ 0, 1 ]
100
[]
0
true
93.114754
2
1
100
1
def visit_OverlayScope(self, node: nodes.OverlayScope, **kwargs: t.Any) -> None:
27,860