Node

class understand.Node

Bases: object

Graph plugin node object

A node in a graph. Nodes are created from Graph objects with node. Graphviz attributes can be set. Use sync to associate entities, references, or locations with the node.

Node objects are hashable and compare equal when they refer to the same underlying Graphviz node.

Methods Summary

attributes

Return Graphviz attributes on this node.

id

Return the node's Graphviz id.

set

Set node attribute.

sync

Sync node to a reference, entities, or file location.

synced_data

Return this node's current sync data.

Methods Documentation

attributes() dict[str, str]

Return Graphviz attributes on this node.

Return type:

dict[str, str]

id() str

Return the node’s Graphviz id.

Return type:

str

set(name, value) None

Set node attribute.

Parameters:
  • name (str) – the attribute name

  • value (str) – the attribute value

Return type:

None

Raises:

RuntimeError – on read-only nodes from graphs returned by draw (raw graph format)

Refer to Graphviz for available attributes.

sync(ref) None
sync(arch) None
sync(ent) None
sync(ent, comparison_ent) None
sync(file, line=0, column=0) None

Sync node to a reference, entities, or file location.

Parameters:
  • ref (understand.Ref) – a reference to sync

  • arch (understand.Arch) – an architecture to sync

  • ent (understand.Ent) – an entity to sync

  • comparison_ent (understand.Ent or None) – an entity from the comparison database

  • file (understand.Ent or str) – a file entity or file path

  • line (int or None) – optional, a line number

  • column (int or None) – optional, a column number

Return type:

None

Raises:

RuntimeError – on read-only graphs returned by draw (raw graph format)

Line and column numbers are 1-based.

For entity comparison, ent or comparison_ent may be None to show added/removed entities.

synced_data() object

Return this node’s current sync data.

Return type:

understand.Ref or understand.Arch or understand.Ent or tuple[understand.Ent | None, understand.Ent | None] or dict[str, str | int | understand.Ent] or list[understand.Ref] or None

Returns:

sync data currently associated with this object

Locations are returned as dictionaries with a “file” key and optional keys: “entity”, “line”, “column”, “end_line”, and “end_column”. Line and column numbers are 1-based.

Entity comparisons are returned as a tuple with left and right entities. Either entity may be None, usually representing an added/removed entity.

Built-in graphs have more sync types than supported from plugins. Specifically, locations can have end_line and end_column (Control Flow graphs are an example) and edges often sync a list of references.