def __setattr__(self, name, value): py_typecheck.check_type(name, str) _check_is_optionally_federated_named_tuple( self, "__setattr__('{}', {})".format(name, value)) value_comp = ValueImpl.get_comp(to_value(value, None, self._context_stack)) if _is_federated_named_tuple(self): new_comp = building_block_factory.create_federated_setattr_call( self._comp, name, value_comp) super().__setattr__('_comp', new_comp) return named_tuple_setattr_lambda = building_block_factory.create_named_tuple_setattr_lambda( self._comp.type_signature, name, value_comp) new_comp = building_blocks.Call(named_tuple_setattr_lambda, self._comp) super().__setattr__('_comp', new_comp)
def __setattr__(self, name, value): py_typecheck.check_type(name, str) _check_struct_or_federated_struct(self, name) value_comp = ValueImpl.get_comp(to_value(value, None, self._context_stack)) if _is_federated_named_tuple(self): new_comp = building_block_factory.create_federated_setattr_call( self._comp, name, value_comp) super().__setattr__('_comp', new_comp) return named_tuple_setattr_lambda = building_block_factory.create_named_tuple_setattr_lambda( self.type_signature, name, value_comp) new_comp = building_blocks.Call(named_tuple_setattr_lambda, self._comp) fc_context = self._context_stack.current ref = fc_context.bind_computation_to_reference(new_comp) super().__setattr__('_comp', ref)
def __setattr__(self, name, value): py_typecheck.check_type(name, six.string_types) value_comp = ValueImpl.get_comp(to_value(value, None, self._context_stack)) if isinstance(self._comp.type_signature, computation_types.FederatedType) and isinstance( self._comp.type_signature.member, computation_types.NamedTupleType): new_comp = building_block_factory.create_federated_setattr_call( self._comp, name, value_comp) super(ValueImpl, self).__setattr__('_comp', new_comp) return elif not isinstance(self._comp.type_signature, computation_types.NamedTupleType): raise TypeError( 'Operator setattr() is only supported for named tuples, but the ' 'object on which it has been invoked is of type {}.'.format( self._comp.type_signature)) named_tuple_setattr_lambda = building_block_factory.create_named_tuple_setattr_lambda( self._comp.type_signature, name, value_comp) new_comp = building_blocks.Call(named_tuple_setattr_lambda, self._comp) super(ValueImpl, self).__setattr__('_comp', new_comp)