← GDG /

#145 gdtest_docstring_seealso

#145 gdtest_docstring_seealso OK CONFIG
See Also sections cross-referencing related functions
Docstrings with See Also sections listing related functions, each with a brief description. Should render as a linked list of related API entries.
View Site → Build Log ๐Ÿงช Test Coverage

Build Mode

● Has great-docs.yml

This package ships a pre-supplied config. The great-docs init step is skipped and great-docs build uses the spec-defined configuration directly. Tests specific config options and their rendered output.

Dimensions

L22
L22See Also sectiondocstring

Source Files

๐Ÿ“ gdtest_docstring_seealso/
๐Ÿ“„ __init__.py
"""Package with See Also sections in docstrings."""

__version__ = "0.1.0"
__all__ = ["serialize", "deserialize", "to_json"]


def serialize(obj: object) -> bytes:
    """
    Serialize a Python object to bytes.

    Converts the given object into a byte string representation
    using pickle serialization.

    Parameters
    ----------
    obj
        The Python object to serialize. Must be picklable.

    Returns
    -------
    bytes
        The serialized byte string.

    Raises
    ------
    TypeError
        If the object cannot be pickled.

    See Also
    --------
    deserialize : Convert bytes back into a Python object.
    to_json : Serialize an object to a JSON string instead.

    Examples
    --------
    >>> data = serialize({"key": "value"})
    >>> isinstance(data, bytes)
    True
    """
    import pickle

    return pickle.dumps(obj)


def deserialize(data: bytes) -> object:
    """
    Deserialize bytes back into a Python object.

    Reconstructs a Python object from a byte string that was
    previously created by ``serialize``.

    Parameters
    ----------
    data
        A byte string produced by ``serialize``.

    Returns
    -------
    object
        The reconstructed Python object.

    Raises
    ------
    ValueError
        If the byte string is corrupted or invalid.

    See Also
    --------
    serialize : Convert a Python object to bytes.

    Examples
    --------
    >>> original = {"key": "value"}
    >>> data = serialize(original)
    >>> deserialize(data)
    {'key': 'value'}
    """
    import pickle

    return pickle.loads(data)


def to_json(obj: object) -> str:
    """
    Serialize a Python object to a JSON string.

    Converts the given object into a human-readable JSON string.
    Supports dicts, lists, strings, numbers, booleans, and None.

    Parameters
    ----------
    obj
        The Python object to serialize. Must be JSON-serializable.

    Returns
    -------
    str
        A JSON-formatted string.

    Raises
    ------
    TypeError
        If the object is not JSON-serializable.

    See Also
    --------
    serialize : Serialize to bytes using pickle (supports more types).
    from_json : Parse a JSON string back into a Python object.

    Examples
    --------
    >>> to_json({"name": "test", "value": 42})
    '{"name": "test", "value": 42}'
    """
    import json

    return json.dumps(obj)
๐Ÿ“„ README.md
# gdtest-docstring-seealso

A synthetic test package with See Also sections.
๐Ÿ“„ great-docs.yml
parser: numpy