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


Python jedi.Interpreter方法代碼示例

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


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

示例1: get_completions

# 需要導入模塊: import jedi [as 別名]
# 或者: from jedi import Interpreter [as 別名]
def get_completions(code, cursor=None, namespaces=None):
    """
    Get code autocompletion candidates.
    """
    import jedi
    import __main__

    if namespaces is None:
        namespaces = [__main__.__dict__]

    if cursor is None:
        cursor = len(code)
    code = code[:cursor]
    interp = jedi.Interpreter(source=code, namespaces=namespaces)
    completions = interp.completions()

    return [x.name for x in completions] 
開發者ID:iodide-project,項目名稱:pyodide,代碼行數:19,代碼來源:pyodide.py

示例2: _cmd_shell_autocomplete

# 需要導入模塊: import jedi [as 別名]
# 或者: from jedi import Interpreter [as 別名]
def _cmd_shell_autocomplete(self, cmd):
        error = None
        try:
            import jedi
        except ImportError:
            completions = []
            error = "Could not import jedi"
        else:
            try:
                # with warnings.catch_warnings():
                interpreter = jedi.Interpreter(cmd.source, [__main__.__dict__])
                completions = self._export_completions(interpreter.completions())
            except Exception as e:
                completions = []
                error = "Autocomplete error: " + str(e)

        return InlineResponse(
            "shell_autocomplete", source=cmd.source, completions=completions, error=error
        ) 
開發者ID:thonny,項目名稱:thonny,代碼行數:21,代碼來源:backend.py

示例3: get_completions

# 需要導入模塊: import jedi [as 別名]
# 或者: from jedi import Interpreter [as 別名]
def get_completions(self, line):
        """Get completions. Used by the ``autocomplete`` extension."""
        script = jedi.Interpreter(line, [self.interpreter.locals])
        return [comp.name for comp in script.completions()] 
開發者ID:marcus-oscarsson,項目名稱:pyqtconsole,代碼行數:6,代碼來源:console.py

示例4: get_completions

# 需要導入模塊: import jedi [as 別名]
# 或者: from jedi import Interpreter [as 別名]
def get_completions(self, info):
        '''Get Python completions'''
        # https://github.com/davidhalter/jedi/blob/master/jedi/utils.py
        if jedi is None:
            return []

        text = info['code']
        position = (info['line_num'], info['column'])
        interpreter = Interpreter(text, [self.env])

        if jedi.__version__ >= LooseVersion('0.12.0'):
            lines = split_lines(text)
            name = get_on_completion_name(
                interpreter._module_node,
                lines,
                position
            )
            before = text[:len(text) - len(name)]
        elif jedi.__version__ >= LooseVersion('0.10.0'):
            lines = split_lines(text)
            name = get_on_completion_name(
                interpreter._get_module_node(),
                lines,
                position
            )
            before = text[:len(text) - len(name)]
        else:
            path = UserContext(text, position).get_path_until_cursor()
            path, dot, like = completion_parts(path)
            before = text[:len(text) - len(like)]

        completions = interpreter.completions()
        completions = [before + c.name_with_symbols for c in completions]

        self.kernel.log.error(completions)

        return [c[info['start']:] for c in completions] 
開發者ID:Calysto,項目名稱:metakernel,代碼行數:39,代碼來源:python_magic.py


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