syft.ast.attribute

This module contains Attribute, an interface of a generic node in the AST.

Classes

Attribute(client[, path_and_name, ...])

Attribute is the interface of a generic node in the AST that covers basic functionality.

class syft.ast.attribute.Attribute(client, path_and_name=None, object_ref=None, return_type_name=None, parent=None)[source]

Bases: object

Attribute is the interface of a generic node in the AST that covers basic functionality.

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

Base constructor for all AST nodes.

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

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

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

  • return_type_name – The given action’s return type name, with its full path, in string format.

  • parent – The parent node in the AST.

property classes

Extract all classes from the current node attributes.

Returns

The list of classes in the current AST node attributes.

property properties

Extract all properties from the current node attributes.

Returns

The list of properties in the current AST node attributes.

query(path, obj_type=None)[source]

The query method is a tree traversal function based on the path to retrieve the node.

It has a similar functionality to __call__, main difference being that query retrieves node without performing execution on node.

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

  • obj_type – The type of the object that we want to call, whose path is resolved from the lookup_cache.

Returns

The attribute in the AST at the given initial path.

property name

Retrieve the name of the current AST node from its path_and_name.

Returns

The name of the current attribute.

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.

fetch_live_object()[source]

Get the new object and its attributes from the client.

object_change()[source]

Check if client wants to change any nodes in the AST with a new object.

reconstruct_node()[source]

Changes node reference in the AST by adding the new object’s reference as specified by client.

apply_node_changes()[source]

Apply the changes in the nodes in the AST as specified by the client.

property parent

Check if all the nodes have a parent node.

Returns

parent node

Return type

Attribute

Raises

AttributeError – If node has no parent attribute.