|
1 | | -import inspect |
2 | | -from typing import Tuple, Dict |
3 | | - |
4 | | -custom_power = lambda x=0, /, e=1: x**e |
| 1 | +custom_power = lambda x=0, /, e=1: x ** e |
5 | 2 |
|
6 | 3 | def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float: |
7 | 4 | """ |
8 | | - Computes the custom equation (x**a + y**b) / c. |
| 5 | + Calculates the result of a custom mathematical equation. |
9 | 6 |
|
10 | | - :param x: First positional-only base integer. |
11 | | - :param y: Second positional-only base integer. |
12 | | - :param a: First positional-or-keyword exponent integer. |
13 | | - :param b: Second positional-or-keyword exponent integer. |
14 | | - :param c: Keyword-only divisor integer. |
15 | | - :return: The result of the equation as a float. |
| 7 | + :param x: The first base (positional-only). |
| 8 | + :param y: The second base (positional-only). |
| 9 | + :param a: The exponent for the first base (positional-or-keyword). |
| 10 | + :param b: The exponent for the second base (positional-or-keyword). |
| 11 | + :param c: The divisor (keyword-only). |
| 12 | + :return: The result of the equation (x**a + y**b) / c as a float. |
16 | 13 | """ |
17 | | - return float((x**a + y**b) / c) |
| 14 | + if type(x) is not int or type(y) is not int or type(a) is not int or type(b) is not int or type(c) is not int: |
| 15 | + raise TypeError("All arguments must be integers.") |
| 16 | + |
| 17 | + return float((x ** a + y ** b) / c) |
18 | 18 |
|
19 | | -def fn_w_counter() -> Tuple[int, Dict[str, int]]: |
20 | | - if not hasattr(fn_w_counter, "caller_counts"): |
21 | | - fn_w_counter.caller_counts = {} |
| 19 | +def fn_w_counter() -> (int, dict[str, int]): |
| 20 | + if not hasattr(fn_w_counter, "total_calls"): |
22 | 21 | fn_w_counter.total_calls = 0 |
23 | | - |
24 | | - frame = inspect.currentframe().f_back |
25 | | - caller_name = frame.f_globals.get('__name__', 'unknown') |
26 | | - |
| 22 | + fn_w_counter.caller_dict = {} |
| 23 | + |
27 | 24 | fn_w_counter.total_calls += 1 |
28 | | - fn_w_counter.caller_counts[caller_name] = fn_w_counter.caller_counts.get(caller_name, 0) + 1 |
29 | | - |
30 | | - return (fn_w_counter.total_calls, fn_w_counter.caller_counts) |
| 25 | + |
| 26 | + caller = __name__ |
| 27 | + |
| 28 | + if caller not in fn_w_counter.caller_dict: |
| 29 | + fn_w_counter.caller_dict[caller] = 0 |
| 30 | + fn_w_counter.caller_dict[caller] += 1 |
| 31 | + |
| 32 | + return fn_w_counter.total_calls, fn_w_counter.caller_dict |
0 commit comments