From e0ef3f73150040ff4c1b305b2aa1fe8ef6cc341b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elif=20Yalva=C3=A7?= <59252046+elifyalvac@users.noreply.github.com> Date: Tue, 17 Mar 2026 13:48:08 +0300 Subject: [PATCH 01/10] Add custom functions and call counter Defines custom power and equation functions, and a call counter. --- Week04/functions_elif_yalvac.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Week04/functions_elif_yalvac.py diff --git a/Week04/functions_elif_yalvac.py b/Week04/functions_elif_yalvac.py new file mode 100644 index 00000000..901d44b8 --- /dev/null +++ b/Week04/functions_elif_yalvac.py @@ -0,0 +1,32 @@ +# 1. custom_power +custom_power = lambda x=0, /, e=1: x ** e + + +# 2. custom_equation +def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float: + """ + Calculates a specific mathematical expression. + + :param x: positional-only integer, default 0 + :param y: positional-only integer, default 0 + :param a: positional-or-keyword integer, default 1 + :param b: positional-or-keyword integer, default 1 + :param c: keyword-only integer, default 1 + :return: result of (x**a + y**b) / c as float + """ + return (x ** a + y ** b) / c + + + +# 3. fn_w_counter +from collections import defaultdict +import inspect +_total_calls = 0 +_caller_counts = defaultdict(int) + +def fn_w_counter() -> tuple[int, dict[str, int]]: + global _total_calls + _total_calls += 1 + caller = inspect.currentframe().f_back.f_globals.get('__name__', '') + _caller_counts[caller] += 1 + return _total_calls, dict(_caller_counts) From 0706a548965da8b81fd873b6e8af2fb289580e13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elif=20Yalva=C3=A7?= <59252046+elifyalvac@users.noreply.github.com> Date: Tue, 17 Mar 2026 13:51:37 +0300 Subject: [PATCH 02/10] Change type hints in fn_w_counter function Updated type hints to use Tuple and Dict from typing. --- Week04/functions_elif_yalvac.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week04/functions_elif_yalvac.py b/Week04/functions_elif_yalvac.py index 901d44b8..08917a9e 100644 --- a/Week04/functions_elif_yalvac.py +++ b/Week04/functions_elif_yalvac.py @@ -24,7 +24,7 @@ def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int _total_calls = 0 _caller_counts = defaultdict(int) -def fn_w_counter() -> tuple[int, dict[str, int]]: +def fn_w_counter() -> Tuple[int, Dict[str, int]]: global _total_calls _total_calls += 1 caller = inspect.currentframe().f_back.f_globals.get('__name__', '') From b8afb3cea5c069d440deb786c2902c6d7deace4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elif=20Yalva=C3=A7?= <59252046+elifyalvac@users.noreply.github.com> Date: Tue, 17 Mar 2026 13:56:47 +0300 Subject: [PATCH 03/10] Refactor fn_w_counter return type annotations Updated function return type annotations to use PEP 585 syntax. --- Week04/functions_elif_yalvac.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Week04/functions_elif_yalvac.py b/Week04/functions_elif_yalvac.py index 08917a9e..0e1c1e07 100644 --- a/Week04/functions_elif_yalvac.py +++ b/Week04/functions_elif_yalvac.py @@ -21,12 +21,13 @@ def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int # 3. fn_w_counter from collections import defaultdict import inspect + _total_calls = 0 _caller_counts = defaultdict(int) - -def fn_w_counter() -> Tuple[int, Dict[str, int]]: +def fn_w_counter() -> tuple[int, dict[str, int]]: global _total_calls _total_calls += 1 - caller = inspect.currentframe().f_back.f_globals.get('__name__', '') + caller_frame = inspect.currentframe().f_back + caller = caller_frame.f_globals.get('__name__', '') _caller_counts[caller] += 1 return _total_calls, dict(_caller_counts) From 3a4c6445b54cc9c488a22372dd8c6aa0fac40780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elif=20Yalva=C3=A7?= <59252046+elifyalvac@users.noreply.github.com> Date: Tue, 17 Mar 2026 14:00:22 +0300 Subject: [PATCH 04/10] Update type hints in fn_w_counter function --- Week04/functions_elif_yalvac.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Week04/functions_elif_yalvac.py b/Week04/functions_elif_yalvac.py index 0e1c1e07..742996c1 100644 --- a/Week04/functions_elif_yalvac.py +++ b/Week04/functions_elif_yalvac.py @@ -21,13 +21,13 @@ def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int # 3. fn_w_counter from collections import defaultdict import inspect +from typing import Tuple, Dict -_total_calls = 0 -_caller_counts = defaultdict(int) -def fn_w_counter() -> tuple[int, dict[str, int]]: +def fn_w_counter() -> Tuple[int, Dict[str, int]]: global _total_calls _total_calls += 1 - caller_frame = inspect.currentframe().f_back - caller = caller_frame.f_globals.get('__name__', '') + current_frame = inspect.currentframe() + caller_frame = current_frame.f_back + caller = caller_frame.f_globals.get('__name__', '') _caller_counts[caller] += 1 return _total_calls, dict(_caller_counts) From 1e09165ca5dc73af178096b31c35650257adc30c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elif=20Yalva=C3=A7?= <59252046+elifyalvac@users.noreply.github.com> Date: Tue, 17 Mar 2026 14:05:01 +0300 Subject: [PATCH 05/10] Update functions_elif_yalvac.py --- Week04/functions_elif_yalvac.py | 41 ++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/Week04/functions_elif_yalvac.py b/Week04/functions_elif_yalvac.py index 742996c1..07b031b7 100644 --- a/Week04/functions_elif_yalvac.py +++ b/Week04/functions_elif_yalvac.py @@ -1,33 +1,36 @@ -# 1. custom_power -custom_power = lambda x=0, /, e=1: x ** e +from collections import defaultdict +import inspect +from typing import Tuple, Dict + +_total_calls = 0 +_caller_counts = defaultdict(int) + +# 1. custom_power: +custom_power = lambda x=0, e=1, / : x ** e -# 2. custom_equation +# 2. custom_equation: def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float: """ - Calculates a specific mathematical expression. - - :param x: positional-only integer, default 0 - :param y: positional-only integer, default 0 - :param a: positional-or-keyword integer, default 1 - :param b: positional-or-keyword integer, default 1 - :param c: keyword-only integer, default 1 - :return: result of (x**a + y**b) / c as float + Calculates a specific mathematical expression. + + :param x: positional-only integer, default 0 + :param y: positional-only integer, default 0 + :param a: positional-or-keyword integer, default 1 + :param b: positional-or-keyword integer, default 1 + :param c: keyword-only integer, default 1 + :return: result of (x**a + y**b) / c as float """ - return (x ** a + y ** b) / c - + return float((x**a + y**b) / c) -# 3. fn_w_counter -from collections import defaultdict -import inspect -from typing import Tuple, Dict +# 3. fn_w_counter: def fn_w_counter() -> Tuple[int, Dict[str, int]]: - global _total_calls + global _total_calls, _caller_counts _total_calls += 1 current_frame = inspect.currentframe() caller_frame = current_frame.f_back - caller = caller_frame.f_globals.get('__name__', '') + caller = caller_frame.f_globals.get('__name__', '') _caller_counts[caller] += 1 return _total_calls, dict(_caller_counts) From d2e83dccc66585c12651447777bab18320d0d323 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elif=20Yalva=C3=A7?= <59252046+elifyalvac@users.noreply.github.com> Date: Tue, 17 Mar 2026 14:08:34 +0300 Subject: [PATCH 06/10] Refactor comments and improve function definitions --- Week04/functions_elif_yalvac.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Week04/functions_elif_yalvac.py b/Week04/functions_elif_yalvac.py index 07b031b7..47af866f 100644 --- a/Week04/functions_elif_yalvac.py +++ b/Week04/functions_elif_yalvac.py @@ -5,11 +5,10 @@ _total_calls = 0 _caller_counts = defaultdict(int) -# 1. custom_power: +# 1. custom_power custom_power = lambda x=0, e=1, / : x ** e - -# 2. custom_equation: +# 2. custom_equation def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float: """ Calculates a specific mathematical expression. @@ -21,13 +20,13 @@ def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int :param c: keyword-only integer, default 1 :return: result of (x**a + y**b) / c as float """ - +n: Hesaplama sonucu float olarak doner. + """ return float((x**a + y**b) / c) - -# 3. fn_w_counter: +# 3. fn_w_counter def fn_w_counter() -> Tuple[int, Dict[str, int]]: - global _total_calls, _caller_counts + global _total_calls _total_calls += 1 current_frame = inspect.currentframe() caller_frame = current_frame.f_back From e435aba58cc9b800ffebbf6efeb66d5ac689d14b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elif=20Yalva=C3=A7?= <59252046+elifyalvac@users.noreply.github.com> Date: Tue, 17 Mar 2026 14:09:29 +0300 Subject: [PATCH 07/10] Clean up docstring in functions_elif_yalvac.py Remove unnecessary docstring line in the function. --- Week04/functions_elif_yalvac.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Week04/functions_elif_yalvac.py b/Week04/functions_elif_yalvac.py index 47af866f..bc061d40 100644 --- a/Week04/functions_elif_yalvac.py +++ b/Week04/functions_elif_yalvac.py @@ -20,8 +20,6 @@ def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int :param c: keyword-only integer, default 1 :return: result of (x**a + y**b) / c as float """ -n: Hesaplama sonucu float olarak doner. - """ return float((x**a + y**b) / c) # 3. fn_w_counter From bc71ed3c27d353fcd8e350e8de39898a8b7b544f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elif=20Yalva=C3=A7?= <59252046+elifyalvac@users.noreply.github.com> Date: Tue, 17 Mar 2026 14:15:40 +0300 Subject: [PATCH 08/10] Refactor custom_power and custom_equation functions Updated function signatures and added type checks in custom_equation. --- Week04/functions_elif_yalvac.py | 36 +++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/Week04/functions_elif_yalvac.py b/Week04/functions_elif_yalvac.py index bc061d40..3873eb3d 100644 --- a/Week04/functions_elif_yalvac.py +++ b/Week04/functions_elif_yalvac.py @@ -6,28 +6,34 @@ _caller_counts = defaultdict(int) # 1. custom_power -custom_power = lambda x=0, e=1, / : x ** e +custom_power = lambda x=0, /, e=1: x ** e + # 2. custom_equation -def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float: +def custom_equation(x: int = 0, y: int = 0, /, + a: int = 1, b: int = 1, *, + c: int = 1) -> float: """ - Calculates a specific mathematical expression. - - :param x: positional-only integer, default 0 - :param y: positional-only integer, default 0 - :param a: positional-or-keyword integer, default 1 - :param b: positional-or-keyword integer, default 1 - :param c: keyword-only integer, default 1 - :return: result of (x**a + y**b) / c as float + Calculates a specific mathematical expression. + + :param x: positional-only integer, default 0 + :param y: positional-only integer, default 0 + :param a: positional-or-keyword integer, default 1 + :param b: positional-or-keyword integer, default 1 + :param c: keyword-only integer, default 1 + :return: result of (x**a + y**b) / c as float """ - return float((x**a + y**b) / c) + for val in (x, y, a, b, c): + if not isinstance(val, int): + raise TypeError("must be int") + + return (x ** a + y ** b) / c + # 3. fn_w_counter -def fn_w_counter() -> Tuple[int, Dict[str, int]]: +def fn_w_counter() -> (int, dict[str, int]): global _total_calls _total_calls += 1 - current_frame = inspect.currentframe() - caller_frame = current_frame.f_back - caller = caller_frame.f_globals.get('__name__', '') + caller = inspect.stack()[1].frame.f_globals.get("__name__", "") _caller_counts[caller] += 1 return _total_calls, dict(_caller_counts) From 1be74fc3de6b5eb1a0f9471f06992acd96b11552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elif=20Yalva=C3=A7?= <59252046+elifyalvac@users.noreply.github.com> Date: Tue, 17 Mar 2026 14:21:44 +0300 Subject: [PATCH 09/10] Remove unused import and simplify caller retrieval --- Week04/functions_elif_yalvac.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Week04/functions_elif_yalvac.py b/Week04/functions_elif_yalvac.py index 3873eb3d..bdbbf217 100644 --- a/Week04/functions_elif_yalvac.py +++ b/Week04/functions_elif_yalvac.py @@ -1,5 +1,4 @@ from collections import defaultdict -import inspect from typing import Tuple, Dict _total_calls = 0 @@ -23,6 +22,7 @@ def custom_equation(x: int = 0, y: int = 0, /, :param c: keyword-only integer, default 1 :return: result of (x**a + y**b) / c as float """ + for val in (x, y, a, b, c): if not isinstance(val, int): raise TypeError("must be int") @@ -34,6 +34,6 @@ def custom_equation(x: int = 0, y: int = 0, /, def fn_w_counter() -> (int, dict[str, int]): global _total_calls _total_calls += 1 - caller = inspect.stack()[1].frame.f_globals.get("__name__", "") + caller = __name__ _caller_counts[caller] += 1 return _total_calls, dict(_caller_counts) From 0a346b7d07d9e9c93cb85c55e8350577c551f333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elif=20Yalva=C3=A7?= <59252046+elifyalvac@users.noreply.github.com> Date: Thu, 19 Mar 2026 00:43:05 +0300 Subject: [PATCH 10/10] Refactor functions_elif_yalvac.py to improve clarity Removed unused imports and global variables. Updated fn_w_counter to use a function attribute for counting calls. --- Week04/functions_elif_yalvac.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/Week04/functions_elif_yalvac.py b/Week04/functions_elif_yalvac.py index bdbbf217..b14e51ce 100644 --- a/Week04/functions_elif_yalvac.py +++ b/Week04/functions_elif_yalvac.py @@ -1,13 +1,8 @@ -from collections import defaultdict -from typing import Tuple, Dict - -_total_calls = 0 -_caller_counts = defaultdict(int) - # 1. custom_power custom_power = lambda x=0, /, e=1: x ** e + # 2. custom_equation def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, @@ -26,14 +21,13 @@ def custom_equation(x: int = 0, y: int = 0, /, for val in (x, y, a, b, c): if not isinstance(val, int): raise TypeError("must be int") - return (x ** a + y ** b) / c + # 3. fn_w_counter def fn_w_counter() -> (int, dict[str, int]): - global _total_calls - _total_calls += 1 - caller = __name__ - _caller_counts[caller] += 1 - return _total_calls, dict(_caller_counts) + if not hasattr(fn_w_counter, "count"): + fn_w_counter.count = 0 + fn_w_counter.count += 1 + return fn_w_counter.count, {__name__.split('.')[-1]: fn_w_counter.count}