本文整理汇总了Python中importmagic.symbols.Scope.from_source方法的典型用法代码示例。如果您正苦于以下问题:Python Scope.from_source方法的具体用法?Python Scope.from_source怎么用?Python Scope.from_source使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类importmagic.symbols.Scope
的用法示例。
在下文中一共展示了Scope.from_source方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_symbol_from_argument_defaults
# 需要导入模块: from importmagic.symbols import Scope [as 别名]
# 或者: from importmagic.symbols.Scope import from_source [as 别名]
def test_symbol_from_argument_defaults():
src = dedent("""
def f(a, b=os.path, c=os): pass
""")
symbols, _ = Scope.from_source(src).find_unresolved_and_unreferenced_symbols()
assert symbols == set(['os.path', 'os'])
示例2: test_symbol_from_decorator
# 需要导入模块: from importmagic.symbols import Scope [as 别名]
# 或者: from importmagic.symbols.Scope import from_source [as 别名]
def test_symbol_from_decorator():
src = dedent("""
@foo.bar(a=waz)
def bar(): pass
""")
symbols, _ = Scope.from_source(src).find_unresolved_and_unreferenced_symbols()
assert symbols == set(['foo.bar', 'waz'])
示例3: test_import_future_preserved
# 需要导入模块: from importmagic.symbols import Scope [as 别名]
# 或者: from importmagic.symbols.Scope import from_source [as 别名]
def test_import_future_preserved(index):
src = 'from __future__ import absolute_import'
unresolved, unreferenced = Scope.from_source(src).find_unresolved_and_unreferenced_symbols()
assert not unresolved
assert not unreferenced
new_src = update_imports(src, index, unresolved, unreferenced).strip()
assert src == new_src
示例4: test_from_import_as
# 需要导入模块: from importmagic.symbols import Scope [as 别名]
# 或者: from importmagic.symbols.Scope import from_source [as 别名]
def test_from_import_as(index):
src = dedent('''
from clastic import MiddleWare as WebMiddleWare
''').strip()
scope = Scope.from_source(src)
new_src = update_imports(src, index, *scope.find_unresolved_and_unreferenced_symbols())
assert src == new_src.strip()
示例5: test_importer_directives_not_referenced
# 需要导入模块: from importmagic.symbols import Scope [as 别名]
# 或者: from importmagic.symbols.Scope import from_source [as 别名]
def test_importer_directives_not_referenced(index):
src = dedent('''
# Make sure the in thread reactor is installed.
from Tribler.Core.Utilities.twisted_thread import reactor
# importmagic: manage
import re
import sys
print(os.path.basename('moo'))
''').strip()
expected_src = dedent('''
# Make sure the in thread reactor is installed.
from Tribler.Core.Utilities.twisted_thread import reactor
# importmagic: manage
import os.path
print(os.path.basename('moo'))
''').strip()
scope = Scope.from_source(src)
new_src = update_imports(src, index, *scope.find_unresolved_and_unreferenced_symbols()).strip()
assert expected_src == new_src
示例6: test_accepts_unicode_strings
# 需要导入模块: from importmagic.symbols import Scope [as 别名]
# 或者: from importmagic.symbols.Scope import from_source [as 别名]
def test_accepts_unicode_strings():
src = dedent(u("""
# coding: utf-8
foo
""")).strip()
scope = Scope.from_source(src)
unresolved, unreferenced = scope.find_unresolved_and_unreferenced_symbols()
assert unresolved == set(['foo'])
示例7: test_referenced_symbols_from_decorated_function
# 需要导入模块: from importmagic.symbols import Scope [as 别名]
# 或者: from importmagic.symbols.Scope import from_source [as 别名]
def test_referenced_symbols_from_decorated_function():
src = dedent("""
@foo.bar
def bar():
print(waz)
print(baz)
""")
symbols, _ = Scope.from_source(src).find_unresolved_and_unreferenced_symbols()
assert symbols == set(['foo.bar', 'waz', 'baz'])
示例8: test_annotations_without_imports
# 需要导入模块: from importmagic.symbols import Scope [as 别名]
# 或者: from importmagic.symbols.Scope import from_source [as 别名]
def test_annotations_without_imports():
src = dedent("""
def print_it(it: Iterable):
for i in it:
method1(i)
print_it(['a', 'b', 'c'])
""")
scope = Scope.from_source(src)
unresolved, unreferenced = scope.find_unresolved_and_unreferenced_symbols()
assert unresolved == set(['method1', 'Iterable'])
assert unreferenced == set([])
示例9: test_annotations_with_imports
# 需要导入模块: from importmagic.symbols import Scope [as 别名]
# 或者: from importmagic.symbols.Scope import from_source [as 别名]
def test_annotations_with_imports():
src = dedent("""
from typing import Iterable
def print_it(it: Iterable):
for i in it:
print(i)
""")
scope = Scope.from_source(src)
unresolved, unreferenced = scope.find_unresolved_and_unreferenced_symbols()
assert unresolved == set([])
assert unreferenced == set(['print_it'])
示例10: test_annotations_return_type
# 需要导入模块: from importmagic.symbols import Scope [as 别名]
# 或者: from importmagic.symbols.Scope import from_source [as 别名]
def test_annotations_return_type():
# https://www.python.org/dev/peps/pep-3107/
src = dedent("""
def foo(a) -> CustomType:
print(a)
foo()
""")
scope = Scope.from_source(src)
unresolved, unreferenced = scope.find_unresolved_and_unreferenced_symbols()
assert unresolved == set(['CustomType'])
assert unreferenced == set([])
示例11: test_annotations_complex
# 需要导入模块: from importmagic.symbols import Scope [as 别名]
# 或者: from importmagic.symbols.Scope import from_source [as 别名]
def test_annotations_complex():
# https://www.python.org/dev/peps/pep-3107/
src = dedent("""
def foo(a: 'x', b: 5 + 6, c: list, \
d: Iterable, e: CustomType) -> max(2, 9):
print(a)
foo()
""")
scope = Scope.from_source(src)
unresolved, unreferenced = scope.find_unresolved_and_unreferenced_symbols()
assert unresolved == set(['Iterable', 'CustomType'])
assert unreferenced == set([])
示例12: test_update_imports_correctly_aliases
# 需要导入模块: from importmagic.symbols import Scope [as 别名]
# 或者: from importmagic.symbols.Scope import from_source [as 别名]
def test_update_imports_correctly_aliases(index):
src = dedent('''
print(basename('src/foo'))
''').strip()
unresolved, unreferenced = Scope.from_source(src).find_unresolved_and_unreferenced_symbols()
assert unresolved == set(['basename'])
new_src = update_imports(src, index, unresolved, unreferenced)
assert dedent('''
from os.path import basename
print(basename('src/foo'))
''').strip() == new_src
示例13: test_deep_import_of_unknown_symbol
# 需要导入模块: from importmagic.symbols import Scope [as 别名]
# 或者: from importmagic.symbols.Scope import from_source [as 别名]
def test_deep_import_of_unknown_symbol(index):
src = dedent("""
print(os.unknown('/'))
""").strip()
unresolved, unreferenced = Scope.from_source(src).find_unresolved_and_unreferenced_symbols()
assert unresolved == set(['os.unknown'])
new_src = update_imports(src, index, unresolved, unreferenced)
assert dedent("""
import os
print(os.unknown('/'))
""").strip() == new_src
示例14: test_get_update
# 需要导入模块: from importmagic.symbols import Scope [as 别名]
# 或者: from importmagic.symbols.Scope import from_source [as 别名]
def test_get_update(index):
src = dedent("""
# header comment
import sys
print(os.unknown('/'))
""").strip()
unresolved, unreferenced = Scope.from_source(src).find_unresolved_and_unreferenced_symbols()
start_line, end_line, new_block = get_update(src, index, unresolved, unreferenced)
assert dedent("""\
import os
""").lstrip() == new_block
示例15: test_imports_module_assignment
# 需要导入模块: from importmagic.symbols import Scope [as 别名]
# 或者: from importmagic.symbols.Scope import from_source [as 别名]
def test_imports_module_assignment(index):
src = dedent('''
def func(n):
sys.stderr = n
''').strip()
scope = Scope.from_source(src)
new_src = update_imports(src, index, *scope.find_unresolved_and_unreferenced_symbols())
assert dedent('''
import sys
def func(n):
sys.stderr = n
''').strip() == new_src.strip()