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
| Attribute | Type | Description |
|---|---|---|
| key | string = t | The 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
| Name | Type | Description |
|---|---|---|
| value | t.Any | The object to be validated against the tuple type |
Returns
| Type | Description |
|---|---|
bool | True 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
| Name | Type | Description |
|---|---|---|
| value | t.Any | The tuple instance to be serialized into JSON format |
Returns
| Type | Description |
|---|---|
t.Any | A 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
| Name | Type | Description |
|---|---|---|
| value | t.Any | The list-like object to be cast back into a tuple |
Returns
| Type | Description |
|---|---|
t.Any | A tuple containing the items from the input list |