当前位置: 首页>>代码示例>>Python>>正文


Python Scope.from_source方法代码示例

本文整理汇总了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'])
开发者ID:ChillarAnand,项目名称:importmagic,代码行数:9,代码来源:symbols_test.py

示例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'])
开发者ID:MartinSoto,项目名称:emacs.d,代码行数:9,代码来源:symbols_test.py

示例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
开发者ID:adarshk7,项目名称:SublimePythonImportMagic,代码行数:9,代码来源:importer_test.py

示例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()
开发者ID:adarshk7,项目名称:SublimePythonImportMagic,代码行数:9,代码来源:importer_test.py

示例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
开发者ID:ChillarAnand,项目名称:importmagic,代码行数:29,代码来源:importer_test.py

示例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'])
开发者ID:MartinSoto,项目名称:emacs.d,代码行数:10,代码来源:symbols_test.py

示例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'])
开发者ID:MartinSoto,项目名称:emacs.d,代码行数:11,代码来源:symbols_test.py

示例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([])
开发者ID:alecthomas,项目名称:importmagic,代码行数:13,代码来源:symbols_test.py

示例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'])
开发者ID:alecthomas,项目名称:importmagic,代码行数:14,代码来源:symbols_test.py

示例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([])
开发者ID:alecthomas,项目名称:importmagic,代码行数:14,代码来源:symbols_test.py

示例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([])
开发者ID:alecthomas,项目名称:importmagic,代码行数:15,代码来源:symbols_test.py

示例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
开发者ID:adarshk7,项目名称:SublimePythonImportMagic,代码行数:15,代码来源:importer_test.py

示例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
开发者ID:adarshk7,项目名称:SublimePythonImportMagic,代码行数:15,代码来源:importer_test.py

示例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
开发者ID:DamnWidget,项目名称:importmagic,代码行数:16,代码来源:importer_test.py

示例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()
开发者ID:ChillarAnand,项目名称:importmagic,代码行数:17,代码来源:importer_test.py


注:本文中的importmagic.symbols.Scope.from_source方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。