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
| Attribute | Type | Description |
|---|---|---|
| key | string = t | The 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
| Name | Type | Description |
|---|---|---|
| value | t.Any | The object to be inspected for tuple type compatibility |
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 item.
Parameters
| Name | Type | Description |
|---|---|---|
| value | t.Any | The tuple instance to be serialized into a JSON-compatible 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
Reconstructs a Python tuple from a list of values during deserialization.
Parameters
| Name | Type | Description |
|---|---|---|
| value | t.Any | The list of values to be cast back into a tuple structure |
Returns
| Type | Description |
|---|---|
t.Any | A new tuple containing the elements from the input list |