Skip to content
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
env/
mypy_cache/
typing_challenges/
2 changes: 1 addition & 1 deletion constants.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
___ = None
none_type = ___
2 changes: 1 addition & 1 deletion level_1/1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from constants import ___


def is_user_banned(user_id: ___) -> ___:
def is_user_banned(user_id: int) -> bool:
pass


Expand Down
3 changes: 2 additions & 1 deletion level_1/10.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import uuid

from constants import ___
from typing import Any


def stringify(value: ___) -> ___:
def stringify(value: Any) -> str:
pass


Expand Down
2 changes: 1 addition & 1 deletion level_1/2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from constants import ___


def is_adult(age: ___, country_name: ___) -> ___:
def is_adult(age: int, country_name: str) -> bool:
pass


Expand Down
4 changes: 2 additions & 2 deletions level_1/3.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from constants import ___
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 | None) -> str:
pass


Expand Down
2 changes: 1 addition & 1 deletion level_1/4.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from constants import ___


def calculate_age(date_of_birth: ___) -> ___:
def calculate_age(date_of_birth: datetime.date) -> int:
pass


Expand Down
2 changes: 1 addition & 1 deletion level_1/5.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from constants import ___


def is_correct_email(raw_email: ___) -> ___:
def is_correct_email(raw_email: str) -> bool:
pass


Expand Down
2 changes: 1 addition & 1 deletion level_1/6.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from constants import ___


def is_loan_amount_too_big(loan_amount_usd: ___, max_loan_amount_for_user_usd: ___) -> ___:
def is_loan_amount_too_big(loan_amount_usd: int, max_loan_amount_for_user_usd: int | None) -> bool:
pass


Expand Down
2 changes: 1 addition & 1 deletion level_1/7.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from constants import ___


def send_email(header: ___, text_content: ___, send_to: ___) -> ___:
def send_email(header: str, text_content: str, send_to: str) -> None:
pass


Expand Down
4 changes: 2 additions & 2 deletions level_1/8.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import decimal
import uuid

from constants import ___
from constants import none_type


def get_user_balance(user_id: ___) -> ___:
def get_user_balance(user_id: uuid.UUID) -> decimal.Decimal | None:
pass


Expand Down
2 changes: 1 addition & 1 deletion level_1/9.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from constants import ___


def is_correct_int(raw_int: ___) -> ___:
def is_correct_int(raw_int: str | None) -> bool:
pass


Expand Down
2 changes: 1 addition & 1 deletion level_2/1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from constants import ___


def get_avg_currency_rate(rates_history: ___) -> ___:
def get_avg_currency_rate(rates_history: list[float]) -> float:
pass


Expand Down
3 changes: 2 additions & 1 deletion level_2/10.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from constants import ___


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


Expand Down
2 changes: 1 addition & 1 deletion level_2/2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from constants import ___


def is_recovery_code_correct(code: ___, user_codes: ___) -> ___:
def is_recovery_code_correct(code: str, user_codes: list[str]) -> bool:
pass


Expand Down
4 changes: 3 additions & 1 deletion level_2/3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
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]
) -> decimal.Decimal | None:
pass


Expand Down
2 changes: 1 addition & 1 deletion level_2/4.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from constants import ___


def ban_users(users_ids: ___) -> ___:
def ban_users(users_ids: set[int]) -> int:
pass


Expand Down
2 changes: 1 addition & 1 deletion level_2/5.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from constants import ___


def get_current_user() -> ___:
def get_current_user() -> tuple[str, int, str]:
pass


Expand Down
3 changes: 2 additions & 1 deletion level_2/6.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from constants import ___


def is_name_male(name: ___, name_gender_map: ___) -> ___:
def is_name_male(name: str, name_gender_map: dict[str, bool]) -> bool | None:
pass



if __name__ == "__main__":
name_gender_map = {
"John": True,
Expand Down
2 changes: 1 addition & 1 deletion level_2/7.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from constants import ___


def calculate_total_spent_for_user(user: ___) -> ___:
def calculate_total_spent_for_user(user: tuple[str, int, list[int]]) -> int:
pass


Expand Down
2 changes: 1 addition & 1 deletion level_2/8.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from constants import ___


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


Expand Down
9 changes: 5 additions & 4 deletions level_2/9.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import datetime

from constants import ___


def parse_receipt(raw_receipt: ___) -> ___:
# Вопрос: в тупле [("Молоко", 1, 32.2)]) последний элемент - 32.2,
# даже type(32.2) выдаёт float, поэтому ящитаю, что убирать его не надо. Добавляю опцию int,
# но чувствую подвох
def parse_receipt(raw_receipt: str) -> tuple[int, datetime.date, list[tuple[str, int, float | int]]]:
pass


if __name__ == "__main__":
assert parse_receipt(
raw_receipt="Кассовый чек 12 Продажа Позиции: ...",
Expand Down
3 changes: 2 additions & 1 deletion level_3/1.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import decimal

from constants import ___
from typing import Mapping


def get_transaction_amount(transaction_id: ___, transactions_amounts_map: ___) -> ___:
def get_transaction_amount(transaction_id: int, transactions_amounts_map: Mapping[int, decimal.Decimal]) -> decimal.Decimal | None:
# попробуйте использовать typing.Mapping: transactions_amounts_map по смыслу не должен меняться внутри функции
pass

Expand Down
16 changes: 15 additions & 1 deletion level_3/2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from constants import ___
from typing import TypedDict


def calculate_total_spent_for_user(user: ___) -> ___:
class User(TypedDict):
name: str
age: int
transactions_sums: list[int]


def calculate_total_spent_for_user(user: User) -> int:
# попробуй тут воспользовать typing.TypedDict
pass

Expand All @@ -14,3 +21,10 @@ def calculate_total_spent_for_user(user: ___) -> ___:
"transactions_sums": [102, 15, 63, 12],
},
) == 192

# Вопрос:
# допустимо ли в аннотации типов указывать TypeDict следующими способами?
#def calculate_total_spent_for_user(user: TypedDict('User', 'name' = str, 'age' = int, 'transactions_sums' = list[int])) -> int:
#def calculate_total_spent_for_user(user: TypedDict('User', {'name': str, 'age': int, 'transactions_sums': list[int]})) -> int:

# пока на основе документации понимаю, что оба варианта верны, и именно в таком виде, без квадратных скобок
8 changes: 5 additions & 3 deletions level_3/3.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from constants import ___
from types import FunctionType


def create_user(user_name: ___, user_age: ___, after_created: ___) -> ___:
# Полагаюсь на это:
# types.FunctionType The type of user-defined functions and functions created by lambda expressions.
def create_user(user_name: str, user_age: int, after_created: FunctionType) -> None:
pass


def send_test_email(user_id: int) -> None:
pass

Expand Down