forked from canbula/PythonProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions_helin_harman.py
More file actions
55 lines (41 loc) · 1.3 KB
/
functions_helin_harman.py
File metadata and controls
55 lines (41 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import inspect
# -------------------------------------------------
# custom_power
# -------------------------------------------------
custom_power = lambda x=0, /, e=1: x**e
# -------------------------------------------------
# custom_equation
# -------------------------------------------------
def custom_equation(
x: int = 0,
y: int = 0,
/,
a: int = 1,
b: int = 1,
*,
c: int = 1,
) -> float:
"""
Calculate a custom equation.
:param x: positional-only integer
:param y: positional-only integer
:param a: positional-or-keyword integer
:param b: positional-or-keyword integer
:param c: keyword-only integer
:return: result of the equation
"""
for name, value in {"x": x, "y": y, "a": a, "b": b, "c": c}.items():
if not isinstance(value, int):
raise TypeError(f"{name} must be int")
return (x**a + y**b) / c
# -------------------------------------------------
# fn_w_counter
# -------------------------------------------------
_counter = 0
_callers = {}
def fn_w_counter() -> (int, dict[str, int]):
global _counter, _callers
_counter += 1
module_name = inspect.getmodule(fn_w_counter).__name__
_callers[module_name] = _callers.get(module_name, 0) + 1
return _counter, {module_name: _callers[module_name]}