Skip to main content

TagTuple

This class provides a mechanism for serializing and deserializing Python tuple objects into a JSON-compatible format. It identifies tuples during the serialization process, recursively tags their elements, and ensures they are restored as tuple types when converted back to Python.

Attributes​

AttributeTypeDescription
keystring = tThe unique identifier string used by the serializer to tag and identify tuple types during JSON conversion.

Methods​


check()​

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

Checks if the provided value is an instance of a tuple.

Parameters​

NameTypeDescription
valuet.AnyThe object to be validated against the tuple type

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 element.

Parameters​

NameTypeDescription
valuet.AnyThe tuple instance to be serialized into JSON 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

Converts a JSON-decoded list back into a Python tuple.

Parameters​

NameTypeDescription
valuet.AnyThe list-like object to be cast back into a tuple

Returns​

TypeDescription
t.AnyA tuple containing the items from the input list