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

Function FromImport

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

Return an import statement in the form: from package import name_leafs

(package_name, name_leafs)

Source from the content-addressed store, hash-verified

109 Leaf(token.RBRACE, "]")])
110
111def FromImport(package_name, name_leafs):
112 """ Return an import statement in the form:
113 from package import name_leafs"""
114 # XXX: May not handle dotted imports properly (eg, package_name='foo.bar')
115 #assert package_name == '.' or '.' not in package_name, "FromImport has "\
116 # "not been tested with dotted package names -- use at your own "\
117 # "peril!"
118
119 for leaf in name_leafs:
120 # Pull the leaves out of their old tree
121 leaf.remove()
122
123 children = [Leaf(token.NAME, "from"),
124 Leaf(token.NAME, package_name, prefix=" "),
125 Leaf(token.NAME, "import", prefix=" "),
126 Node(syms.import_as_names, name_leafs)]
127 imp = Node(syms.import_from, children)
128 return imp
129
130def ImportAndCall(node, results, names):
131 """Returns an import statement and calls a method

Callers 3

transform_memberMethod · 0.90
touch_importFunction · 0.85
transformMethod · 0.85

Calls 3

LeafClass · 0.85
NodeClass · 0.70
removeMethod · 0.45

Tested by

no test coverage detected