Skip to content

3. Шкрыль Роман Иванович. 614 - #106

Open
luvkis wants to merge 22 commits into
python-department:mainfrom
luvkis:third_assignment
Open

luvkis wants to merge 22 commits into
python-department:mainfrom
luvkis:third_assignment

Conversation

@luvkis

@luvkis luvkis commented Oct 8, 2026

Copy link
Copy Markdown

No description provided.

@github-actions github-actions Bot added the 614 label Oct 8, 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 len(storage) == 0:

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.

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

Comment thread src/part3/crud.py
print("product name must not be blank")
return None

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/run_admin.py
case ["show"]:
print(get_storage_str_representation(storage))
return True
case ["create", *command]:

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.

Вы могли бы проверять состав команды прямо тут, т.к. конструкция match-case как раз и нужна для сопоставления шаблонов:

Suggested change
case ["create", *command]:
case ["create", *name_parts, price, quantity]:

А так у вас получилось дублирование логики проверки числа слова. Это нарушение критерия S1. Минус балл

Comment thread src/part3/run_admin.py
if len(command) < 3:
print(f"'{line}' is not a command")
return True
quantity = int(command[-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.

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

Comment thread src/part3/run_admin.py
match line.split():
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/utils.py
max(len_headers[3], len_quantity),
]

s = (

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.

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

Comment thread src/part3/utils.py
)

for product in storage:
s += "\n"

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.

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

Comment thread src/part3/utils.py
]

s = (
f"| ID {' ' * (len_headers[0] - 2)}| name {' ' * (len_headers[1] - 4)}| price {' ' * (len_headers[2] - 5)}| quantity {' ' * (len_headers[3] - 8)}|\n"

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.

ruff не ругается, но фактически, это очень длинная строка. Такие строки сложно читать. Также из-за таких строк сложнее анализировать код в двух и более параллельно открытых вкладках. Длинные строки и строковые литералы старайтесь записывать на нескольких физических строках. Следить за тем, чтобы длина строки не превышала ограничений, принятых на проекте (в рамках нашего курса - это 88 символов)

Comment thread src/part3/utils.py
len_price = len(str(product[PRICE_INDEX]))
len_quantity = len(str(product[QUANTITY_INDEX]))

s += f"| {product[PRODUCT_ID_INDEX]} {' ' * (len_headers[0] - len_id)}| {product[NAME_INDEX]} {' ' * (len_headers[1] - len_name)}| {product[PRICE_INDEX]} {' ' * (len_headers[2] - len_price)}| {product[QUANTITY_INDEX]} {' ' * (len_headers[3] - len_quantity)}|"

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/utils.py
# TODO: при необходимости добавьте свои вспомогательные функции


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. Минус балл

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants