Repository navigation
3. Павлова Валери Юрьевна. 614 - #132
lerapavlova-1 wants to merge 6 commits into
Conversation
|
|
||
| def generate_product_id(storage: list[Product]) -> int: | ||
| """Choose the identifier for the next product added to ``storage``. | ||
| if not len(storage): |
There was a problem hiding this comment.
Неверная проверка на пустоту. Правильно так:
| if not len(storage): | |
| if not storage: |
Нарушение критерия T4. Минус 0.25 балла
| """ | ||
| # TODO: реализуйте функцию | ||
| return 0 | ||
| fields = (normalize_product_name(fields[0]), fields[1], fields[2]) |
There was a problem hiding this comment.
Использование магических констант для индексации полей продукта. Нарушение критерия S3. Минус балл.
| if not len(storage): | ||
| return PRODUCT_ID_MIN | ||
| mid = 0 | ||
| for i in range(len(storage)): |
There was a problem hiding this comment.
Нарушение критерия T5. Минус 0.25 балла
| return None | ||
|
|
||
| id = generate_product_id(storage) | ||
| cena = normalize_price(fields[1]) |
There was a problem hiding this comment.
Не используйте транслитерацию для именования переменных
| match command: | ||
| case ["help"]: | ||
| show_help() | ||
| return True |
There was a problem hiding this comment.
Можно было не писать return True в каждом кейсе. Достаточно оставить return False только для команды exit, а return True переместить в конец функции. В Python выполнение кейсов осуществляется без проваливания в соседние кейсы, в отличие от C/C++, так что это работало бы корректно.
| print(get_storage_str_representation(storage)) | ||
| return True | ||
|
|
||
| case ["create", *rest] if len(rest) >= 3: |
There was a problem hiding this comment.
Можно было записать шаблон так:
| case ["create", *rest] if len(rest) >= 3: | |
| case ["create", *name_parts, price_str, quantity_str]: |
| print_result(read_product(storage, prod_id)) | ||
| return True | ||
|
|
||
| case ["update", prod_id_str, *rest] if len(rest) >= 3: |
There was a problem hiding this comment.
Можно было записать шаблон так:
| case ["update", prod_id_str, *rest] if len(rest) >= 3: | |
| case ["update", prod_id_str, *name_parts, price_str, quantity_str]: |
| return " ".join(list_name2) | ||
|
|
||
|
|
||
| def get_storage_str_representation(storage: list[Product]) -> str: |
There was a problem hiding this comment.
Функция нарушает принцип единой ответственности, т.к. в ней происходит и вычисление длины полей, и форматирование строки.
Нарушение критерия S2. минус балл
| width = max(width, len(row[column])) | ||
| widths.append(width) | ||
|
|
||
| def format_row(cells: list[str] | tuple[str, ...]) -> str: |
There was a problem hiding this comment.
Старайтесь не писать вложенные функции без крайней необходимости. Часто наличие вложенной функции указывает на проблему архитектуры
No description provided.