-
Notifications
You must be signed in to change notification settings - Fork 63
Edit3 #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Edit3 #20
Changes from all commits
b4ab387
b461c94
a7cb339
338df8a
3f7db4a
56a9315
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| env/ | ||
| mypy_cache/ | ||
| typing_challenges/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| ___ = None | ||
| none_type = ___ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| 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 | ||
|
|
||
|
|
||
| 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" | ||
| 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]) -> bool: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right_bottom_corner тоже из двух элементов состоит :) |
||
| pass | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| import decimal | ||
|
|
||
| from constants import ___ | ||
| 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]) -> dict[int, decimal.decimal] | None: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| pass | ||
|
|
||
|
|
||
|
|
||
| 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 | ||
|
|
||
|
|
||
|
|
||
| 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 | ||
|
|
||
|
|
||
|
|
||
| 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: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Возвращаемый тип не совсем точный |
||
| pass | ||
|
|
||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| name_gender_map = { | ||
| "John": True, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,11 @@ | ||
| import datetime | ||
|
|
||
| from constants import ___ | ||
|
|
||
|
|
||
| def parse_receipt(raw_receipt: ___) -> ___: | ||
| def parse_receipt(raw_receipt: str) -> tuple[int, datetime.date, list[tuple[str, int, float]]]: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. В тупле в последнем элементе не флоат |
||
| pass | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| assert parse_receipt( | ||
| raw_receipt="Кассовый чек 12 Продажа Позиции: ...", | ||
|
|
||
| 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] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут кавычки лишние, правильно как в датаклассах. |
||
|
|
||
|
|
||
| def calculate_total_spent_for_user(user: User) -> int: | ||
| # попробуй тут воспользовать typing.TypedDict | ||
| pass | ||
|
|
||
|
|
@@ -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: | ||
|
|
||
| # пока на основе документации понимаю, что оба варианта верны, и именно в таком виде, без квадратных скобок | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Синтаксически это может и верно, но в реальной жизни если и приходится использвоать тайпеддикт (редко), то пригождается тот способ, которым ты воспользовалась: ты отдельно определяешь тайпдикт как класс, а потом указываешь его в аннотации. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,11 @@ | ||
| from constants import ___ | ||
|
|
||
|
|
||
| def create_user(user_name: ___, user_age: ___, after_created: ___) -> ___: | ||
| pass | ||
|
|
||
| def create_user(user_name: str, user_age: int, after_created: function) -> None: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут пока неправильно. Посмотри, какие типы есть в модуле typing, может найдёшь чего :) |
||
| pass | ||
|
|
||
|
|
||
| def send_test_email(user_id: int) -> None: | ||
| pass | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не, когда у функции указываешь именованые аргументы, пробелы вокруг равно не нужны. Они нужны когда равно – это присваивание значения переменной.