From d86b53bd621ada37ba9e1151b64093987020b361 Mon Sep 17 00:00:00 2001 From: Ervand1989 Date: Sun, 6 Oct 2024 12:33:06 +0200 Subject: [PATCH 1/3] 'Ervand' --- level_1/1.py | 2 +- level_1/10.py | 3 ++- level_1/2.py | 2 +- level_1/3.py | 8 +++++--- level_1/4.py | 2 +- level_1/5.py | 2 +- level_1/6.py | 9 ++++++--- level_1/7.py | 5 +++-- level_1/8.py | 2 +- level_1/9.py | 3 ++- level_2/1.py | 3 ++- level_2/10.py | 3 ++- level_2/2.py | 6 ++++-- level_2/3.py | 9 ++++++--- level_2/4.py | 3 ++- level_2/5.py | 2 +- level_2/6.py | 3 ++- level_2/7.py | 6 ++++-- level_2/8.py | 3 ++- level_2/9.py | 4 +++- level_3/1.py | 9 ++++++--- level_3/2.py | 10 ++++++++-- level_3/3.py | 3 ++- 23 files changed, 67 insertions(+), 35 deletions(-) diff --git a/level_1/1.py b/level_1/1.py index 1813c9f..97ba86b 100644 --- a/level_1/1.py +++ b/level_1/1.py @@ -1,7 +1,7 @@ from constants import ___ -def is_user_banned(user_id: ___) -> ___: +def is_user_banned(user_id: int) -> bool: pass diff --git a/level_1/10.py b/level_1/10.py index 77bbaf3..480f638 100644 --- a/level_1/10.py +++ b/level_1/10.py @@ -1,7 +1,8 @@ from constants import ___ +from typing import Any -def stringify(value: ___) -> ___: +def stringify(value: Any) -> str: pass diff --git a/level_1/2.py b/level_1/2.py index 8a2c1bf..8558a13 100644 --- a/level_1/2.py +++ b/level_1/2.py @@ -1,7 +1,7 @@ from constants import ___ -def is_adult(age: ___, country_name: ___) -> ___: +def is_adult(age: int, country_name: str) -> bool: pass diff --git a/level_1/3.py b/level_1/3.py index ae55bfd..c7792a6 100644 --- a/level_1/3.py +++ b/level_1/3.py @@ -1,10 +1,12 @@ from constants import ___ -def compose_full_name(first_name: ___, last_name: ___, middle_name: ___) -> ___: +def compose_full_name(first_name: str, last_name: str, middle_name: str) -> str: pass if __name__ == "__main__": - assert compose_full_name(first_name="John", last_name="Doe", middle_name=None) == "Doe John" - assert compose_full_name(first_name="Ilya", last_name="Lebedev", middle_name="Alexeyevich") == "Lebedev Ilya Alexeyevich" + assert compose_full_name( + first_name="John", last_name="Doe", middle_name=None) == "Doe John" + assert compose_full_name(first_name="Ilya", last_name="Lebedev", + middle_name="Alexeyevich") == "Lebedev Ilya Alexeyevich" diff --git a/level_1/4.py b/level_1/4.py index 4b4cbe5..b6c2041 100644 --- a/level_1/4.py +++ b/level_1/4.py @@ -3,7 +3,7 @@ from constants import ___ -def calculate_age(date_of_birth: ___) -> ___: +def calculate_age(date_of_birth: datetime) -> int: pass diff --git a/level_1/5.py b/level_1/5.py index 0728530..9b06931 100644 --- a/level_1/5.py +++ b/level_1/5.py @@ -1,7 +1,7 @@ from constants import ___ -def is_correct_email(raw_email: ___) -> ___: +def is_correct_email(raw_email: str) -> bool: pass diff --git a/level_1/6.py b/level_1/6.py index 7cb57fc..15eb2b5 100644 --- a/level_1/6.py +++ b/level_1/6.py @@ -1,10 +1,13 @@ from constants import ___ +from typing import Optional -def is_loan_amount_too_big(loan_amount_usd: ___, max_loan_amount_for_user_usd: ___) -> ___: +def is_loan_amount_too_big(loan_amount_usd: Optional[int], max_loan_amount_for_user_usd: Optional[int]) -> bool: pass if __name__ == "__main__": - assert is_loan_amount_too_big(loan_amount_usd=1000, max_loan_amount_for_user_usd=4000) is False - assert is_loan_amount_too_big(loan_amount_usd=1000, max_loan_amount_for_user_usd=None) is False + assert is_loan_amount_too_big( + loan_amount_usd=1000, max_loan_amount_for_user_usd=4000) is False + assert is_loan_amount_too_big( + loan_amount_usd=1000, max_loan_amount_for_user_usd=None) is False diff --git a/level_1/7.py b/level_1/7.py index 68c6890..0b57234 100644 --- a/level_1/7.py +++ b/level_1/7.py @@ -1,9 +1,10 @@ from constants import ___ -def send_email(header: ___, text_content: ___, send_to: ___) -> ___: +def send_email(header: str, text_content: str, send_to: str) -> None: pass if __name__ == "__main__": - assert send_email(header="Test email", text_content="This is a test email", send_to="test@gmail.com") is None + assert send_email(header="Test email", text_content="This is a test email", + send_to="test@gmail.com") is None diff --git a/level_1/8.py b/level_1/8.py index 8ba8083..f009c27 100644 --- a/level_1/8.py +++ b/level_1/8.py @@ -4,7 +4,7 @@ from constants import ___ -def get_user_balance(user_id: ___) -> ___: +def get_user_balance(user_id: uuid.UUID) -> decimal.Decimal: pass diff --git a/level_1/9.py b/level_1/9.py index 215588a..17b426f 100644 --- a/level_1/9.py +++ b/level_1/9.py @@ -1,7 +1,8 @@ from constants import ___ +from typing import Optional -def is_correct_int(raw_int: ___) -> ___: +def is_correct_int(raw_int: Optional[str]) -> bool: pass diff --git a/level_2/1.py b/level_2/1.py index c6ead64..3e40c1c 100644 --- a/level_2/1.py +++ b/level_2/1.py @@ -1,7 +1,8 @@ from constants import ___ +from typing import List -def get_avg_currency_rate(rates_history: ___) -> ___: +def get_avg_currency_rate(rates_history: List[float]) -> float: pass diff --git a/level_2/10.py b/level_2/10.py index 69f7bd0..6af8fc2 100644 --- a/level_2/10.py +++ b/level_2/10.py @@ -1,7 +1,8 @@ from constants import ___ +from typing import Tuple -def is_point_in_square(point: ___, left_upper_corner: ___, right_bottom_corner: ___) -> ___: +def is_point_in_square(point: Tuple[int, int], left_upper_corner: Tuple[int, int], right_bottom_corner: Tuple[int, int]) -> bool: pass diff --git a/level_2/2.py b/level_2/2.py index e2ab2aa..76a45fd 100644 --- a/level_2/2.py +++ b/level_2/2.py @@ -1,9 +1,11 @@ from constants import ___ +from typing import List -def is_recovery_code_correct(code: ___, user_codes: ___) -> ___: +def is_recovery_code_correct(code: str, user_codes: List[str]) -> bool: pass if __name__ == "__main__": - assert is_recovery_code_correct(code="5212", user_codes=["1862", "8172", "7212"]) is False + assert is_recovery_code_correct(code="5212", user_codes=[ + "1862", "8172", "7212"]) is False diff --git a/level_2/3.py b/level_2/3.py index 8487e4b..2087709 100644 --- a/level_2/3.py +++ b/level_2/3.py @@ -1,9 +1,10 @@ import decimal +from typing import Dict, Optional from constants import ___ -def get_transaction_amount(transaction_id: ___, transactions_amounts_map: ___) -> ___: +def get_transaction_amount(transaction_id: int, transactions_amounts_map: Dict[int: decimal.Decimal]) -> Optional[str]: pass @@ -13,5 +14,7 @@ def get_transaction_amount(transaction_id: ___, transactions_amounts_map: ___) - 514: decimal.Decimal("164.1"), 372: decimal.Decimal("92"), } - assert get_transaction_amount(transaction_id=156, transactions_amounts_map=transactions_amounts_map) == decimal.Decimal("30.6") - assert get_transaction_amount(transaction_id=1000, transactions_amounts_map=transactions_amounts_map) is None + assert get_transaction_amount( + transaction_id=156, transactions_amounts_map=transactions_amounts_map) == decimal.Decimal("30.6") + assert get_transaction_amount( + transaction_id=1000, transactions_amounts_map=transactions_amounts_map) is None diff --git a/level_2/4.py b/level_2/4.py index 791b2e0..ff21865 100644 --- a/level_2/4.py +++ b/level_2/4.py @@ -1,7 +1,8 @@ from constants import ___ +from typing import Set -def ban_users(users_ids: ___) -> ___: +def ban_users(users_ids: Set[int]) -> int: pass diff --git a/level_2/5.py b/level_2/5.py index 2b0ce2d..b6b86f4 100644 --- a/level_2/5.py +++ b/level_2/5.py @@ -1,7 +1,7 @@ from constants import ___ -def get_current_user() -> ___: +def get_current_user() -> tuple[str, int, str]: pass diff --git a/level_2/6.py b/level_2/6.py index af117e9..386e011 100644 --- a/level_2/6.py +++ b/level_2/6.py @@ -1,7 +1,8 @@ from constants import ___ +from typing import Dict, Optional -def is_name_male(name: ___, name_gender_map: ___) -> ___: +def is_name_male(name: str, name_gender_map: Dict[str: bool]) -> Optional[bool]: pass diff --git a/level_2/7.py b/level_2/7.py index f8f7f6f..1140656 100644 --- a/level_2/7.py +++ b/level_2/7.py @@ -1,9 +1,11 @@ from constants import ___ +from typing import Tuple, List -def calculate_total_spent_for_user(user: ___) -> ___: +def calculate_total_spent_for_user(user: Tuple[str, int, List[int]]) -> int: pass if __name__ == "__main__": - assert calculate_total_spent_for_user(user=("Ilya", 32, [102, 15, 63, 12])) == 192 + assert calculate_total_spent_for_user( + user=("Ilya", 32, [102, 15, 63, 12])) == 192 diff --git a/level_2/8.py b/level_2/8.py index 1801197..2ec2b29 100644 --- a/level_2/8.py +++ b/level_2/8.py @@ -1,7 +1,8 @@ from constants import ___ +from typing import Set, Dict, Tuple, List -def calculate_total_spent_for_users(users_ids: ___, users_ids_to_users_map: ___) -> ___: +def calculate_total_spent_for_users(users_ids: Set[int], users_ids_to_users_map: Dict[int, Tuple[str, int, List[int]]]) -> int: pass diff --git a/level_2/9.py b/level_2/9.py index 693804a..1fc1d18 100644 --- a/level_2/9.py +++ b/level_2/9.py @@ -1,9 +1,11 @@ import datetime from constants import ___ +from typing import List, Set, Tuple +from datetime import date -def parse_receipt(raw_receipt: ___) -> ___: +def parse_receipt(raw_receipt: str) -> Tuple[int, date, List[Tuple[str, int, float]]]: pass diff --git a/level_3/1.py b/level_3/1.py index 9578f5e..901573f 100644 --- a/level_3/1.py +++ b/level_3/1.py @@ -1,9 +1,10 @@ import decimal from constants import ___ +from typing import Mapping, Optional -def get_transaction_amount(transaction_id: ___, transactions_amounts_map: ___) -> ___: +def get_transaction_amount(transaction_id: int, transactions_amounts_map: Mapping[int, decimal.Decimal]) -> Optional[decimal.Decimal]: # попробуйте использовать typing.Mapping: transactions_amounts_map по смыслу не должен меняться внутри функции pass @@ -14,5 +15,7 @@ def get_transaction_amount(transaction_id: ___, transactions_amounts_map: ___) - 514: decimal.Decimal("164.1"), 372: decimal.Decimal("92"), } - assert get_transaction_amount(transaction_id=156, transactions_amounts_map=transactions_amounts_map) == decimal.Decimal("30.6") - assert get_transaction_amount(transaction_id=1000, transactions_amounts_map=transactions_amounts_map) is None + assert get_transaction_amount( + transaction_id=156, transactions_amounts_map=transactions_amounts_map) == decimal.Decimal("30.6") + assert get_transaction_amount( + transaction_id=1000, transactions_amounts_map=transactions_amounts_map) is None diff --git a/level_3/2.py b/level_3/2.py index edde766..72b2dd4 100644 --- a/level_3/2.py +++ b/level_3/2.py @@ -1,8 +1,14 @@ from constants import ___ +from typing import List, TypedDict -def calculate_total_spent_for_user(user: ___) -> ___: - # попробуй тут воспользовать typing.TypedDict +class User(TypedDict): + name: str + age: int + transactions_sums: List[int] + + +def calculate_total_spent_for_user(user: User) -> int: pass diff --git a/level_3/3.py b/level_3/3.py index 50ed15a..e95e815 100644 --- a/level_3/3.py +++ b/level_3/3.py @@ -1,7 +1,8 @@ from constants import ___ +from typing import Callable -def create_user(user_name: ___, user_age: ___, after_created: ___) -> ___: +def create_user(user_name: str, user_age: int, after_created: Callable[[int], None]) -> None: pass From ef61f9dd0fd5c283c56a331b462bdcbdf46bd643 Mon Sep 17 00:00:00 2001 From: Ervand1989 Date: Fri, 11 Oct 2024 19:50:36 +0200 Subject: [PATCH 2/3] 'Resave' --- level_3/1.py | 4 ++-- level_3/2.py | 6 +++--- level_3/3.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/level_3/1.py b/level_3/1.py index 901573f..f9a234e 100644 --- a/level_3/1.py +++ b/level_3/1.py @@ -1,10 +1,10 @@ import decimal from constants import ___ -from typing import Mapping, Optional +from typing import Mapping -def get_transaction_amount(transaction_id: int, transactions_amounts_map: Mapping[int, decimal.Decimal]) -> Optional[decimal.Decimal]: +def get_transaction_amount(transaction_id: int, transactions_amounts_map: Mapping[int, decimal.Decimal]) -> decimal.Decimal | None: # попробуйте использовать typing.Mapping: transactions_amounts_map по смыслу не должен меняться внутри функции pass diff --git a/level_3/2.py b/level_3/2.py index 72b2dd4..ce3223f 100644 --- a/level_3/2.py +++ b/level_3/2.py @@ -1,14 +1,14 @@ from constants import ___ -from typing import List, TypedDict +from typing import TypedDict class User(TypedDict): name: str age: int - transactions_sums: List[int] + transactions_sums: list[int] -def calculate_total_spent_for_user(user: User) -> int: +def calculate_total_spent_for_user(user: User) -> int | None: pass diff --git a/level_3/3.py b/level_3/3.py index e95e815..f6300fa 100644 --- a/level_3/3.py +++ b/level_3/3.py @@ -2,7 +2,7 @@ from typing import Callable -def create_user(user_name: str, user_age: int, after_created: Callable[[int], None]) -> None: +def create_user(user_name: str, user_age: int, after_created: Callable[[int], str | None]) -> str | None: pass From 8d41376526b2683bbf374f66ae54b5f1394d602a Mon Sep 17 00:00:00 2001 From: Ervand1989 Date: Fri, 11 Oct 2024 19:51:39 +0200 Subject: [PATCH 3/3] 'Resave --- level_1/1.py | 2 +- level_1/10.py | 3 +-- level_1/2.py | 2 +- level_1/3.py | 2 +- level_1/4.py | 2 +- level_1/5.py | 2 +- level_1/6.py | 3 +-- level_1/7.py | 2 +- level_1/8.py | 2 +- level_1/9.py | 3 +-- level_2/1.py | 3 +-- level_2/10.py | 2 +- level_2/2.py | 3 +-- level_2/3.py | 3 +-- level_2/4.py | 3 +-- level_2/5.py | 2 +- level_2/6.py | 3 +-- level_2/7.py | 3 +-- level_2/8.py | 3 +-- level_2/9.py | 3 +-- 20 files changed, 20 insertions(+), 31 deletions(-) diff --git a/level_1/1.py b/level_1/1.py index 97ba86b..c79da05 100644 --- a/level_1/1.py +++ b/level_1/1.py @@ -1,7 +1,7 @@ from constants import ___ -def is_user_banned(user_id: int) -> bool: +def is_user_banned(user_id: int) -> bool | None: pass diff --git a/level_1/10.py b/level_1/10.py index 480f638..31f2845 100644 --- a/level_1/10.py +++ b/level_1/10.py @@ -1,8 +1,7 @@ from constants import ___ -from typing import Any -def stringify(value: Any) -> str: +def stringify(value: str | int | float | None) -> str | None: pass diff --git a/level_1/2.py b/level_1/2.py index 8558a13..6970708 100644 --- a/level_1/2.py +++ b/level_1/2.py @@ -1,7 +1,7 @@ from constants import ___ -def is_adult(age: int, country_name: str) -> bool: +def is_adult(age: int, country_name: str) -> bool | None: pass diff --git a/level_1/3.py b/level_1/3.py index c7792a6..911f607 100644 --- a/level_1/3.py +++ b/level_1/3.py @@ -1,7 +1,7 @@ from constants import ___ -def compose_full_name(first_name: str, last_name: str, middle_name: str) -> str: +def compose_full_name(first_name: str, last_name: str, middle_name: str | None) -> str | None: pass diff --git a/level_1/4.py b/level_1/4.py index b6c2041..84772d7 100644 --- a/level_1/4.py +++ b/level_1/4.py @@ -3,7 +3,7 @@ from constants import ___ -def calculate_age(date_of_birth: datetime) -> int: +def calculate_age(date_of_birth: datetime.date) -> int | None: pass diff --git a/level_1/5.py b/level_1/5.py index 9b06931..236a5a9 100644 --- a/level_1/5.py +++ b/level_1/5.py @@ -1,7 +1,7 @@ from constants import ___ -def is_correct_email(raw_email: str) -> bool: +def is_correct_email(raw_email: str) -> bool | None: pass diff --git a/level_1/6.py b/level_1/6.py index 15eb2b5..1ade048 100644 --- a/level_1/6.py +++ b/level_1/6.py @@ -1,8 +1,7 @@ from constants import ___ -from typing import Optional -def is_loan_amount_too_big(loan_amount_usd: Optional[int], max_loan_amount_for_user_usd: Optional[int]) -> bool: +def is_loan_amount_too_big(loan_amount_usd: int | None, max_loan_amount_for_user_usd: int | None) -> bool | None: pass diff --git a/level_1/7.py b/level_1/7.py index 0b57234..5ca7a80 100644 --- a/level_1/7.py +++ b/level_1/7.py @@ -1,7 +1,7 @@ from constants import ___ -def send_email(header: str, text_content: str, send_to: str) -> None: +def send_email(header: str, text_content: str, send_to: str) -> str | None: pass diff --git a/level_1/8.py b/level_1/8.py index f009c27..7ad874c 100644 --- a/level_1/8.py +++ b/level_1/8.py @@ -4,7 +4,7 @@ from constants import ___ -def get_user_balance(user_id: uuid.UUID) -> decimal.Decimal: +def get_user_balance(user_id: uuid.UUID) -> decimal.Decimal | None: pass diff --git a/level_1/9.py b/level_1/9.py index 17b426f..2adea3a 100644 --- a/level_1/9.py +++ b/level_1/9.py @@ -1,8 +1,7 @@ from constants import ___ -from typing import Optional -def is_correct_int(raw_int: Optional[str]) -> bool: +def is_correct_int(raw_int: str | None) -> bool | None: pass diff --git a/level_2/1.py b/level_2/1.py index 3e40c1c..e42e5f4 100644 --- a/level_2/1.py +++ b/level_2/1.py @@ -1,8 +1,7 @@ from constants import ___ -from typing import List -def get_avg_currency_rate(rates_history: List[float]) -> float: +def get_avg_currency_rate(rates_history: list[float]) -> float | None: pass diff --git a/level_2/10.py b/level_2/10.py index 6af8fc2..284c4ce 100644 --- a/level_2/10.py +++ b/level_2/10.py @@ -2,7 +2,7 @@ from typing import Tuple -def is_point_in_square(point: Tuple[int, int], left_upper_corner: Tuple[int, int], right_bottom_corner: Tuple[int, int]) -> bool: +def is_point_in_square(point: Tuple[int, int], left_upper_corner: Tuple[int, int], right_bottom_corner: Tuple[int, int]) -> bool | None: pass diff --git a/level_2/2.py b/level_2/2.py index 76a45fd..3977b97 100644 --- a/level_2/2.py +++ b/level_2/2.py @@ -1,8 +1,7 @@ from constants import ___ -from typing import List -def is_recovery_code_correct(code: str, user_codes: List[str]) -> bool: +def is_recovery_code_correct(code: str, user_codes: list[str]) -> bool | None: pass diff --git a/level_2/3.py b/level_2/3.py index 2087709..4b8efcd 100644 --- a/level_2/3.py +++ b/level_2/3.py @@ -1,10 +1,9 @@ import decimal -from typing import Dict, Optional from constants import ___ -def get_transaction_amount(transaction_id: int, transactions_amounts_map: Dict[int: decimal.Decimal]) -> Optional[str]: +def get_transaction_amount(transaction_id: int, transactions_amounts_map: dict[int, decimal.Decimal]) -> decimal.Decimal | None: pass diff --git a/level_2/4.py b/level_2/4.py index ff21865..2e927c8 100644 --- a/level_2/4.py +++ b/level_2/4.py @@ -1,8 +1,7 @@ from constants import ___ -from typing import Set -def ban_users(users_ids: Set[int]) -> int: +def ban_users(users_ids: set[int]) -> int | None: pass diff --git a/level_2/5.py b/level_2/5.py index b6b86f4..e8e6401 100644 --- a/level_2/5.py +++ b/level_2/5.py @@ -1,7 +1,7 @@ from constants import ___ -def get_current_user() -> tuple[str, int, str]: +def get_current_user() -> tuple[str, int, str] | None: pass diff --git a/level_2/6.py b/level_2/6.py index 386e011..d76e15c 100644 --- a/level_2/6.py +++ b/level_2/6.py @@ -1,8 +1,7 @@ from constants import ___ -from typing import Dict, Optional -def is_name_male(name: str, name_gender_map: Dict[str: bool]) -> Optional[bool]: +def is_name_male(name: str, name_gender_map: dict[str, bool]) -> bool | None: pass diff --git a/level_2/7.py b/level_2/7.py index 1140656..0cd9c28 100644 --- a/level_2/7.py +++ b/level_2/7.py @@ -1,8 +1,7 @@ from constants import ___ -from typing import Tuple, List -def calculate_total_spent_for_user(user: Tuple[str, int, List[int]]) -> int: +def calculate_total_spent_for_user(user: tuple[str, int, list[int]]) -> int | None: pass diff --git a/level_2/8.py b/level_2/8.py index 2ec2b29..d67e3b6 100644 --- a/level_2/8.py +++ b/level_2/8.py @@ -1,8 +1,7 @@ from constants import ___ -from typing import Set, Dict, Tuple, List -def calculate_total_spent_for_users(users_ids: Set[int], users_ids_to_users_map: Dict[int, Tuple[str, int, List[int]]]) -> int: +def calculate_total_spent_for_users(users_ids: set[int], users_ids_to_users_map: dict[int, tuple[str, int, list[int]]]) -> int | None: pass diff --git a/level_2/9.py b/level_2/9.py index 1fc1d18..f867d68 100644 --- a/level_2/9.py +++ b/level_2/9.py @@ -1,11 +1,10 @@ import datetime from constants import ___ -from typing import List, Set, Tuple from datetime import date -def parse_receipt(raw_receipt: str) -> Tuple[int, date, List[Tuple[str, int, float]]]: +def parse_receipt(raw_receipt: str) -> tuple[int, date, list[tuple[str, int, float]]] | None: pass