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


Python ast.Ellipsis方法代碼示例

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


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

示例1: _handle_type_comments

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Ellipsis [as 別名]
def _handle_type_comments(self, node):
        for (lineno, col_offset), comment in self._type_comments.get(node, ()):
            comment = comment.split(':', 1)[1].strip()
            func_match = TYPE_FUNC_RE.match(comment)
            if func_match:
                parts = (
                    func_match.group(1).replace('*', ''),
                    func_match.group(2).strip(),
                )
            else:
                parts = (comment,)

            for part in parts:
                if PY2:
                    part = part.replace('...', 'Ellipsis')
                self.deferFunction(functools.partial(
                    self.handleStringAnnotation,
                    part, DummyNode(lineno, col_offset), lineno, col_offset,
                    messages.CommentAnnotationSyntaxError,
                )) 
開發者ID:PyCQA,項目名稱:pyflakes,代碼行數:22,代碼來源:checker.py

示例2: visit_Index

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Ellipsis [as 別名]
def visit_Index(self, node):
        new_value = self._visit(node.value)
        if isinstance(new_value, ast.Ellipsis):
            new_node = new_value
        elif isinstance(new_value, ast.Tuple):
            if any(isinstance(elt, ast.Ellipsis) for elt in new_value.elts):
                new_elts = [elt if isinstance(elt, (ast.Ellipsis, ast.Slice))
                            else ast.Index(elt)
                            for elt in new_value.elts]
                new_node = ast.ExtSlice(new_elts)
            else:
                new_node = ast.Index(new_value)
        else:
            new_node = ast.Index(new_value)
        ast.copy_location(new_node, node)
        return new_node 
開發者ID:serge-sans-paille,項目名稱:gast,代碼行數:18,代碼來源:ast2.py

示例3: update_annotations_using_type_comments

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Ellipsis [as 別名]
def update_annotations_using_type_comments(app: Sphinx, obj: Any, bound_method: bool) -> None:
    """Update annotations info of *obj* using type_comments."""
    try:
        function = get_type_comment(obj)
        if function and hasattr(function, 'argtypes'):
            if function.argtypes != [ast.Ellipsis]:  # type: ignore
                sig = inspect.signature(obj, bound_method)
                for i, param in enumerate(sig.parameters.values()):
                    if param.name not in obj.__annotations__:
                        annotation = ast_unparse(function.argtypes[i])  # type: ignore
                        obj.__annotations__[param.name] = annotation

            if 'return' not in obj.__annotations__:
                obj.__annotations__['return'] = ast_unparse(function.returns)  # type: ignore
    except NotImplementedError as exc:  # failed to ast.unparse()
        logger.warning("Failed to parse type_comment for %r: %s", obj, exc) 
開發者ID:thu-coai,項目名稱:cotk,代碼行數:18,代碼來源:type_comment.py

示例4: atom_rewrite

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Ellipsis [as 別名]
def atom_rewrite(loc, name, token, value, number, strs, namedc, ellipsis, dict, is_dict,
                 is_gen, is_list, comp, yield_expr):
    if name:
        if not token:
            return ast.Name(name.value, ast.Load(), **loc @ name)
        return ex_ast.AssignExpr(
            ast.Name(name.value, ast.Store(), **loc @ name), value=value, **loc @ token)

    if number:
        return ast.Num(eval(number.value), **loc @ number)

    if strs:
        return str_maker(*strs)

    if ellipsis:
        return ast.Ellipsis()

    if namedc:
        return ast.NameConstant(eval(namedc.value), **loc @ namedc)

    if is_dict:
        return dict or ex_ast.ExDict([], [], ast.Load(), **loc @ is_dict)

    if is_gen:
        if yield_expr:
            return yield_expr
        return comp(is_tuple=True) if comp else ast.Tuple([], ast.Load(), **loc @ is_gen)

    if is_list:
        return comp(is_list=True) if comp else ast.List([], ast.Load(), **loc @ is_list)

    raise TypeError 
開發者ID:Xython,項目名稱:YAPyPy,代碼行數:34,代碼來源:helper.py

示例5: _unparse

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Ellipsis [as 別名]
def _unparse(node: ast.expr) -> str:
    if isinstance(node, ast.Name):
        return node.id
    elif isinstance(node, ast.Attribute):
        return ''.join((_unparse(node.value), '.', node.attr))
    elif isinstance(node, ast.Call):
        return '{}()'.format(_unparse(node.func))
    elif isinstance(node, ast.Subscript):
        if sys.version_info >= (3, 9):  # pragma: no cover (py39+)
            # https://github.com/python/typeshed/pull/3950
            node_slice: ast.expr = node.slice  # type: ignore
        elif isinstance(node.slice, ast.Index):  # pragma: no cover (<py39)
            node_slice = node.slice.value
        else:
            raise AssertionError(f'expected Slice: {ast.dump(node)}')
        if isinstance(node_slice, ast.Tuple):
            if len(node_slice.elts) == 1:
                slice_s = f'{_unparse(node_slice.elts[0])},'
            else:
                slice_s = ', '.join(_unparse(elt) for elt in node_slice.elts)
        else:
            slice_s = _unparse(node_slice)
        return '{}[{}]'.format(_unparse(node.value), slice_s)
    elif isinstance(node, ast.Str):
        return repr(node.s)
    elif isinstance(node, ast.Ellipsis):
        return '...'
    elif isinstance(node, ast.List):
        return '[{}]'.format(', '.join(_unparse(elt) for elt in node.elts))
    elif isinstance(node, ast.NameConstant):
        return repr(node.value)
    else:
        raise NotImplementedError(ast.dump(node)) 
開發者ID:asottile,項目名稱:pyupgrade,代碼行數:35,代碼來源:pyupgrade.py

示例6: _is_stub_function

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Ellipsis [as 別名]
def _is_stub_function(self, node: ast.FunctionDef) -> bool:
        for stmt in node.body:
            if (
                    isinstance(stmt, ast.Expr) and
                    isinstance(stmt.value, (ast.Str, ast.Ellipsis))
            ):
                continue  # docstring or ...
            elif isinstance(stmt, ast.Pass):
                continue  # pass
            elif (
                    isinstance(stmt, ast.Raise) and
                    stmt.cause is None and (
                        (
                            isinstance(stmt.exc, ast.Name) and
                            stmt.exc.id in STUB_EXCEPTIONS
                        ) or (
                            isinstance(stmt.exc, ast.Call) and
                            isinstance(stmt.exc.func, ast.Name) and
                            stmt.exc.func.id in STUB_EXCEPTIONS
                        )
                    )
            ):
                continue  # raise NotImplementedError
            else:
                return False
        else:
            return True 
開發者ID:asottile,項目名稱:dead,代碼行數:29,代碼來源:dead.py

示例7: is_void

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Ellipsis [as 別名]
def is_void(func):
    """
    Determines if a function is a void function, i.e., one whose body contains
    nothing but a docstring or an ellipsis. A void function can be used to introduce
    an overloaded function without actually registering an implementation.
    """
    try:
        source = dedent(inspect.getsource(func))
    except (OSError, IOError):
        return False
    fdef = next(ast.iter_child_nodes(ast.parse(source)))
    return (
      type(fdef) is ast.FunctionDef and len(fdef.body) == 1 and
      type(fdef.body[0]) is ast.Expr and
      type(fdef.body[0].value) in {ast.Str, ast.Ellipsis}) 
開發者ID:bintoro,項目名稱:overloading.py,代碼行數:17,代碼來源:overloading.py

示例8: _is_singleton

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Ellipsis [as 別名]
def _is_singleton(node):  # type: (ast.AST) -> bool
        return (
            isinstance(node, ast.Constant) and
            isinstance(node.value, (bool, type(Ellipsis), type(None)))
        ) 
開發者ID:PyCQA,項目名稱:pyflakes,代碼行數:7,代碼來源:checker.py

示例9: visit_Subscript

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Ellipsis [as 別名]
def visit_Subscript(self, node):
        new_slice = self._visit(node.slice)
        if isinstance(node.slice, ast.Ellipsis):
            new_slice = gast.Index(new_slice)

        new_node = gast.Subscript(
            self._visit(node.value),
            new_slice,
            self._visit(node.ctx),
        )
        gast.copy_location(new_node, node)
        new_node.end_lineno = new_node.end_col_offset = None
        return new_node 
開發者ID:serge-sans-paille,項目名稱:gast,代碼行數:15,代碼來源:ast2.py

示例10: visit_Ellipsis

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Ellipsis [as 別名]
def visit_Ellipsis(self, node):
        new_node = gast.Constant(
            Ellipsis,
            None,
        )
        gast.copy_location(new_node, node)
        new_node.end_lineno = new_node.end_col_offset = None
        return new_node 
開發者ID:serge-sans-paille,項目名稱:gast,代碼行數:10,代碼來源:ast2.py

示例11: visit_ExtSlice

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Ellipsis [as 別名]
def visit_ExtSlice(self, node):
        has_ellipsis = any(isinstance(d, ast.Ellipsis) for d in node.dims)
        has_slice = any(isinstance(d, ast.Slice) for d in node.dims)
        new_dims = self._visit(node.dims)
        if has_ellipsis and not has_slice:
            new_dims = [nd.value if isinstance(nd, gast.Index) else nd
                        for nd in new_dims]
            new_node = gast.Index(gast.Tuple(new_dims,
                                             gast.Load()))
        else:
            new_node = gast.ExtSlice(new_dims)
        gast.copy_location(new_node, node)
        new_node.end_lineno = new_node.end_col_offset = None
        return new_node 
開發者ID:serge-sans-paille,項目名稱:gast,代碼行數:16,代碼來源:ast2.py

示例12: visit_Constant

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Ellipsis [as 別名]
def visit_Constant(self, node):
        if isinstance(node.value, (bool, int, long, float, complex)):
            new_node = ast.Num(node.value)
        elif node.value is Ellipsis:
            new_node = ast.Ellipsis()
        else:
            new_node = ast.Str(node.value)
        ast.copy_location(new_node, node)
        return new_node 
開發者ID:serge-sans-paille,項目名稱:gast,代碼行數:11,代碼來源:ast2.py

示例13: visit_Constant

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Ellipsis [as 別名]
def visit_Constant(self, node):
            if node.value is None:
                new_node = ast.NameConstant(node.value)
            elif node.value is Ellipsis:
                new_node = ast.Ellipsis()
            elif isinstance(node.value, bool):
                new_node = ast.NameConstant(node.value)
            elif isinstance(node.value, (int, float, complex)):
                new_node = ast.Num(node.value)
            elif isinstance(node.value, str):
                new_node = ast.Str(node.value)
            else:
                new_node = ast.Bytes(node.value)
            ast.copy_location(new_node, node)
            return new_node 
開發者ID:serge-sans-paille,項目名稱:gast,代碼行數:17,代碼來源:ast3.py

示例14: p_subscript_1

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Ellipsis [as 別名]
def p_subscript_1(p):
    '''subscript : DOT DOT DOT'''
    #                1   2   3
    p[0] = ast.Ellipsis(rule=inspect.currentframe().f_code.co_name, **p[1][1]) 
開發者ID:histogrammar,項目名稱:histogrammar-python,代碼行數:6,代碼來源:hgawk_grammar.py

示例15: _convert_Constant

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Ellipsis [as 別名]
def _convert_Constant(self, n):
        val = n.value
        if val is None or val is True or val is False:
            return NameConstant(val)
        if isinstance(val, (int, float, complex)):
            return Num(val)
        if isinstance(val, str):
            return Str(val)
        if isinstance(val, bytes):
            return Bytes(val)
        if val is _Ellipsis:
            return Ellipsis()
        raise RuntimeError('Cannot convert %s constants.' % type(val).__name__) 
開發者ID:flexxui,項目名稱:pscript,代碼行數:15,代碼來源:commonast.py


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