From 04fe414fb2200f27bd50bbe6d1bc5b4e184a67b8 Mon Sep 17 00:00:00 2001 From: cemil koca Date: Sun, 5 Apr 2026 15:36:12 +0300 Subject: [PATCH 1/5] Add files via upload --- Week04/decorators_cemil_koca.py | 25 +++++++++++++++++++++++++ Week04/functions_cemil_koca.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 Week04/decorators_cemil_koca.py create mode 100644 Week04/functions_cemil_koca.py diff --git a/Week04/decorators_cemil_koca.py b/Week04/decorators_cemil_koca.py new file mode 100644 index 00000000..bbb1fa96 --- /dev/null +++ b/Week04/decorators_cemil_koca.py @@ -0,0 +1,25 @@ +import time +import tracemalloc + +def performance(fn): + def _performance(*args, **kwargs): # wraps yok, düz wrapper + performance.counter += 1 + + tracemalloc.start() + start = time.perf_counter() + + result = fn(*args, **kwargs) + + elapsed = time.perf_counter() - start + _, peak = tracemalloc.get_traced_memory() + tracemalloc.stop() + + performance.total_time += elapsed + performance.total_mem += peak + + return result + return _performance + +performance.counter = 0 +performance.total_time = 0 +performance.total_mem = 0 \ No newline at end of file diff --git a/Week04/functions_cemil_koca.py b/Week04/functions_cemil_koca.py new file mode 100644 index 00000000..01aaf04f --- /dev/null +++ b/Week04/functions_cemil_koca.py @@ -0,0 +1,30 @@ +custom_power = lambda x=0, /, e=1: x**e + +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: Base value 1. + :type x: int + :param y: Base value 2. + :type y: int + :param a: Exponent for x. + :type a: int + :param b: Exponent for y. + :type b: int + :param c: Divisor. + :type c: int + :return: Result of (x**a + y**b) / c. + :rtype: float + """ + return (x**a + y**b) / c +import inspect + +def fn_w_counter() -> tuple[int, dict[str, int]]: + """Count function calls with caller information.""" + fn_w_counter.total += 1 + caller_name = inspect.stack()[1][0].f_globals["__name__"] + fn_w_counter.callers[caller_name] = fn_w_counter.callers.get(caller_name, 0) + 1 + return (fn_w_counter.total, dict(fn_w_counter.callers)) + +fn_w_counter.total = 0 +fn_w_counter.callers = {} \ No newline at end of file From 88b9599ecf69cc20963e431bedfa9ec6ba412d1c Mon Sep 17 00:00:00 2001 From: cemil koca Date: Sun, 5 Apr 2026 15:44:54 +0300 Subject: [PATCH 2/5] Refactor functions and fix formatting issues --- Week04/functions_cemil_koca.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week04/functions_cemil_koca.py b/Week04/functions_cemil_koca.py index 01aaf04f..e7044955 100644 --- a/Week04/functions_cemil_koca.py +++ b/Week04/functions_cemil_koca.py @@ -27,4 +27,4 @@ def fn_w_counter() -> tuple[int, dict[str, int]]: return (fn_w_counter.total, dict(fn_w_counter.callers)) fn_w_counter.total = 0 -fn_w_counter.callers = {} \ No newline at end of file +fn_w_counter.callers = {} From 60420a42f618e5a04ee441ba0914b4414f97aa77 Mon Sep 17 00:00:00 2001 From: cemil koca Date: Sun, 5 Apr 2026 15:53:42 +0300 Subject: [PATCH 3/5] Update functions_cemil_koca.py --- Week04/functions_cemil_koca.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Week04/functions_cemil_koca.py b/Week04/functions_cemil_koca.py index e7044955..14aa98f1 100644 --- a/Week04/functions_cemil_koca.py +++ b/Week04/functions_cemil_koca.py @@ -1,3 +1,4 @@ +import inspect custom_power = lambda x=0, /, e=1: x**e def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float: @@ -17,8 +18,7 @@ def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int :rtype: float """ return (x**a + y**b) / c -import inspect - + def fn_w_counter() -> tuple[int, dict[str, int]]: """Count function calls with caller information.""" fn_w_counter.total += 1 From 76e2c4ffcd2d4531f369270b9bfe8e09084ed55f Mon Sep 17 00:00:00 2001 From: cemil koca Date: Sun, 5 Apr 2026 16:04:24 +0300 Subject: [PATCH 4/5] Update functions_cemil_koca.py --- Week04/functions_cemil_koca.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Week04/functions_cemil_koca.py b/Week04/functions_cemil_koca.py index 14aa98f1..065e06ad 100644 --- a/Week04/functions_cemil_koca.py +++ b/Week04/functions_cemil_koca.py @@ -1,6 +1,6 @@ -import inspect custom_power = lambda x=0, /, e=1: x**e + def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float: """Calculate a custom equation. @@ -17,14 +17,19 @@ def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int :return: Result of (x**a + y**b) / c. :rtype: float """ + for param in (x, y, a, b, c): + if not isinstance(param, int) or isinstance(param, bool): + raise TypeError("All parameters must be integers.") return (x**a + y**b) / c - -def fn_w_counter() -> tuple[int, dict[str, int]]: + + +def fn_w_counter() -> (int, dict[str, int]): """Count function calls with caller information.""" fn_w_counter.total += 1 - caller_name = inspect.stack()[1][0].f_globals["__name__"] + caller_name = __name__ fn_w_counter.callers[caller_name] = fn_w_counter.callers.get(caller_name, 0) + 1 return (fn_w_counter.total, dict(fn_w_counter.callers)) + fn_w_counter.total = 0 fn_w_counter.callers = {} From c4f6ac581dc5ab8af4e0be33d3d523809a379099 Mon Sep 17 00:00:00 2001 From: cemil koca Date: Sun, 5 Apr 2026 16:22:31 +0300 Subject: [PATCH 5/5] Add files via upload --- Week05/awaitme_cemil_koca.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Week05/awaitme_cemil_koca.py diff --git a/Week05/awaitme_cemil_koca.py b/Week05/awaitme_cemil_koca.py new file mode 100644 index 00000000..6a2ecb10 --- /dev/null +++ b/Week05/awaitme_cemil_koca.py @@ -0,0 +1,7 @@ +def awaitme(fn): + async def _wrapper(*args, **kwargs): + return fn(*args, **kwargs) + _wrapper.__name__ = fn.__name__ + _wrapper.__doc__ = fn.__doc__ + _wrapper.__annotations__ = fn.__annotations__ + return _wrapper \ No newline at end of file