Skip to content

Commit

Permalink
Add debug function
Browse files Browse the repository at this point in the history
  • Loading branch information
facelessuser committed Nov 22, 2023
1 parent d855e25 commit 226aed8
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions coloraide/util.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Utilities."""
from __future__ import annotations
import math
from functools import wraps
from . import algebra as alg
from .types import Vector, VectorLike
from typing import Any, Callable

DEF_PREC = 5
DEF_FIT_TOLERANCE = 0.000075
Expand Down Expand Up @@ -204,3 +206,18 @@ def fmt_float(f: float, p: int = 0, percent: float = 0.0, offset: float = 0.0) -
if p == -1:
p = 17 # double precision
return ('{{:{}{}g}}{}'.format('' if abs(value) >= 10 ** p else '.', p, '%' if percent else '')).format(value)


def debug(func: Callable[..., Any]) -> Callable[..., Any]: # pragma: no cover
"""Intercept function call and print arguments and results."""

@wraps(func)
def _wrapper(*args: Any, **kwargs: Any) -> Any:
"""Print debug information about the function."""

print(f"<debug> Calling '{func.__name__}' with args={args} and kwargs={kwargs}")
result = func(*args, **kwargs)
print(f"<debug> '{func.__name__}' returned {result}")
return result

return _wrapper

0 comments on commit 226aed8

Please sign in to comment.