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


Python ast.Store方法代碼示例

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


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

示例1: setName

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Store [as 別名]
def setName(self, node):
        # XXX INOUT access in Store context, unlike with compiler
        # XXX check whether ast context is correct
        n = node.id
        if self.access == _access.INOUT:  # augmented assign
            if n in self.tree.sigdict:
                sig = self.tree.sigdict[n]
                if isinstance(sig, _Signal):
                    self.raiseError(node, _error.NotSupported, "Augmented signal assignment")
            if n in self.tree.vardict:
                obj = self.tree.vardict[n]
                # upgrade bool to int for augmented assignments
                if isinstance(obj, bool):
                    obj = int(-1)
                    self.tree.vardict[n] = obj
                node.obj = obj
        else:
            if n in ("__verilog__", "__vhdl__"):
                self.raiseError(node, _error.NotSupported,
                                "%s in generator function" % n)
            if n in self.globalRefs:
                self.raiseError(node, _error.UnboundLocal, n)
            self.refStack.add(n) 
開發者ID:myhdl,項目名稱:myhdl,代碼行數:25,代碼來源:_analyze.py

示例2: accessIndex

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Store [as 別名]
def accessIndex(self, node):
        self.visit(node.value)
        self.access = _access.INPUT
        self.visit(node.slice.value)
        if isinstance(node.value.obj, _Ram):
            if isinstance(node.ctx, ast.Store):
                self.raiseError(node, _error.ListElementAssign)
            else:
                node.obj = node.value.obj.elObj
        elif _isMem(node.value.obj):
            node.obj = node.value.obj[0]
        elif isinstance(node.value.obj, _Rom):
            node.obj = int(-1)
        elif isinstance(node.value.obj, intbv):
            node.obj = bool()
        else:
            node.obj = bool()  # XXX default 
開發者ID:myhdl,項目名稱:myhdl,代碼行數:19,代碼來源:_analyze.py

示例3: accessSlice

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Store [as 別名]
def accessSlice(self, node):
        self.generic_visit(node)
        lower = node.value.vhd.size
        t = type(node.value.vhd)
        # node.expr.vhd = vhd_unsigned(node.expr.vhd.size)
        if node.slice.lower:
            node.slice.lower.vhd = vhd_int()
            lower = self.getVal(node.slice.lower)
        upper = 0
        if node.slice.upper:
            node.slice.upper.vhd = vhd_int()
            upper = self.getVal(node.slice.upper)
        if isinstance(node.ctx, ast.Store):
            node.vhd = t(lower - upper)
        else:
            node.vhd = vhd_unsigned(lower - upper)
        node.vhdOri = copy(node.vhd) 
開發者ID:myhdl,項目名稱:myhdl,代碼行數:19,代碼來源:_toVHDL.py

示例4: NAME

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Store [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, ast.AugLoad)):
            self.handleNodeLoad(node)
            if (node.id == 'locals' and isinstance(self.scope, FunctionScope)
                    and isinstance(node.parent, ast.Call)):
                # we are doing locals() call in current scope
                self.scope.usesLocals = True
        elif isinstance(node.ctx, (ast.Store, ast.AugStore)):
            self.handleNodeStore(node)
        elif isinstance(node.ctx, ast.Del):
            self.handleNodeDelete(node)
        else:
            # must be a Param context -- this only happens for names in function
            # arguments, but these aren't dispatched through here
            raise RuntimeError("Got impossible expression context: %r" % (node.ctx,)) 
開發者ID:AtomLinter,項目名稱:linter-pylama,代碼行數:21,代碼來源:checker.py

示例5: TUPLE

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Store [as 別名]
def TUPLE(self, node):
        if not PY2 and isinstance(node.ctx, ast.Store):
            # Python 3 advanced tuple unpacking: a, *b, c = d.
            # Only one starred expression is allowed, and no more than 1<<8
            # assignments are allowed before a stared expression. There is
            # also a limit of 1<<24 expressions after the starred expression,
            # which is impossible to test due to memory restrictions, but we
            # add it here anyway
            has_starred = False
            star_loc = -1
            for i, n in enumerate(node.elts):
                if isinstance(n, ast.Starred):
                    if has_starred:
                        self.report(messages.TwoStarredExpressions, node)
                        # The SyntaxError doesn't distinguish two from more
                        # than two.
                        break
                    has_starred = True
                    star_loc = i
            if star_loc >= 1 << 8 or len(node.elts) - star_loc - 1 >= 1 << 24:
                self.report(messages.TooManyExpressionsInStarredAssignment, node)
        self.handleChildren(node) 
開發者ID:AtomLinter,項目名稱:linter-pylama,代碼行數:24,代碼來源:checker.py

示例6: __init__

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Store [as 別名]
def __init__(
            self,
            keys: t.List[ast.expr],
            values: t.List[ast.expr],
            ctx: t.Union[ast.Store, ast.Load],
            lineno=None,
            col_offset=None,
    ):
        super().__init__()
        self.keys = keys
        self.values = values
        self.ctx = ctx
        if lineno:
            self.lineno = lineno
        if col_offset:
            self.col_offset = col_offset 
開發者ID:Xython,項目名稱:YAPyPy,代碼行數:18,代碼來源:extended_ast.py

示例7: visit

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Store [as 別名]
def visit(self, node) -> Any:
        if isinstance(node, ast.Name):
            if isinstance(node.ctx, ast.Load):
                self.loaded.add(node.id)
            elif isinstance(node.ctx, ast.Store):
                self.stored.add(node.id)
        elif isinstance(node, ast.Return):
            self.has_return = True
        # We must keep track of importer name in order to avoid considering as variable
        # names:
        elif isinstance(node, ast.Import):
            self.imported.update([ n.name for n in node.names])
        elif isinstance(node, ast.ImportFrom):
            self.imported.update([ n.name for n in node.names])

        self.generic_visit(node) 
開發者ID:Orange-OpenSource,項目名稱:pyDcop,代碼行數:18,代碼來源:expressionfunction.py

示例8: pop_format_context

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Store [as 別名]
def pop_format_context(self, expl_expr):
        """Format the %-formatted string with current format context.

        The expl_expr should be an ast.Str instance constructed from
        the %-placeholders created by .explanation_param().  This will
        add the required code to format said string to .expl_stmts and
        return the ast.Name instance of the formatted string.

        """
        current = self.stack.pop()
        if self.stack:
            self.explanation_specifiers = self.stack[-1]
        keys = [ast.Str(key) for key in current.keys()]
        format_dict = ast.Dict(keys, list(current.values()))
        form = ast.BinOp(expl_expr, ast.Mod(), format_dict)
        name = "@py_format" + str(next(self.variable_counter))
        if self.enable_assertion_pass_hook:
            self.format_variables.append(name)
        self.expl_stmts.append(ast.Assign([ast.Name(name, ast.Store())], form))
        return ast.Name(name, ast.Load()) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:22,代碼來源:rewrite.py

示例9: visit_Return

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Store [as 別名]
def visit_Return(self, return_):
        """Convert returns into assignment/exception pairs

        Since the body of this function will be in the global namespace we
        can't have any returns. An acceptable alternative is to set a variable
        called 'RETURN' and then immediately raise an exception.

        >>> self = NamespacePromoter(buffer='foo')
        >>> code = '''
        ...
        ... return 5
        ...
        ... '''
        >>> tree = ast.parse(code)
        >>> return_, = tree.body

        """
        nodes = [
            ast.Assign(targets=[ast.Name(id='RETURN', ctx=ast.Store())], value=return_.value, lineno=return_.lineno),
            ast.Raise(exc=ast.Call(func=ast.Name(id='Exception', ctx=ast.Load()), args=[ast.Str(s='return')], keywords=[]), cause=None),
        ]
        return nodes 
開發者ID:ebanner,項目名稱:pynt,代碼行數:24,代碼來源:node_transformers.py

示例10: visit_For

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Store [as 別名]
def visit_For(self, loop_):
        """
        >>> self = RestIterableFor()
        >>> code = '''
        ...
        ... for i in range(5):
        ...     for j in range(5):
        ...         k = i + j
        ...         print(k)
        ... '''
        >>> tree = ast.parse(code)
        >>> loop_, = tree.body
        >>> FirstPassFor().visit(copy.deepcopy(loop_))

        """
        loop = self.generic_visit(loop_)
        global N
        varname = N.pop(0)
        loop.iter = ast.Name(id=varname, ctx=ast.Store())
        return loop 
開發者ID:ebanner,項目名稱:pynt,代碼行數:22,代碼來源:node_transformers.py

示例11: visit_Name

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Store [as 別名]
def visit_Name(self, node):
        # If it is from the argument list or loop variable, we do not worry about it!
        if node.id in self._args.keys():
            return
        fors = [loop.target.id for loop in self.scope_level if isinstance(loop, ast.For)]
        if node.id in fors:
            return
        # The loop variable cannot be overwritten when iteration
        if isinstance(node.ctx, ast.Store) and node.id in fors:
            raise ValueError("Iter var cannot be overwritten")

        if node.id not in self.status.keys():
            if not isinstance(node.ctx, ast.Store):
                raise ValueError('In Python, "first store" indicates "declaration"')
            self.status[node.id] = (node, self.scope_level[-1], set())
        else:
            decl, loop, usage = self.status[node.id]
            usage.add(type(node.ctx))
            self.status[node.id] = (decl, loop, usage) 
開發者ID:mlperf,項目名稱:training_results_v0.6,代碼行數:21,代碼來源:var_decl.py

示例12: pop_format_context

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Store [as 別名]
def pop_format_context(self, expl_expr: ast.expr) -> ast.Name:
        """Format the %-formatted string with current format context.

        The expl_expr should be an str ast.expr instance constructed from
        the %-placeholders created by .explanation_param().  This will
        add the required code to format said string to .expl_stmts and
        return the ast.Name instance of the formatted string.

        """
        current = self.stack.pop()
        if self.stack:
            self.explanation_specifiers = self.stack[-1]
        keys = [ast.Str(key) for key in current.keys()]
        format_dict = ast.Dict(keys, list(current.values()))
        form = ast.BinOp(expl_expr, ast.Mod(), format_dict)
        name = "@py_format" + str(next(self.variable_counter))
        if self.enable_assertion_pass_hook:
            self.format_variables.append(name)
        self.expl_stmts.append(ast.Assign([ast.Name(name, ast.Store())], form))
        return ast.Name(name, ast.Load()) 
開發者ID:pytest-dev,項目名稱:pytest,代碼行數:22,代碼來源:rewrite.py

示例13: visit_IfExp

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Store [as 別名]
def visit_IfExp(self, node):
        if isinstance(node.test, (ast.Name, ast.Attribute)):
            return self.generic_visit(node)
        else:
            temp_var_id = '__if_exp_{}'.format(self._temporary_variable_index)
            self._temporary_variable_index += 1
            assignment_of_test = ast.Assign(
                targets=[ast.Name(id=temp_var_id, ctx=ast.Store())],
                value=self.visit(node.test),
            )
            ast.copy_location(assignment_of_test, node)
            self.assignments.append(assignment_of_test)
            transformed_if_exp = ast.IfExp(
                test=ast.Name(id=temp_var_id, ctx=ast.Load()),
                body=self.visit(node.body),
                orelse=self.visit(node.orelse),
            )
            ast.copy_location(transformed_if_exp, node)
            return transformed_if_exp 
開發者ID:python-security,項目名稱:pyt,代碼行數:21,代碼來源:transformer.py

示例14: test_classdef

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Store [as 別名]
def test_classdef(self):
        def cls(bases=None, keywords=None, body=None, decorator_list=None):
            if bases is None:
                bases = []
            if keywords is None:
                keywords = []
            if body is None:
                body = [ast.Pass()]
            if decorator_list is None:
                decorator_list = []
            return ast.ClassDef("myclass", bases, keywords,
                                body, decorator_list)
        self.stmt(cls(bases=[ast.Name("x", ast.Store())]),
                  "must have Load context")
        self.stmt(cls(keywords=[ast.keyword("x", ast.Name("x", ast.Store()))]),
                  "must have Load context")
        self.stmt(cls(body=[]), "empty body on ClassDef")
        self.stmt(cls(body=[None]), "None disallowed")
        self.stmt(cls(decorator_list=[ast.Name("x", ast.Store())]),
                  "must have Load context") 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:22,代碼來源:test_ast.py

示例15: test_subscript

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Store [as 別名]
def test_subscript(self):
        sub = ast.Subscript(ast.Name("x", ast.Store()), ast.Index(ast.Num(3)),
                            ast.Load())
        self.expr(sub, "must have Load context")
        x = ast.Name("x", ast.Load())
        sub = ast.Subscript(x, ast.Index(ast.Name("y", ast.Store())),
                            ast.Load())
        self.expr(sub, "must have Load context")
        s = ast.Name("x", ast.Store())
        for args in (s, None, None), (None, s, None), (None, None, s):
            sl = ast.Slice(*args)
            self.expr(ast.Subscript(x, sl, ast.Load()),
                      "must have Load context")
        sl = ast.ExtSlice([])
        self.expr(ast.Subscript(x, sl, ast.Load()), "empty dims on ExtSlice")
        sl = ast.ExtSlice([ast.Index(s)])
        self.expr(ast.Subscript(x, sl, ast.Load()), "must have Load context") 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:19,代碼來源:test_ast.py


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