Skip to content

spongebobcase.tospongebob

tospongebob(x)

A single-dispatch generic function for converting text in Python objects to Mocking SpongeBob case. The core method for strings will return the input string with converted to Mocking Spongebob case. For other objects, it will attempt to appropriately find contained strings and convert them. Note that this returns new objects and should not be modifying any objects inplace.

Parameters:

Name Type Description Default
x ~T

input with text to convert

required

Returns:

Type Description
~T

new object of same type with text converted

Source code in spongebobcase/tospongebob.py
@singledispatch
def tospongebob(x: T) -> T:
    """A single-dispatch generic function for converting text in Python objects
    to [Mocking SpongeBob case](https://knowyourmeme.com/memes/mocking-spongebob).
    The core method for strings will return the input string with converted to Mocking Spongebob
    case. For other objects, it will attempt to appropriately find contained strings and convert
    them. Note that this returns new objects and should not be modifying any objects inplace.

    Args:
        x: input with text to convert

    Returns:
        new object of same type with text converted
    """
    if hasattr(x, "__dict__"):
        x_dict = tospongebob(x.__dict__)
        x = copy(x)
        x.__dict__ = x_dict
    return x