MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / ListComp

Function ListComp

tools/python-3.11.9-amd64/Lib/lib2to3/fixer_util.py:87–109  ·  view source on GitHub ↗

A list comprehension of the form [xp for fp in it if test]. If test is None, the "if test" part is omitted.

(xp, fp, it, test=None)

Source from the content-addressed store, hash-verified

85 return Leaf(token.STRING, string, prefix=prefix)
86
87def ListComp(xp, fp, it, test=None):
88 """A list comprehension of the form [xp for fp in it if test].
89
90 If test is None, the "if test" part is omitted.
91 """
92 xp.prefix = ""
93 fp.prefix = " "
94 it.prefix = " "
95 for_leaf = Leaf(token.NAME, "for")
96 for_leaf.prefix = " "
97 in_leaf = Leaf(token.NAME, "in")
98 in_leaf.prefix = " "
99 inner_args = [for_leaf, fp, in_leaf, it]
100 if test:
101 test.prefix = " "
102 if_leaf = Leaf(token.NAME, "if")
103 if_leaf.prefix = " "
104 inner_args.append(Node(syms.comp_if, [if_leaf, test]))
105 inner = Node(syms.listmaker, [xp, Node(syms.comp_for, inner_args)])
106 return Node(syms.atom,
107 [Leaf(token.LBRACE, "["),
108 inner,
109 Leaf(token.RBRACE, "]")])
110
111def FromImport(package_name, name_leafs):
112 """ Return an import statement in the form:

Callers 2

transformMethod · 0.85
transformMethod · 0.85

Calls 3

LeafClass · 0.85
NodeClass · 0.70
appendMethod · 0.45

Tested by

no test coverage detected