コード例 #1
0
ファイル: value_impl.py プロジェクト: zhangjinyiyi/federated
 def __getattr__(self, name):
     py_typecheck.check_type(name, str)
     _check_struct_or_federated_struct(self, name)
     if _is_federated_named_tuple(self):
         return ValueImpl(
             building_block_factory.create_federated_getattr_call(
                 self._comp, name), self._context_stack)
     if name not in dir(self.type_signature):
         raise AttributeError(
             'There is no such attribute \'{}\' in this tuple. Valid attributes: ({})'
             .format(name, ', '.join(dir(self.type_signature))))
     if self._comp.is_struct():
         return ValueImpl(getattr(self._comp, name), self._context_stack)
     return ValueImpl(building_blocks.Selection(self._comp, name=name),
                      self._context_stack)
コード例 #2
0
ファイル: value_impl.py プロジェクト: zhaochenlihui/federated
 def __getattr__(self, name):
     py_typecheck.check_type(name, str)
     _check_is_optionally_federated_named_tuple(
         self, "__getattr__('{}')".format(name))
     if _is_federated_named_tuple(self):
         return ValueImpl(
             building_block_factory.create_federated_getattr_call(
                 self._comp, name), self._context_stack)
     if name not in dir(self._comp.type_signature):
         raise AttributeError(
             'There is no such attribute as \'{}\' in this tuple.'.format(
                 name))
     if isinstance(self._comp, building_blocks.Tuple):
         return ValueImpl(getattr(self._comp, name), self._context_stack)
     return ValueImpl(building_blocks.Selection(self._comp, name=name),
                      self._context_stack)
コード例 #3
0
 def __getattr__(self, name):
   py_typecheck.check_type(name, six.string_types)
   if (isinstance(self._comp.type_signature, computation_types.FederatedType)
       and isinstance(self._comp.type_signature.member,
                      computation_types.NamedTupleType)):
     return ValueImpl(
         building_block_factory.create_federated_getattr_call(
             self._comp, name), self._context_stack)
   elif not isinstance(self._comp.type_signature,
                       computation_types.NamedTupleType):
     raise TypeError(
         'Operator getattr() is only supported for named tuples, but the '
         'object on which it has been invoked is of type {}.'.format(
             self._comp.type_signature))
   if name not in dir(self._comp.type_signature):
     raise AttributeError(
         'There is no such attribute as \'{}\' in this tuple.'.format(name))
   if isinstance(self._comp, building_blocks.Tuple):
     return ValueImpl(getattr(self._comp, name), self._context_stack)
   return ValueImpl(
       building_blocks.Selection(self._comp, name=name), self._context_stack)