當前位置: 首頁>>代碼示例>>Python>>正文


Python jedi.Script類代碼示例

本文整理匯總了Python中jedi.Script的典型用法代碼示例。如果您正苦於以下問題:Python Script類的具體用法?Python Script怎麽用?Python Script使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Script類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _validate_import

    def _validate_import(self, module_line, lineno):
        """Try to validate the given iport line
        """

        if 'noqa' in module_line:
            return True

        error = []
        error_string = 'can\'t import {0}'
        valid = True
        for word in module_line.split():
            if word in ('from', 'import', 'as'):
                continue

            offset = int(module_line.find(word) + len(word) / 2)
            s = Script(self.source, lineno, offset, self.filename)
            if not self.filename:
                s = Script(module_line, 1, offset)

            if not s.goto_assignments():
                if valid is True:
                    valid = False
                error.append(word)

        err = '' if valid else error_string.format(' '.join(error))
        return err, valid
開發者ID:DamnWidget,項目名稱:anaconda,代碼行數:26,代碼來源:import_validator.py

示例2: test_module_attributes

def test_module_attributes():
    def_, = Script('__name__').completions()
    assert def_.name == '__name__'
    assert def_.line == None
    assert def_.column == None
    str_, = def_._goto_definitions()
    assert str_.name == 'str'
開發者ID:ColossusPenguin,項目名稱:.emacs.d,代碼行數:7,代碼來源:test_context.py

示例3: feed

    def feed(self):
        source      = self.area.get('1.0', 'end')
        line        = self.area.indcur()[0]
        size        = len(self.area.get('insert linestart', 'insert'))
        script      = Script(source, line, size, self.area.filename)
        completions = script.completions()

        for ind in completions:
            self.box.insert('end', ind.name)
開發者ID:rahmiyildiz,項目名稱:vy,代碼行數:9,代碼來源:utils.py

示例4: do_completion

    def do_completion(self):
        source = self.area.get("1.0", "end")
        line = self.area.indcur()[0]
        size = len(self.area.get("insert linestart", "insert"))
        script = Script(source, line, size, self.area.filename)
        completions = script.completions()

        for ind in completions:
            self.insert("end", ind.name)
開發者ID:yutzhead,項目名稱:vy,代碼行數:9,代碼來源:wordbox.py

示例5: test_completion_docstring

def test_completion_docstring():
    """
    Jedi should follow imports in certain conditions
    """
    c = Script('import jedi\njed').completions()[0]
    assert c.docstring(fast=False) == cleandoc(jedi_doc)

    c = Script('import jedi\njedi.Scr').completions()[0]
    assert c.docstring(raw=True, fast=False) == cleandoc(Script.__doc__)
開發者ID:Hylen,項目名稱:jedi,代碼行數:9,代碼來源:test_api_classes.py

示例6: __init__

    def __init__(self, area, *args, **kwargs):
        CompleteBox.__init__(self, area, *args, **kwargs)

        source      = self.area.get('1.0', 'end')
        line        = self.area.indcur()[0]
        size        = len(self.area.get('insert linestart', 'insert'))
        script      = Script(source, line, size, self.area.filename)
        completions = script.completions()

        for ind in completions:
            self.insert('end', ind.name)
開發者ID:dev0p0,項目名稱:vy,代碼行數:11,代碼來源:utils.py

示例7: run

 def run(self, *args, **kwargs):
     request = self.__request
     script = Script(request.source_code, request.line, request.col,
                     request.filename, request.encoding)
     try:
         call = script.get_in_function_call()
         if call:
             self.resultsAvailable.signal.emit(call, request)
         else:
             self.failedEvent.signal.emit()
     except:
         self.failedEvent.signal.emit()
開發者ID:hofoen,項目名稱:pcef-core,代碼行數:12,代碼來源:calltips.py

示例8: ComputeCandidates

  def ComputeCandidates( self, unused_query, unused_start_column ):
    filename = vim.current.buffer.name
    line, column = vimsupport.CurrentLineAndColumn()
    # Jedi expects lines to start at 1, not 0
    line += 1
    contents = '\n'.join( vim.current.buffer )
    script = Script( contents, line, column, filename )

    return [ { 'word': str( completion.word ),
               'menu': str( completion.description ),
               'info': str( completion.doc ) }
             for completion in script.complete() ]
開發者ID:arcarson,項目名稱:dotfiles,代碼行數:12,代碼來源:jedi_completer.py

示例9: test_add_dynamic_mods

 def test_add_dynamic_mods(self):
     fname = '__main__.py'
     api.settings.additional_dynamic_modules = [fname]
     # Fictional module that defines a function.
     src1 = "def r(a): return a"
     # Other fictional modules in another place in the fs.
     src2 = 'from .. import setup; setup.r(1)'
     script = Script(src1, path='../setup.py')
     imports.load_module(script._evaluator, os.path.abspath(fname), src2)
     result = script.goto_definitions()
     assert len(result) == 1
     assert result[0].description == 'class int'
開發者ID:Jim-tech,項目名稱:windows-vim,代碼行數:12,代碼來源:test_regression.py

示例10: do_complete

    def do_complete(self, data):
        file_ = self.db.get_file(self.current_file)
        file_ = to_unicode(file_)
        lines = file_.splitlines()
        lno = self.current['lno']
        line_before = ''
        if len(lines) >= lno:
            line_before = lines[lno - 1]
        indent = len(line_before) - len(line_before.lstrip())
        segments = data.splitlines()
        for segment in reversed(segments):
            line = u(' ') * indent + segment
            lines.insert(lno - 1, line)
        script = Script(
            u('\n').join(lines), lno - 1 + len(segments),
            len(segments[-1]) + indent, '')
        try:
            completions = script.completions()
        except Exception:
            self.db.send('Suggest')
            self.notify_exc('Completion failed for %s' % (
                '\n'.join(reversed(segments))))
            return

        try:
            funs = script.call_signatures() or []
        except Exception:
            self.db.send('Suggest')
            self.notify_exc('Completion of function failed for %s' % (
                '\n'.join(reversed(segments))))
            return

        try:
            suggest_obj = {
                'params': [{
                    'params': [p.get_code().replace('\n', '')
                               for p in fun.params],
                    'index': fun.index,
                    'module': fun.module.path,
                    'call_name': fun.call_name} for fun in funs],
                'completions': [{
                    'base': comp.name[
                        :len(comp.name) - len(comp.complete)],
                    'complete': comp.complete,
                    'description': comp.description
                } for comp in completions if comp.name.endswith(
                    comp.complete)]
            }
            self.db.send('Suggest|%s' % dump(suggest_obj))
        except Exception:
            self.db.send('Suggest')
            self.notify_exc('Completion generation failed for %s' % (
                '\n'.join(reversed(segments))))
開發者ID:Avinash9,項目名稱:wdb,代碼行數:53,代碼來源:ui.py

示例11: test_loading_unicode_files_with_bad_global_charset

def test_loading_unicode_files_with_bad_global_charset(monkeypatch, tmpdir):
    dirname = str(tmpdir.mkdir('jedi-test'))
    filename1 = os.path.join(dirname, 'test1.py')
    filename2 = os.path.join(dirname, 'test2.py')
    if sys.version_info < (3, 0):
        data = "# coding: latin-1\nfoo = 'm\xf6p'\n"
    else:
        data = "# coding: latin-1\nfoo = 'm\xf6p'\n".encode("latin-1")

    with open(filename1, "wb") as f:
        f.write(data)
    s = Script("from test1 import foo\nfoo.",
               line=2, column=4, path=filename2)
    s.completions()
開發者ID:Jim-tech,項目名稱:windows-vim,代碼行數:14,代碼來源:test_regression.py

示例12: test_dict_literal_in_incomplete_call

def test_dict_literal_in_incomplete_call():
    source = """\
    import json

    def foo():
        json.loads(

        json.load.return_value = {'foo': [],
                                  'bar': True}

        c = Foo()
    """

    script = Script(dedent(source), line=4, column=15)
    assert script.call_signatures()
開發者ID:ABob,項目名稱:vim,代碼行數:15,代碼來源:test_call_signatures.py

示例13: __init__

class Traverser:

  def __init__(self):
    self._script = Script('', 1, 0, 'example.py')
    self._module = self._script._get_module()

  def names_in_module(self, module_name):
    try:
      _import_module(module_name)
    except Exception as e:
      pp.pprint(e)
      return []

    imp = Importer(
        self._script._evaluator, [FakeName('.'.join(module_name))],
        self._module, 0)
    try:
      scope_set = imp.follow()
    except Exception as e:
      # print('Error "{}" in {}, ignoring...'.format(e, module_name))
      return []

    all_names = []
    for s in scope_set:
      names = []
      for names_dict in s.names_dicts(search_global=False):
        names += chain.from_iterable(names_dict.values())

      all_names += finder.filter_definition_names(names, self._module)
    return all_names
開發者ID:harai,項目名稱:auto-import-jedi-sample,代碼行數:30,代碼來源:modules.py

示例14: test_completion_docstring

def test_completion_docstring():
    """
    Jedi should follow imports in certain conditions
    """
    def docstr(src, result):
        c = Script(src).completions()[0]
        assert c.docstring(raw=True, fast=False) == cleandoc(result)

    c = Script('import jedi\njed').completions()[0]
    assert c.docstring(fast=False) == cleandoc(jedi_doc)

    docstr('import jedi\njedi.Scr', cleandoc(Script.__doc__))

    docstr('abcd=3;abcd', '')
    docstr('"hello"\nabcd=3\nabcd', '')
    docstr(dedent('''
        def x():
            "hello"
            0
        x'''),
        'hello'
    )
    docstr(dedent('''
        def x():
            "hello";0
        x'''),
        'hello'
    )
    # Shouldn't work with a tuple.
    docstr(dedent('''
        def x():
            "hello",0
        x'''),
        ''
    )
    # Should also not work if we rename something.
    docstr(dedent('''
        def x():
            "hello"
        y = x
        y'''),
        ''
    )
開發者ID:OrangeCrush,項目名稱:dotfiles,代碼行數:43,代碼來源:test_classes.py

示例15: test_completion_docstring

def test_completion_docstring():
    """
    Jedi should follow imports in certain conditions
    """
    def docstr(src, result):
        c = Script(src).completions()[0]
        assert c.docstring(raw=True, fast=False) == cleandoc(result)

    c = Script('import jedi\njed').completions()[0]
    assert c.docstring(fast=False) == cleandoc(jedi_doc)

    docstr('import jedi\njedi.Scr', cleandoc(Script.__doc__))

    docstr('abcd=3;abcd', '')
    docstr('"hello"\nabcd=3\nabcd', 'hello')
    # It works with a ; as well.
    docstr('"hello"\nabcd=3;abcd', 'hello')
    # Shouldn't work with a tuple.
    docstr('"hello",0\nabcd=3\nabcd', '')
開發者ID:ABob,項目名稱:vim,代碼行數:19,代碼來源:test_classes.py


注:本文中的jedi.Script類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。