Skip to content

3. Павлова Валери Юрьевна. 614 - #132

Open
lerapavlova-1 wants to merge 6 commits into
python-department:mainfrom
lerapavlova-1:task-3
Open

lerapavlova-1 wants to merge 6 commits into
python-department:mainfrom
lerapavlova-1:task-3

Conversation

@lerapavlova-1

Copy link
Copy Markdown

No description provided.

@github-actions github-actions Bot added the 614 label Oct 12, 2026
Comment thread src/part3/crud.py

def generate_product_id(storage: list[Product]) -> int:
"""Choose the identifier for the next product added to ``storage``.
if not len(storage):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Неверная проверка на пустоту. Правильно так:

Suggested change
if not len(storage):
if not storage:

Нарушение критерия T4. Минус 0.25 балла

Comment thread src/part3/crud.py
"""
# TODO: реализуйте функцию
return 0
fields = (normalize_product_name(fields[0]), fields[1], fields[2])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Использование магических констант для индексации полей продукта. Нарушение критерия S3. Минус балл.

Comment thread src/part3/crud.py
if not len(storage):
return PRODUCT_ID_MIN
mid = 0
for i in range(len(storage)):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нарушение критерия T5. Минус 0.25 балла

Comment thread src/part3/crud.py
return None

id = generate_product_id(storage)
cena = normalize_price(fields[1])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не используйте транслитерацию для именования переменных

Comment thread src/part3/run_admin.py
match command:
case ["help"]:
show_help()
return True

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно было не писать return True в каждом кейсе. Достаточно оставить return False только для команды exit, а return True переместить в конец функции. В Python выполнение кейсов осуществляется без проваливания в соседние кейсы, в отличие от C/C++, так что это работало бы корректно.

Comment thread src/part3/run_admin.py
print(get_storage_str_representation(storage))
return True

case ["create", *rest] if len(rest) >= 3:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно было записать шаблон так:

Suggested change
case ["create", *rest] if len(rest) >= 3:
case ["create", *name_parts, price_str, quantity_str]:

Comment thread src/part3/run_admin.py
print_result(read_product(storage, prod_id))
return True

case ["update", prod_id_str, *rest] if len(rest) >= 3:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно было записать шаблон так:

Suggested change
case ["update", prod_id_str, *rest] if len(rest) >= 3:
case ["update", prod_id_str, *name_parts, price_str, quantity_str]:

Comment thread src/part3/utils.py
return " ".join(list_name2)


def get_storage_str_representation(storage: list[Product]) -> str:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Функция нарушает принцип единой ответственности, т.к. в ней происходит и вычисление длины полей, и форматирование строки.

Нарушение критерия S2. минус балл

Comment thread src/part3/utils.py
width = max(width, len(row[column]))
widths.append(width)

def format_row(cells: list[str] | tuple[str, ...]) -> str:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Старайтесь не писать вложенные функции без крайней необходимости. Часто наличие вложенной функции указывает на проблему архитектуры

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants