本文整理汇总了Python中lib2to3.fixer_util.does_tree_import方法的典型用法代码示例。如果您正苦于以下问题:Python fixer_util.does_tree_import方法的具体用法?Python fixer_util.does_tree_import怎么用?Python fixer_util.does_tree_import使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib2to3.fixer_util
的用法示例。
在下文中一共展示了fixer_util.does_tree_import方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: try_with
# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import does_tree_import [as 别名]
def try_with(self, string):
failing_tests = (("a", "a", "from a import b"),
("a.d", "a", "from a.d import b"),
("d.a", "a", "from d.a import b"),
(None, "a", "import b"),
(None, "a", "import b, c, d"))
for package, name, import_ in failing_tests:
n = self.does_tree_import(package, name, import_ + "\n" + string)
self.assertFalse(n)
n = self.does_tree_import(package, name, string + "\n" + import_)
self.assertFalse(n)
passing_tests = (("a", "a", "from a import a"),
("x", "a", "from x import a"),
("x", "a", "from x import b, c, a, d"),
("x.b", "a", "from x.b import a"),
("x.b", "a", "from x.b import b, c, a, d"),
(None, "a", "import a"),
(None, "a", "import b, c, a, d"))
for package, name, import_ in passing_tests:
n = self.does_tree_import(package, name, import_ + "\n" + string)
self.assertTrue(n)
n = self.does_tree_import(package, name, string + "\n" + import_)
self.assertTrue(n)
示例2: does_tree_import
# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import does_tree_import [as 别名]
def does_tree_import(self, package, name, string):
node = parse(string)
# Find the binding of start -- that's what we'll go from
node = self._find_bind_rec('start', node)
return fixer_util.does_tree_import(package, name, node)
示例3: transform
# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import does_tree_import [as 别名]
def transform(self, node, results):
if does_tree_import('builtins', 'input', node):
return
return super(FixInput, self).transform(node, results)