syft.ast.klass

This module contains Class attribute,an AST node representing a class.

Functions

attach_description(obj, description)

Add description to the object.

attach_tags(obj, tags)

Add tags to the object.

generate_class_property_function(...)

Returns a function that handles action on property.

get_run_class_method(attr_path_and_name)

Create a function for class method in attr_path_and_name for remote execution.

pointerize_args_and_kwargs(args, kwargs, client)

Get pointers to args and kwargs.

wrap_iterator(attrs)

Add syft Iterator to attrs['__iter__'].

wrap_len(attrs)

Add method to access pointer len to attr[__len__].

Classes

Class(path_and_name, parent, object_ref, ...)

A Class attribute represents a class.

syft.ast.klass.get_run_class_method(attr_path_and_name)[source]

Create a function for class method in attr_path_and_name for remote execution.

Parameters

attr_path_and_name – The path of the class method.

Returns

Function for the class method.

Note

It might seem hugely un-necessary to have these methods nested in this way. However, it has to do with ensuring that the scope of attr_path_and_name is local and not global.

If we do not put a get_run_class_method around run_class_method then each run_class_method will end up referencing the same attr_path_and_name variable and all methods will actually end up calling the same method.

If, instead, we return the function object itself then it includes the current attr_path_and_name as an internal variable and when we call get_run_class_method multiple times it returns genuinely different methods each time with a different internal attr_path_and_name variable.

syft.ast.klass.generate_class_property_function(attr_path_and_name, action, map_to_dyn)[source]

Returns a function that handles action on property.

Parameters
  • attr_path_and_name – The path of the property in AST.

  • action – action to perform on property (GET | SET | DEL).

Returns

Function to handle action on property.

syft.ast.klass.wrap_iterator(attrs)[source]

Add syft Iterator to attrs[‘__iter__’].

Parameters

attrs – Dict of `Attribute`s of node.

Raises

AttributeError – Base __iter__ is not callable.

syft.ast.klass.wrap_len(attrs)[source]

Add method to access pointer len to attr[__len__].

Parameters

attrs – Dict of `Attribute`s of node.

Raises

AttributeError – Base __len__ is not callable.

syft.ast.klass.attach_tags(obj, tags)[source]

Add tags to the object.

Parameters
  • obj – Object to add tags to.

  • tags – List of tags.

Raises

AttributeError – Cannot add tags to object.

syft.ast.klass.attach_description(obj, description)[source]

Add description to the object.

Parameters
  • obj – Object to add description to.

  • description – Description.

Raises

AttributeError – Cannot add description to object.

class syft.ast.klass.Class(path_and_name, parent, object_ref, return_type_name, client)[source]

Bases: syft.ast.callable.Callable

A Class attribute represents a class.

__init__(path_and_name, parent, object_ref, return_type_name, client)[source]

Base constructor for Class Attribute.

Parameters
  • path_and_name – The path for the current node, e.g. syft.lib.python.List.

  • parent – The parent node is needed when solving EnumAttributes.

  • object_ref – The actual python object for which the computation is being made.

  • return_type_name – The return type name of given action as a string with its full path.

  • client – The client for which all computation is being executed.

property pointer_type

Get pointer type of Class Attribute.

Returns

pointer_type of the object.

create_pointer_class()[source]

Create pointer type for object.

store_init_args()[source]

Stores args and kwargs of outer_self init by wrapping the init method.

create_send_method()[source]

Add send method to outer_self.object_ref.

create_storable_object_attr_convenience_methods()[source]

Add methods to set tag and description to outer_self.object_ref.

add_path(path, index, return_type_name=None, framework_reference=None, is_static=False)[source]

The add_path method adds new nodes in AST based on type of current node and type of object to be added.

Parameters
  • path – The node path added in AST, e.g. syft.lib.python.List or [“syft”, “lib”, “python”, “List].

  • index – The associated position in the path for the current node.

  • framework_reference – The Python framework in which we can resolve same path to obtain Python object.

  • return_type_name – The return type name of the given action as a string with its full path.

  • is_static – If the queried object is static, it has to be found on AST itself, not on an existing pointer.

syft.ast.klass.pointerize_args_and_kwargs(args, kwargs, client)[source]

Get pointers to args and kwargs.

Parameters
  • args – List of arguments.

  • kwargs – Dict of Keyword arguments.

  • client – Client node.

Returns

Tuple of args and kwargs with pointer to values.