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


Python ast.Param方法代碼示例

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


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

示例1: NAME

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Param [as 別名]
def NAME(self, node):
        """
        Handle occurrence of Name (which can be a load/store/delete access.)
        """
        # Locate the name in locals / function / globals scopes.
        if isinstance(node.ctx, ast.Load):
            self.handleNodeLoad(node)
            if (node.id == 'locals' and isinstance(self.scope, FunctionScope) and
                    isinstance(node._pyflakes_parent, ast.Call)):
                # we are doing locals() call in current scope
                self.scope.usesLocals = True
        elif isinstance(node.ctx, ast.Store):
            self.handleNodeStore(node)
        elif PY2 and isinstance(node.ctx, ast.Param):
            self.handleNodeStore(node)
        elif isinstance(node.ctx, ast.Del):
            self.handleNodeDelete(node)
        else:
            # Unknown context
            raise RuntimeError("Got impossible expression context: %r" % (node.ctx,)) 
開發者ID:PyCQA,項目名稱:pyflakes,代碼行數:22,代碼來源:checker.py

示例2: ctx_to_store

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Param [as 別名]
def ctx_to_store(obj, store=ast.Store):
    if isinstance(obj, list):
        for i, x in enumerate(obj):
            obj[i] = ctx_to_store(x, store)
        return obj
    elif isinstance(obj, (ast.Attribute, ast.Subscript)):
        obj.ctx = store()
        return obj
    elif isinstance(obj, ast.AST):
        for attrib in obj._fields:
            value = getattr(obj, attrib)
            if isinstance(value, ast.Load):
                setattr(obj, attrib, store())
            elif isinstance(value, ast.Param):
                setattr(obj, attrib, store())
            elif isinstance(value, list):
                for i, x in enumerate(value):
                    value[i] = ctx_to_store(x, store)
            elif isinstance(value, ast.AST):
                setattr(obj, attrib, ctx_to_store(value, store))
        return obj
    else:
        return obj 
開發者ID:histogrammar,項目名稱:histogrammar-python,代碼行數:25,代碼來源:hgawk_grammar.py

示例3: _make_fn

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Param [as 別名]
def _make_fn(name, chain_fn, args, defaults):
    args_with_self = ['_self'] + list(args)
    arguments = [_ast.Name(id=arg, ctx=_ast.Load()) for arg in args_with_self]
    defs = [_ast.Name(id='_def{0}'.format(idx), ctx=_ast.Load()) for idx, _ in enumerate(defaults)]
    if _PY2:
        parameters = _ast.arguments(args=[_ast.Name(id=arg, ctx=_ast.Param()) for arg in args_with_self],
                                    defaults=defs)
    else:
        parameters = _ast.arguments(args=[_ast.arg(arg=arg) for arg in args_with_self],
                                    kwonlyargs=[],
                                    defaults=defs,
                                    kw_defaults=[])
    module_node = _ast.Module(body=[_ast.FunctionDef(name=name,
                                                     args=parameters,
                                                     body=[_ast.Return(value=_ast.Call(func=_ast.Name(id='_chain', ctx=_ast.Load()),
                                                                                       args=arguments,
                                                                                       keywords=[]))],
                                                     decorator_list=[])])
    module_node = _ast.fix_missing_locations(module_node)

    # compile the ast
    code = compile(module_node, '<string>', 'exec')

    # and eval it in the right context
    globals_ = {'_chain': chain_fn}
    locals_ = dict(('_def{0}'.format(idx), value) for idx, value in enumerate(defaults))
    eval(code, globals_, locals_)

    # extract our function from the newly created module
    return locals_[name]


########################################################################
# Produce a docstring for the class. 
開發者ID:mbevilacqua,項目名稱:appcompatprocessor,代碼行數:36,代碼來源:namedlist.py

示例4: handleNodeStore

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Param [as 別名]
def handleNodeStore(self, node):
        name = getNodeName(node)
        if not name:
            return
        # if the name hasn't already been defined in the current scope
        if isinstance(self.scope, FunctionScope) and name not in self.scope:
            # for each function or module scope above us
            for scope in self.scopeStack[:-1]:
                if not isinstance(scope, (FunctionScope, ModuleScope)):
                    continue
                # if the name was defined in that scope, and the name has
                # been accessed already in the current scope, and hasn't
                # been declared global
                used = name in scope and scope[name].used
                if used and used[0] is self.scope and name not in self.scope.globals:
                    # then it's probably a mistake
                    self.report(messages.UndefinedLocal,
                                scope[name].used[1], name, scope[name].source)
                    break

        parent_stmt = self.getParent(node)
        if isinstance(parent_stmt, (FOR_TYPES, ast.comprehension)) or (
                parent_stmt != node._pyflakes_parent and
                not self.isLiteralTupleUnpacking(parent_stmt)):
            binding = Binding(name, node)
        elif name == '__all__' and isinstance(self.scope, ModuleScope):
            binding = ExportBinding(name, node._pyflakes_parent, self.scope)
        elif PY2 and isinstance(getattr(node, 'ctx', None), ast.Param):
            binding = Argument(name, self.getScopeNode(node))
        else:
            binding = Assignment(name, node)
        self.addBinding(node, binding) 
開發者ID:PyCQA,項目名稱:pyflakes,代碼行數:34,代碼來源:checker.py

示例5: visit_arguments

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Param [as 別名]
def visit_arguments(self, node):
        # missing locations for vararg and kwarg set at function level
        if node.vararg:
            vararg = ast.Name(node.vararg, ast.Param())
        else:
            vararg = None

        if node.kwarg:
            kwarg = ast.Name(node.kwarg, ast.Param())
        else:
            kwarg = None

        if node.vararg:
            vararg = ast.Name(node.vararg, ast.Param())
        else:
            vararg = None

        new_node = gast.arguments(
            self._visit(node.args),
            [],  # posonlyargs
            self._visit(vararg),
            [],  # kwonlyargs
            [],  # kw_defaults
            self._visit(kwarg),
            self._visit(node.defaults),
        )
        return new_node 
開發者ID:serge-sans-paille,項目名稱:gast,代碼行數:29,代碼來源:ast2.py

示例6: visit_arg

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Param [as 別名]
def visit_arg(self, node):
        new_node = ast.Name(node.arg, ast.Param())
        ast.copy_location(new_node, node)
        return new_node

    # arguments 
開發者ID:serge-sans-paille,項目名稱:gast,代碼行數:8,代碼來源:ast2.py

示例7: visit_Expr

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Param [as 別名]
def visit_Expr(self, node):
        if type(node.value) is ast.Call:
            call = node.value
            if self.is_concurrent_call(call):
                self.encounter_call(call)
                return node
            elif any([self.is_concurrent_call(arg) for arg in call.args]):
                conc_args = [(i, arg) for i, arg in enumerate(call.args) if self.is_concurrent_call(arg)]
                if len(conc_args) > 1:
                    raise self.not_implemented_error(call, "Functions with multiple @concurrent parameters are unsupported")
                conc_call = conc_args[0][1]
                if isinstance(call.func, ast.Attribute):
                    self.arguments.add(SchedulerRewriter.top_level_name(call.func.value))
                self.encounter_call(conc_call)
                call.args[conc_args[0][0]] = ast.Name("__value__", ast.Load())
                if sys.version_info >= (3, 0):
                    args = [ast.arg("__value__", None)]
                else:
                    args = [ast.Name("__value__", ast.Param())]
                call_lambda = ast.Lambda(ast.arguments(args = args, defaults = [], kwonlyargs = [], kw_defaults = []), call)
                copy_location_kwargs = {
                    "func": ast.Attribute(conc_call.func, 'call', ast.Load()),
                    "args": [call_lambda] + conc_call.args,
                    "keywords": conc_call.keywords
                }
                if(sys.version_info < (3, 0)):
                    copy_location_kwargs["kwargs"] = conc_call.kwargs
                return copy_location(ast.Expr(ast.Call(**copy_location_kwargs)), node)
        return self.generic_visit(node) 
開發者ID:alex-sherman,項目名稱:deco,代碼行數:31,代碼來源:astutil.py

示例8: p_fpdef_1

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

示例9: p_fplist_2

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Param [as 別名]
def p_fplist_2(p):
    '''fplist : fpdef COMMA'''
    #               1     2
    p[0] = ast.Tuple([p[1]], ast.Param(), rule=inspect.currentframe().f_code.co_name, paren=False)
    inherit_lineno(p[0], p[1]) 
開發者ID:histogrammar,項目名稱:histogrammar-python,代碼行數:7,代碼來源:hgawk_grammar.py

示例10: p_fplist_star_1

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Param [as 別名]
def p_fplist_star_1(p):
    '''fplist_star : COMMA fpdef'''
    #                    1     2
    p[0] = ast.Tuple([p[2]], ast.Param(), rule=inspect.currentframe().f_code.co_name, paren=False) 
開發者ID:histogrammar,項目名稱:histogrammar-python,代碼行數:6,代碼來源:hgawk_grammar.py

示例11: functionalize

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Param [as 別名]
def functionalize(node):
    # changes node in-place, but returns it anyway
    if isinstance(node, ast.Call) and isinstance(node.func, ast.Name):
        for i, x in enumerate(node.args):
            if (node.func.id, i) in expectFunction:
                numargs = highestDollar(x)
                if numargs > 0:
                    # the parameter name "$args" can't conflict with any valid Python names
                    out = ast.Lambda(ast.arguments([ast.Name("$args", ast.Param())], None, None, []), dollarToArg(x))
                    out.lineno,                  out.col_offset                  = x.lineno, x.col_offset
                    out.args.lineno,             out.args.col_offset             = x.lineno, x.col_offset
                    out.args.args[0].lineno,     out.args.args[0].col_offset     = x.lineno, x.col_offset
                    out.args.args[0].ctx.lineno, out.args.args[0].ctx.col_offset = x.lineno, x.col_offset
                    node.args[i] = out

        for keyword in node.keywords:
            if (node.func.id, keyword.arg) in expectFunction:
                x = keyword.value
                numargs = highestDollar(x)
                if numargs > 0:
                    out = ast.Lambda(ast.arguments([ast.Name("$args", ast.Param())], None, None, []), dollarToArg(x))
                    out.lineno,                  out.col_offset                  = x.lineno, x.col_offset
                    out.args.lineno,             out.args.col_offset             = x.lineno, x.col_offset
                    out.args.args[0].lineno,     out.args.args[0].col_offset     = x.lineno, x.col_offset
                    out.args.args[0].ctx.lineno, out.args.args[0].ctx.col_offset = x.lineno, x.col_offset
                    keyword.value = out
                    
    for field in node._fields:
        subnode = getattr(node, field)
        if isinstance(subnode, ast.AST):
            functionalize(subnode)
        elif isinstance(subnode, list):
            for x in subnode:
                if isinstance(x, ast.AST):
                    functionalize(x)

    return node 
開發者ID:histogrammar,項目名稱:histogrammar-python,代碼行數:39,代碼來源:hgawk_test.py

示例12: _convert_Name

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Param [as 別名]
def _convert_Name(self, n):
        if pyversion < (3, 4):  # pragma: no cover
            M = {'None': None, 'False': False, 'True': True}
            if n.id in M:
                return NameConstant(M[n.id])  # Python < 3.4
        if pyversion < (3, ) and isinstance(n.ctx , ast.Param):
            return Arg(n.id, None, None)
        return Name(n.id) 
開發者ID:flexxui,項目名稱:pscript,代碼行數:10,代碼來源:commonast.py

示例13: visit_Name

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Param [as 別名]
def visit_Name(self, node):
        if (
            isinstance(node.ctx, ast.Load)
            and node.id not in IGNORED_VARIABLE_NAMES
        ):
            self.used_names.add(node.id)
        elif isinstance(node.ctx, (ast.Param, ast.Store)):
            self._define_variable(node.id, node) 
開發者ID:jendrikseipp,項目名稱:vulture,代碼行數:10,代碼來源:core.py

示例14: enter_function_scope

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Param [as 別名]
def enter_function_scope(self, curr_func: ast.FunctionDef) -> "CPSTransformerContext":
        """Returns a new context with an updated current function and set of accessible global names."""
        if self.curr_func:
            raise NodeNotSupportedError(curr_func, "Nested functions not supported")

        new_global_names = set(self.global_names)
        # Remove global names shadowed in function.
        vars_by_usage = find_variables_by_usage(curr_func)
        new_global_names -= vars_by_usage[ast.Param]
        new_global_names -= vars_by_usage[ast.Store]

        return CPSTransformerContext(subsequent_stmts=[], subsequent_live_vars=LivenessTracker(),
                                     curr_class=self.curr_class, curr_func=curr_func, global_names=new_global_names) 
開發者ID:NetSys,項目名稱:kappa,代碼行數:15,代碼來源:cps.py

示例15: visit_FunctionDef

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Param [as 別名]
def visit_FunctionDef(self, func_def: ast.FunctionDef) -> None:
        self.visit_stmt_list(func_def.body)
        # The arguments aren't live before the function definition.
        self._live_vars -= find_variables_by_usage(func_def.args)[ast.Param]
        for decorator in func_def.decorator_list:
            self._live_vars |= find_variables_by_usage(decorator)[ast.Load] 
開發者ID:NetSys,項目名稱:kappa,代碼行數:8,代碼來源:liveness.py


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