Skip to content

3. Раджабов Руслан Ильгамович. 614 - #109

Open
somet1me123 wants to merge 14 commits into
python-department:mainfrom
somet1me123:3.-Раджабов-Руслан-Ильгамович.-614

Hidden character warning

The head ref may contain hidden characters: "3.-\u0420\u0430\u0434\u0436\u0430\u0431\u043e\u0432-\u0420\u0443\u0441\u043b\u0430\u043d-\u0418\u043b\u044c\u0433\u0430\u043c\u043e\u0432\u0438\u0447.-614"
Open

somet1me123 wants to merge 14 commits into
python-department:mainfrom
somet1me123:3.-Раджабов-Руслан-Ильгамович.-614

Conversation

@somet1me123

Copy link
Copy Markdown

No description provided.

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

for item in storage:
if new_name == item[NAME_INDEX]:
print(f"product name '{new_name}' is already taken")

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.

Можно кавычки к строковым литералам добавлять за счет форматирования f-строк:

Suggested change
print(f"product name '{new_name}' is already taken")
print(f"product name {new_name!r} is already taken")

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

f = False

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/crud.py
return None

f = False
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
if product_id == storage[i][PRODUCT_ID_INDEX]:
f = True
break
if f == False:

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.

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

Comment thread src/part3/crud.py
if product_id == storage[i][PRODUCT_ID_INDEX]:
f = True
break
if f == False:

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.

Это сравнение вообще не нужно. Вы могли в предыдущем цикле при выполнении условия if product_id == storage[i][PRODUCT_ID_INDEX]: напечатать нужное сообщение и выйти из функции с помощью return. return немедленно прерывает выполнение тела функции.

Или вы так маскируете факт списывания? :)

Comment thread src/part3/utils.py
# TODO: реализуйте функцию
return ""
mx_len_id = len(TABLE_HEADERS[0]) + 2
mx_len_name = len(TABLE_HEADERS[1]) + 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/utils.py
mx_len_price = len(TABLE_HEADERS[2]) + 2
mx_len_quantity = len(TABLE_HEADERS[3]) + 2
for item in storage:
mx_len_id = max(mx_len_id, len(str(item[PRODUCT_ID_INDEX])) + 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.

Очень много дублирующейся логики. Нарушение критерия S1. Минус балл

Comment thread src/part3/utils.py
mx_len_quantity = max(mx_len_quantity, len(str(item[QUANTITY_INDEX])) + 2)

s = (
f"| {TABLE_HEADERS[0]}{' ' * (mx_len_id - 3)}| {TABLE_HEADERS[1]}{' ' * (mx_len_name - 5)}| {TABLE_HEADERS[2]}{' ' * (mx_len_price - 6)}| {TABLE_HEADERS[3]}{' ' * (mx_len_quantity - 9)}|\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 не ругается, потому что с его точки зрения форматирование f-строк разбивать нельзя. Но честно говоря, так делать никогда не надо. Очень длинная строка - плохо. Вы заставляете читающего отвлекаться от основной части кода, сосредоточенной по правому краю экрана. А еще длинные строки не дают выводить на экран более одного листинга кода одновременно, т.к. длинные строки не умещаются на половине экрана, и постоянно приходится скролить.

В общем, пока что предупреждение, в будущем я за такое буду снижать. Разбивайте длинные строки на несколько физических строк.

Comment thread src/part3/utils.py
mx_len_quantity = max(mx_len_quantity, len(str(item[QUANTITY_INDEX])) + 2)

s = (
f"| {TABLE_HEADERS[0]}{' ' * (mx_len_id - 3)}| {TABLE_HEADERS[1]}{' ' * (mx_len_name - 5)}| {TABLE_HEADERS[2]}{' ' * (mx_len_price - 6)}| {TABLE_HEADERS[3]}{' ' * (mx_len_quantity - 9)}|\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.

А еще здесь форматирование пробелов и длины полей следовало бы реализовать через синтаксис форматирования f-строк

Comment thread src/part3/utils.py
return new_name


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