Skip to content

Hw2#17

Open
N0ktis wants to merge 6 commits into
kib-courses:masterfrom
N0ktis:hw2
Open

Hw2#17
N0ktis wants to merge 6 commits into
kib-courses:masterfrom
N0ktis:hw2

Conversation

@N0ktis
Copy link
Copy Markdown

@N0ktis N0ktis commented Apr 28, 2020

No description provided.

Copy link
Copy Markdown
Collaborator

@romvano romvano left a comment

Choose a reason for hiding this comment

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

Я оставил кучу комментариев насчет TypeError, но потом увидел, где это обрабатывается. Основные замечания - перенести обработку этой ошибки к остальным, чтобы сразу таких вопросов не возникало, а еще переписать дескриптор через проперти, ибо он почти полностью повторяет логику проперти.

Comment thread homework/patient.py

@logger_decorator_maker()
def name_check(name):
if not name.isalpha():
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

если name не str, то залогируется AttributeError, а не TypeError

Comment thread homework/patient.py
raise ValueError("Incorrect date length")
born = born[:4] + '-' + born[5:7] + '-' + born[8:]
for k, i in enumerate(born):
if i.isdigit() and (0 <= k <= 3 or k == 5 or k == 6 or k == 8 or k == 9):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

лучше регуляркой, чтобы было понятней

Comment thread homework/patient.py

@logger_decorator_maker()
def birth_check(born):
if len(born) != 10:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

тут тоже может вылезти AttributeError

Comment thread homework/patient.py
continue
else:
raise ValueError("Date contains invalid characters")
if str(datetime.date.today()) >= born: #колхозное сравнение)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

воистину

Comment thread homework/patient.py

@logger_decorator_maker()
def phone_check(phone):
phone = phone.replace('+', '')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

то же самое с AttributeError

Comment thread homework/patient.py

@logger_decorator_maker()
def __set__(self, obj, val):
if not isinstance(val,str):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ага, всё-таки есть проверка на str. Лучше ее переместить ко всем остальным проверкам, чтобы логика была более консистентной

Comment thread homework/patient.py
self.name = name

def __get__(self, obj, objtype):
return self.data_get(obj, self.name)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

по умолчанию self.data_get == None, и любая попытка достучаться до дескриптора будет валиться с ошибкой о том, что data_get not callable. Это точно то поведение, которое планируется по умолчанию?

Comment thread homework/patient.py
def __init__(self, *args, **kwargs):
pass
def get_field(self, key):
if key == 'first_name':
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

более универсально return getattr(self, "_" + key)

Comment thread homework/patient.py
def create(*args, **kwargs):
raise NotImplementedError()
first_name = DataAccess('first_name', get_field, set_field, del_field, name_check)
last_name = DataAccess('last_name', get_field, set_field, del_field, name_check)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

get_field, set_field, del_field - везде одинаковые. Нужно ли их передавать в параметрах?
Я бы сделал отдельный сеттер для first_name и last_name, чтобы в этом был смысл. Как раз и количество кода в сеттере уменьшится

Comment thread homework/patient.py
def __iter__(self):
try:
for i in range(0, len(pnd.read_csv(self.path, sep='|', header=None, dtype=str).index)):
yield Patient(*pnd.read_csv(self.path, sep='|', header=None, dtype=str).iloc[i])
Copy link
Copy Markdown
Collaborator

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants