From 76e00a301a9c4073a7fd3e24d77949f951b5f499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Recep=20G=C3=B6ktu=C4=9F=20Avc=C4=B1?= Date: Tue, 31 Mar 2026 06:37:26 +0300 Subject: [PATCH 1/4] Week04_decorators_by_goktugavci --- Week04/decorators_recepgoktug_avci.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Week04/decorators_recepgoktug_avci.py diff --git a/Week04/decorators_recepgoktug_avci.py b/Week04/decorators_recepgoktug_avci.py new file mode 100644 index 00000000..a9ce34e1 --- /dev/null +++ b/Week04/decorators_recepgoktug_avci.py @@ -0,0 +1,24 @@ +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: + + + for val in (x, y, a, b, c): + if not isinstance(val, int): + raise TypeError("Arguments must be integers") + + return float((x ** a + y ** b) / c) + + +def fn_w_counter() -> (int, dict[str, int]): + if not hasattr(fn_w_counter, "count"): + fn_w_counter.count = 0 + + fn_w_counter.count += 1 + + module_name = __name__.split('.')[-1] + + return fn_w_counter.count, {module_name: fn_w_counter.count} From fe4407f34984dd3f9e080b3db8107125821c3a57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Recep=20G=C3=B6ktu=C4=9F=20Avc=C4=B1?= Date: Tue, 31 Mar 2026 06:39:15 +0300 Subject: [PATCH 2/4] Week04_decorators_by_goktugavci Added performance decorator to measure execution time and memory usage. --- Week04/decorators_recepgoktug_avci.py | 52 ++++++++++++++------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/Week04/decorators_recepgoktug_avci.py b/Week04/decorators_recepgoktug_avci.py index a9ce34e1..fe1b5872 100644 --- a/Week04/decorators_recepgoktug_avci.py +++ b/Week04/decorators_recepgoktug_avci.py @@ -1,24 +1,28 @@ -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: - - - for val in (x, y, a, b, c): - if not isinstance(val, int): - raise TypeError("Arguments must be integers") - - return float((x ** a + y ** b) / c) - - -def fn_w_counter() -> (int, dict[str, int]): - if not hasattr(fn_w_counter, "count"): - fn_w_counter.count = 0 - - fn_w_counter.count += 1 - - module_name = __name__.split('.')[-1] - - return fn_w_counter.count, {module_name: fn_w_counter.count} +import time +import tracemalloc + +def performance(func): + if not hasattr(performance, "counter"): + performance.counter = 0 + performance.total_time = 0.0 + performance.total_mem = 0 + + def wrapper(*args, **kwargs): + tracemalloc.start() + start_time = time.perf_counter() + + result = func(*args, **kwargs) + + end_time = time.perf_counter() + elapsed_time = end_time - start_time + + current_mem, peak_mem = tracemalloc.get_traced_memory() + tracemalloc.stop() + + performance.counter += 1 + performance.total_time += elapsed_time + performance.total_mem += peak_mem + + return result + + return wrapper From b30f4286ed0270af8aa2c74629be6d4b0367aab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Recep=20G=C3=B6ktu=C4=9F=20Avc=C4=B1?= Date: Tue, 31 Mar 2026 06:40:11 +0300 Subject: [PATCH 3/4] Week04_functions_by_goktugavci Adds custom power and equation functions with input validation. --- Week04/functions_recepgoktug_avci.py | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Week04/functions_recepgoktug_avci.py diff --git a/Week04/functions_recepgoktug_avci.py b/Week04/functions_recepgoktug_avci.py new file mode 100644 index 00000000..0c90c5c7 --- /dev/null +++ b/Week04/functions_recepgoktug_avci.py @@ -0,0 +1,34 @@ + +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: + """ + Calculates the mathematical equation. + + :param x: The first base value. + :param y: The second base value. + :param a: The exponent for x. + :param b: The exponent for y. + :param c: The divisor. + :return: The result of the equation. + """ + + if not all(isinstance(arg, int) for arg in (x, y, a, b, c)): + raise TypeError("All arguments must be integers.") + + return float((x**a + y**b) / c) + + +def fn_w_counter() -> (int, dict[str, int]): + if not hasattr(fn_w_counter, "total_calls"): + fn_w_counter.total_calls = 0 + fn_w_counter.caller_info = {} + + fn_w_counter.total_calls += 1 + + caller_name = __name__ + + fn_w_counter.caller_info[caller_name] = fn_w_counter.caller_info.get(caller_name, 0) + 1 + + return fn_w_counter.total_calls, fn_w_counter.caller_info.copy() From e62d50a415fd987570152df8c8e1a81a6296a082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Recep=20G=C3=B6ktu=C4=9F=20Avc=C4=B1?= Date: Tue, 31 Mar 2026 06:41:51 +0300 Subject: [PATCH 4/4] Week04_awaitme_by_goktugavci --- Week05/awaitme_recepgoktug_avci.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Week05/awaitme_recepgoktug_avci.py diff --git a/Week05/awaitme_recepgoktug_avci.py b/Week05/awaitme_recepgoktug_avci.py new file mode 100644 index 00000000..0c828f4f --- /dev/null +++ b/Week05/awaitme_recepgoktug_avci.py @@ -0,0 +1,17 @@ +import asyncio + +def awaitme(fn): + if asyncio.iscoroutinefunction(fn): + return fn + + async def wrapper(*args, **kwargs): + return fn(*args, **kwargs) + + try: + wrapper.__name__ = fn.__name__ + wrapper.__doc__ = fn.__doc__ + wrapper.__annotations__ = fn.__annotations__ + except (AttributeError, TypeError): + pass + + return wrapper