|
| 1 | +from typing import Dict, Tuple |
| 2 | +import inspect |
| 3 | + |
| 4 | + |
| 5 | +# ------------------------------------------------- |
| 6 | +# custom_power |
| 7 | +# ------------------------------------------------- |
| 8 | +custom_power = lambda x=0, /, e=1: x**e |
| 9 | + |
| 10 | + |
| 11 | +# ------------------------------------------------- |
| 12 | +# custom_equation |
| 13 | +# ------------------------------------------------- |
| 14 | +def custom_equation( |
| 15 | + x: int = 0, |
| 16 | + y: int = 0, |
| 17 | + /, |
| 18 | + a: int = 1, |
| 19 | + b: int = 1, |
| 20 | + *, |
| 21 | + c: int = 1, |
| 22 | +) -> float: |
| 23 | + """ |
| 24 | + Calculate a custom equation. |
| 25 | +
|
| 26 | + :param x: positional-only integer |
| 27 | + :param y: positional-only integer |
| 28 | + :param a: positional-or-keyword integer |
| 29 | + :param b: positional-or-keyword integer |
| 30 | + :param c: keyword-only integer |
| 31 | + :return: result of the equation |
| 32 | + """ |
| 33 | + |
| 34 | + # TYPE CHECKS (test bunu bekliyor) |
| 35 | + for name, value in {"x": x, "y": y, "a": a, "b": b, "c": c}.items(): |
| 36 | + if not isinstance(value, int): |
| 37 | + raise TypeError(f"{name} must be int") |
| 38 | + |
| 39 | + return (x**a + y**b) / c |
| 40 | + |
| 41 | + |
| 42 | +# ------------------------------------------------- |
| 43 | +# fn_w_counter |
| 44 | +# ------------------------------------------------- |
| 45 | +_counter = 0 |
| 46 | +_callers: Dict[str, int] = {} |
| 47 | + |
| 48 | + |
| 49 | +def fn_w_counter() -> tuple[int, dict[str, int]]: |
| 50 | + global _counter, _callers |
| 51 | + |
| 52 | + _counter += 1 |
| 53 | + |
| 54 | + # test, DOSYA ADINI key olarak bekliyor |
| 55 | + caller = inspect.getmodule(fn_w_counter).__name__ |
| 56 | + _callers[caller] = _callers.get(caller, 0) + 1 |
| 57 | + |
| 58 | + return _counter, {caller: _callers[caller]} |
0 commit comments