Skip to main content

TagTuple

This class provides a mechanism for serializing and deserializing Python tuple objects into a JSON-compatible format. It identifies tuple instances, recursively tags their elements for serialization, and reconstructs the original tuple structure during the conversion back to Python.

Attributes

AttributeTypeDescription
keystring = tThe unique identifier string used to tag tuple types during JSON serialization.

Methods


check()

@classmethod
def check(
value: t.Any
) - > bool

Checks if the provided value is a tuple instance to determine if it should be handled by this tag.

Parameters

NameTypeDescription
valuet.AnyThe object to be inspected for tuple type compatibility

Returns

TypeDescription
boolTrue if the value is a tuple, False otherwise

to_json()

@classmethod
def to_json(
value: t.Any
) - > t.Any

Converts a tuple into a JSON-serializable list by recursively tagging each item.

Parameters

NameTypeDescription
valuet.AnyThe tuple instance to be serialized into a JSON-compatible format

Returns

TypeDescription
t.AnyA list containing the tagged representations of the original tuple elements

to_python()

@classmethod
def to_python(
value: t.Any
) - > t.Any

Reconstructs a Python tuple from a list of values during deserialization.

Parameters

NameTypeDescription
valuet.AnyThe list of values to be cast back into a tuple structure

Returns

TypeDescription
t.AnyA new tuple containing the elements from the input list