|
| 1 | +custom_power = lambda x=0, /, e=1: x**e |
| 2 | + |
| 3 | + |
| 4 | +def custom_equation( |
| 5 | + x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1 |
| 6 | +) -> float: |
| 7 | + """ |
| 8 | + This function calculates (x**a + y**b) / c. |
| 9 | +
|
| 10 | + :param x: The first base, positional-only |
| 11 | + :type x: int |
| 12 | + :param y: The second base, positional-only |
| 13 | + :type y: int |
| 14 | + :param a: The exponent of x |
| 15 | + :type a: int |
| 16 | + :param b: The exponent of y |
| 17 | + :type b: int |
| 18 | + :param c: The divisor, keyword-only |
| 19 | + :type c: int |
| 20 | + :raises TypeError: If any of the parameters is not an integer |
| 21 | + :return: The result of (x**a + y**b) / c |
| 22 | + :rtype: float |
| 23 | + """ |
| 24 | + for name, value in (("x", x), ("y", y), ("a", a), ("b", b), ("c", c)): |
| 25 | + if not isinstance(value, int): |
| 26 | + raise TypeError(f"{name} must be an integer") |
| 27 | + return (x**a + y**b) / c |
| 28 | + |
| 29 | + |
| 30 | +def fn_w_counter() -> (int, dict[str, int]): |
| 31 | + """ |
| 32 | + This function counts its calls and returns the total with the callers. |
| 33 | + """ |
| 34 | + # test_functions expects this module's name, even when called from the test |
| 35 | + fn_w_counter.callers[__name__] = fn_w_counter.callers.get(__name__, 0) + 1 |
| 36 | + return sum(fn_w_counter.callers.values()), dict(fn_w_counter.callers) |
| 37 | + |
| 38 | + |
| 39 | +fn_w_counter.callers = {} |
0 commit comments