Skip to content

Commit 589b917

Browse files
authored
Refactor fn_w_counter for clarity and type annotation
Refactor fn_w_counter function to simplify caller name retrieval and adjust return type annotation.
1 parent 5a5b1e3 commit 589b917

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

‎Week04/functions_esra_sepik.py‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import inspect
2-
31
custom_power = lambda x=0, /, e=1: x ** e
42

53

@@ -30,11 +28,9 @@ def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int
3028
_caller_counts: dict[str, int] = {}
3129

3230

33-
def fn_w_counter() -> tuple[int, dict[str, int]]:
31+
def fn_w_counter() -> (int, dict[str, int]):
3432
global _call_count
35-
frame = inspect.stack()[1].frame
36-
caller_name = frame.f_globals["__name__"]
37-
del frame
33+
caller_name = globals()["__name__"]
3834
_call_count += 1
3935
_caller_counts[caller_name] = _caller_counts.setdefault(caller_name, 0) + 1
4036
return (_call_count, dict(_caller_counts))

0 commit comments

Comments
 (0)