MCPcopy Create free account
hub / github.com/numpy/numpy / parse_for

Function parse_for

numpy/_build_utils/tempita/_tempita.py:852–878  ·  view source on GitHub ↗
(tokens, name, context)

Source from the content-addressed store, hash-verified

850
851
852def parse_for(tokens, name, context):
853 first, pos = tokens[0]
854 tokens = tokens[1:]
855 context = ("for",) + context
856 content = []
857 assert first.startswith("for "), first
858 first = first.removesuffix(":")
859 first = first[3:].strip()
860 match = in_re.search(first)
861 if not match:
862 raise TemplateError(f'Bad for (no "in") in {first!r}', position=pos, name=name)
863 vars = first[: match.start()]
864 if "(" in vars:
865 raise TemplateError(
866 f"You cannot have () in the variable section of a for loop ({vars!r})",
867 position=pos,
868 name=name,
869 )
870 vars = tuple(v.strip() for v in first[: match.start()].split(",") if v.strip())
871 expr = first[match.end():]
872 while 1:
873 if not tokens:
874 raise TemplateError("No {{endfor}}", position=pos, name=name)
875 if isinstance(tokens[0], tuple) and tokens[0][0] == "endfor":
876 return ("for", pos, vars, expr, content), tokens[1:]
877 next_chunk, tokens = parse_expr(tokens, name, context)
878 content.append(next_chunk)
879
880
881def parse_default(tokens, name, context):

Callers 1

parse_exprFunction · 0.85

Calls 5

TemplateErrorClass · 0.85
parse_exprFunction · 0.85
startswithMethod · 0.80
stripMethod · 0.80
splitMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…