Skip to content

Conversation

@PythonProjectDeveloper
Copy link

No description provided.

@PythonProjectDeveloper PythonProjectDeveloper changed the title [WIP] Tikhon Puntus Tikhon Puntus Apr 28, 2019
}


def exec_operation(x, y, operation=MULTIPLE):
Copy link
Collaborator

Choose a reason for hiding this comment

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

В сигнатуре функции можно добавлять аннотации вида:
def foo(param1: str, param2: int) -> None:
. . .
Чтобы явно указывать ожидаемый тип аргумента и вывода функции/метода

Имеет смысл поменять имена аргументов, чтобы их назначение было очевидно.

Choose a reason for hiding this comment

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

а если в функции может быть поднято исключение, куда его заносить? В документашку?

Choose a reason for hiding this comment

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

И нужно ли описывать параметры в документации, если мы используем аннотации?

ValueError: If `operation` is not found`.
"""
if operation == POWER and y[0] == MINUS:
a, b = float(y[1:]), float(x)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Имена переменных не несут смысловой нагрузки.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Такая же ситуация не только в этом месте в коде.


result = None
# arithmetic operation
if operation == MULTIPLE:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Избавиться от большого количества if-elif можно заведя словарь-маппинг вида:
functions_mapping = {'*' : mul,
'/' :truediv}
Тогда вместо большого количества проверок ты сможешь напрямую обращаться к нужному объекту-функции по ключу.

Choose a reason for hiding this comment

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

это я знаю, я ограничен был по времени. Если найду время перепишу большую часть кода и разобью на файлы.

]

pattern = re.compile(REGEXP_SIMPLE_DIGIT)
while True:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Зачем тут нужен while True?

Choose a reason for hiding this comment

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

Так как у нас могут быть вложенные запросы. Я не строю дерево.

match = re.search(REGEXP_NON_ZERO_FRACTION_PART, string)
num = num if match else int(num)

return bool(num) if HAS_COMPARE else num
Copy link
Collaborator

Choose a reason for hiding this comment

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

Функция не должна возвращать разные типы данных в зависимости от чего-либо.
Хорошие примеры возвраты из функций:

  • один определенный тип
  • один определенный тип либо None
  • один определенный тип либо None + вызов Exception внутри функции, если что-то пошло не так

Choose a reason for hiding this comment

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

накосячил признаю. Изменю как появится время

@PythonProjectDeveloper PythonProjectDeveloper changed the title Tikhon Puntus [WIP] Tikhon Puntus May 11, 2019
"""


class Library(dict):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Использование класса с родителем dict в этом случае выглядит слишком сложным способом решния нужной задачи. Можно обойтись обычной функцией, которая будет возвращаться нужный словарь.

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.

4 participants