当前位置: 首页>>代码示例>>Python>>正文


Python anno.setanno函数代码示例

本文整理汇总了Python中tensorflow.python.autograph.pyct.anno.setanno函数的典型用法代码示例。如果您正苦于以下问题:Python setanno函数的具体用法?Python setanno怎么用?Python setanno使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了setanno函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_create_source_map_multiple_nodes

  def test_create_source_map_multiple_nodes(self):

    source = """
        from __future__ import print_function
        def test_fn(x):
          return x + 1
    """
    source = textwrap.dedent(source)

    nodes = parser.parse_str(source, single_node=False)
    fake_import_origin = origin_info.OriginInfo(
        loc=origin_info.Location('fake_filename', 3, 7),
        function_name='fake_function_name',
        source_code_line='fake source line',
        comment=None)
    anno.setanno(nodes[0], anno.Basic.ORIGIN, fake_import_origin)
    fake_function_origin = origin_info.OriginInfo(
        loc=origin_info.Location('fake_filename', 3, 7),
        function_name='fake_function_name',
        source_code_line='fake source line',
        comment=None)
    anno.setanno(nodes[1], anno.Basic.ORIGIN, fake_function_origin)

    source_map = origin_info.create_source_map(nodes, source, 'test_filename')

    loc = origin_info.LineLocation('test_filename', 2)
    self.assertIn(loc, source_map)
    self.assertIs(source_map[loc], fake_import_origin)

    loc = origin_info.LineLocation('test_filename', 3)
    self.assertIn(loc, source_map)
    self.assertIs(source_map[loc], fake_function_origin)
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:32,代码来源:origin_info_test.py

示例2: visit_Attribute

 def visit_Attribute(self, node):
   node = self.generic_visit(node)
   parent_val = anno.getanno(node.value, STATIC_VALUE, default=None)
   if parent_val is not None and tf_inspect.ismodule(parent_val):
     if hasattr(parent_val, node.attr):
       anno.setanno(node, STATIC_VALUE, getattr(parent_val, node.attr))
   return node
开发者ID:aritratony,项目名称:tensorflow,代码行数:7,代码来源:directives.py

示例3: visit_FunctionDef

  def visit_FunctionDef(self, node):
    # The FunctionDef node itself has a Scope object that tracks the creation
    # of its name, along with the usage of any decorator accompany it.
    self._enter_scope(False)
    node.decorator_list = self.visit_block(node.decorator_list)
    self.scope.mark_modified(qual_names.QN(node.name))
    anno.setanno(node, anno.Static.SCOPE, self.scope)
    self._exit_scope()

    # A separate Scope tracks the actual function definition.
    self._enter_scope(True)
    assert not (self._in_function_def_args or self.state[_Lambda].level)
    self._in_function_def_args = True
    node.args = self.visit(node.args)
    self._in_function_def_args = False

    # Track the body separately. This is for compatibility reasons, it may not
    # be strictly needed.
    self._enter_scope(False)
    node.body = self.visit_block(node.body)
    anno.setanno(node, NodeAnno.BODY_SCOPE, self.scope)
    self._exit_scope()

    self._exit_scope()
    return node
开发者ID:JonathanRaiman,项目名称:tensorflow,代码行数:25,代码来源:activity.py

示例4: visit_Print

 def visit_Print(self, node):
   self._enter_scope(False)
   node.values = self.visit_block(node.values)
   anno.setanno(node, anno.Static.SCOPE, self.scope)
   anno.setanno(node, NodeAnno.ARGS_SCOPE, self.scope)
   self._exit_scope()
   return node
开发者ID:JonathanRaiman,项目名称:tensorflow,代码行数:7,代码来源:activity.py

示例5: _block_statement_live_out

 def _block_statement_live_out(self, node):
   successors = self.current_analyzer.graph.stmt_next[node]
   stmt_live_out = set()
   for s in successors:
     stmt_live_out.update(self.current_analyzer.in_[s])
   anno.setanno(node, anno.Static.LIVE_VARS_OUT, frozenset(stmt_live_out))
   return node
开发者ID:ThunderQi,项目名称:tensorflow,代码行数:7,代码来源:liveness.py

示例6: visit_Compare

  def visit_Compare(self, node):
    node = self.generic_visit(node)

    if not all(self._has_matching_func(op) for op in node.ops):
      if len(node.ops) == 1:
        # Basic expressions are safe to leave as they are.
        return node
      else:
        raise NotImplementedError(
            'compound expression with at least one unsupported '
            'operator: {}'.format(node.ops))

    ops_and_comps = list(zip(node.ops, node.comparators))
    left = node.left
    op_tree = None

    # Repeated comparisons are converted to conjunctions:
    #   a < b < c   ->   a < b and b < c
    while ops_and_comps:
      op, right = ops_and_comps.pop(0)
      binary_comparison = self._as_function(
          self._matching_func(op), (left, right))
      if isinstance(left, gast.Name) and isinstance(right, gast.Name):
        anno.setanno(binary_comparison, SAFE_BOOLEAN_OPERAND, True)
      if op_tree:
        self._expect_simple_symbol(right)
        op_tree = self._as_function('tf.logical_and',
                                    (binary_comparison, op_tree))
      else:
        op_tree = binary_comparison
      left = right
    assert op_tree is not None
    return op_tree
开发者ID:HughKu,项目名称:tensorflow,代码行数:33,代码来源:logical_expressions.py

示例7: _track_symbol

  def _track_symbol(self,
                    node,
                    composite_writes_alter_parent=False,
                    writes_create_symbol=False):
    # A QN may be missing when we have an attribute (or subscript) on a function
    # call. Example: a().b
    if not anno.hasanno(node, anno.Basic.QN):
      return
    qn = anno.getanno(node, anno.Basic.QN)

    if isinstance(node.ctx, gast.Store):
      self.scope.mark_write(qn)
      if qn.is_composite and composite_writes_alter_parent:
        self.scope.mark_write(qn.parent)
      if writes_create_symbol:
        self.scope.mark_creation(qn, writes_create_symbol=True)
      if self._in_aug_assign:
        self.scope.mark_read(qn)
    elif isinstance(node.ctx, gast.Load):
      self.scope.mark_read(qn)
    elif isinstance(node.ctx, gast.Param):
      # Param contexts appear in function defs, so they have the meaning of
      # defining a variable.
      self.scope.mark_write(qn)
      self.scope.mark_param(qn, self.enclosing_entities[-1])
    else:
      raise ValueError('Unknown context %s for node %s.' % (type(node.ctx), qn))

    anno.setanno(node, NodeAnno.IS_LOCAL, self.scope.has(qn))

    if self._in_return_statement:
      self.scope.mark_returned(qn)
开发者ID:AnishShah,项目名称:tensorflow,代码行数:32,代码来源:activity.py

示例8: _aggregate_successors_live_in

 def _aggregate_successors_live_in(self, node):
   successors = self.current_analyzer.graph.stmt_next[node]
   node_live_out = set()
   for s in successors:
     node_live_out.update(self.current_analyzer.in_[s])
   anno.setanno(node, anno.Static.LIVE_VARS_OUT, frozenset(node_live_out))
   node = self.generic_visit(node)
   return node
开发者ID:AnishShah,项目名称:tensorflow,代码行数:8,代码来源:liveness.py

示例9: _as_function

 def _as_function(self, func_name, args):
   template = """
     func_name(args)
   """
   replacement = templates.replace_as_expression(
       template, func_name=parser.parse_expression(func_name), args=args)
   anno.setanno(replacement, SAFE_BOOLEAN_OPERAND, True)
   return replacement
开发者ID:AnishShah,项目名称:tensorflow,代码行数:8,代码来源:logical_expressions.py

示例10: visit_Name

 def visit_Name(self, node):
   node = self.generic_visit(node)
   if isinstance(node.ctx, gast.Load):
     defs = anno.getanno(node, anno.Static.DEFINITIONS, ())
     is_defined = bool(defs)
     if not is_defined and node.id in self.ctx.info.namespace:
       anno.setanno(node, STATIC_VALUE, self.ctx.info.namespace[node.id])
   return node
开发者ID:perfmjs,项目名称:tensorflow,代码行数:8,代码来源:directives.py

示例11: _process_statement_directive

 def _process_statement_directive(self, call_node, directive):
   if self.local_scope_level < 1:
     raise ValueError(
         '"%s" must be used inside a statement' % directive.__name__)
   target = self.get_local(ENCLOSING_LOOP)
   node_anno = anno.getanno(target, converter.AgAnno.DIRECTIVES, {})
   node_anno[directive] = _map_args(call_node, directive)
   anno.setanno(target, converter.AgAnno.DIRECTIVES, node_anno)
   return call_node
开发者ID:perfmjs,项目名称:tensorflow,代码行数:9,代码来源:directives.py

示例12: visit_Call

 def visit_Call(self, node):
   self._enter_scope(False)
   node.args = self.visit_block(node.args)
   node.keywords = self.visit_block(node.keywords)
   # TODO(mdan): Account starargs, kwargs
   anno.setanno(node, NodeAnno.ARGS_SCOPE, self.scope)
   self._exit_scope()
   node.func = self.visit(node.func)
   return node
开发者ID:JonathanRaiman,项目名称:tensorflow,代码行数:9,代码来源:activity.py

示例13: visit

 def visit(self, node):
   node = super(Annotator, self).visit(node)
   if (self.current_analyzer is not None and
       isinstance(node, gast.stmt) and
       node in self.current_analyzer.graph.index):
     cfg_node = self.current_analyzer.graph.index[node]
     anno.setanno(node, anno.Static.LIVE_VARS_IN,
                  frozenset(self.current_analyzer.in_[cfg_node]))
   return node
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:9,代码来源:liveness.py

示例14: visit_While

 def visit_While(self, node):
   self._enter_scope(False)
   node.test = self.visit(node.test)
   anno.setanno(node, NodeAnno.COND_SCOPE, self.scope)
   anno.setanno(node.test, anno.Static.SCOPE, self.scope)
   self._exit_scope()
   node = self._process_parallel_blocks(node,
                                        ((node.body, NodeAnno.BODY_SCOPE),
                                         (node.orelse, NodeAnno.ORELSE_SCOPE)))
   return node
开发者ID:JonathanRaiman,项目名称:tensorflow,代码行数:10,代码来源:activity.py

示例15: test_rename_symbols_annotations

  def test_rename_symbols_annotations(self):
    node = parser.parse_str('a[i]')
    node = qual_names.resolve(node)
    anno.setanno(node, 'foo', 'bar')
    orig_anno = anno.getanno(node, 'foo')

    node = ast_util.rename_symbols(node,
                                   {qual_names.QN('a'): qual_names.QN('b')})

    self.assertIs(anno.getanno(node, 'foo'), orig_anno)
开发者ID:AnishShah,项目名称:tensorflow,代码行数:10,代码来源:ast_util_test.py


注:本文中的tensorflow.python.autograph.pyct.anno.setanno函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。