Skip to content

utils

Class info

🛈 DocStrings

Module containing helper functions.

InvalidParamError

Bases: ValueError

Exception raised for invalid params in method calls.

Parameters:

Name Type Description Default
value Any

param value which caused the error

required
valid_options Iterable

allowed options

required
Source code in prettyqt/utils/__init__.py
class InvalidParamError(ValueError):
    """Exception raised for invalid params in method calls.

    Args:
        value: param value which caused the error
        valid_options: allowed options
    """

    def __init__(self, value: Any, valid_options: Iterable):
        self.value = value
        opts = " / ".join(repr(opt) for opt in valid_options)
        self.message = f"Invalid value: {value!r}. Allowed options are {opts}."
        super().__init__(self.message)

get_repr(_obj: Any, *args: Any, **kwargs: Any) -> str

Get a suitable repr string for an object.

Parameters:

Name Type Description Default
_obj Any

The object to get a repr for.

required
*args Any

Arguments for the repr

()
**kwargs Any

Keyword arguments for the repr

{}
Source code in prettyqt/utils/__init__.py
def get_repr(_obj: Any, *args: Any, **kwargs: Any) -> str:
    """Get a suitable __repr__ string for an object.

    Args:
        _obj: The object to get a repr for.
        *args: Arguments for the repr
        **kwargs: Keyword arguments for the repr
    """
    classname = type(_obj).__name__
    parts = [repr(val) for val in args]
    kw_parts = [f"{name}={val!r}" for name, val in kwargs.items()]
    return f"{classname}({', '.join(parts + kw_parts)})"