pg.Origin

Accessible via pg.Origin, pg.symbolic.Origin.

class Origin(source, tag, stacktrace=None, stacklimit=None, stacktop=-1)[source]

Bases: pg.Formattable

Class that represents the origin of a symbolic value.

Origin is used for debugging the creation chain of a symbolic value, as well as keeping track of the factory or builder in creational design patterns. An Origin object records the source value, a string tag, and optional stack information on where a symbolic value is created.

Built-in tags are ‘__init__’, ‘clone’, ‘deepclone’ and ‘return’. Users can pass custom tags to the sym_setorigin method of a symbolic value for tracking its source in their own scenarios.

When origin tracking is enabled by calling pg.track_origin(True), the sym_setorigin method of symbolic values will be automatically called during object creation, cloning or being returned from a functor. The stack information can be obtained by origin.stack or origin.stacktrace.

Methods:

chain([tag])

Get the origin list from the neareast to the farthest filtered by tag.

format([compact, verbose, root_indent, markdown])

Formats this object.

history([condition])

Returns a history of origins with an optional filter.

Attributes:

root

Returns the root source of the origin.

source

Returns the source object.

stack

Returns the frame summary of original stack.

stacktrace

Returns stack trace string.

tag

Returns tag.

chain(tag=None)[source]

Get the origin list from the neareast to the farthest filtered by tag.

Return type:

List[pg.Origin]

format(compact=False, verbose=True, root_indent=0, *, markdown=False, **kwargs)[source]

Formats this object.

Return type:

str

history(condition=None)[source]

Returns a history of origins with an optional filter.

Return type:

List[pg.Origin]

Parameters:

condition – An optional callable object with signature (origin) -> should_list. If None, all origins will be listed.

Returns:

A list of filtered origin from the earliest (root) to the most recent.

property root: Origin[source]

Returns the root source of the origin.

property source: Any[source]

Returns the source object.

property stack: List[FrameSummary] | None[source]

Returns the frame summary of original stack.

property stacktrace: str | None[source]

Returns stack trace string.

property tag: str[source]

Returns tag.