Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution #586

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Solution #586

wants to merge 4 commits into from

Conversation

CheshireKate
Copy link

No description provided.

app/main.py Outdated
Comment on lines 13 to 20
def __set__(self, instance: any, value: int) -> None:
if self.min_amount <= value <= self.max_amount:
setattr(instance, self.name, value)
else:
raise ValueError(
f"Value must be between "
f"{self.min_amount} and {self.max_amount}"
)
Copy link

Choose a reason for hiding this comment

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

Suggested change
def __set__(self, instance: any, value: int) -> None:
if self.min_amount <= value <= self.max_amount:
setattr(instance, self.name, value)
else:
raise ValueError(
f"Value must be between "
f"{self.min_amount} and {self.max_amount}"
)
def __set__(self, instance: any, value: int) -> None:
if not isinstance(value, int):
raise TypeError("Only integers are allowed")
if value not in range(self.min_amount, self.max_amount + 1):
raise ValueError(
f"Value must be between "
f"{self.min_amount} and {self.max_amount}"
)
setattr(instance, self.protected_name, value)

app/main.py Outdated
Comment on lines 49 to 54
def __init__(self) -> None:
super().__init__(
IntegerRange(4, 14),
IntegerRange(20, 51),
IntegerRange(80, 121)
)
Copy link

Choose a reason for hiding this comment

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

Suggested change
def __init__(self) -> None:
super().__init__(
IntegerRange(4, 14),
IntegerRange(20, 51),
IntegerRange(80, 121)
)
age = IntegerRange(4, 14)
weight = IntegerRange(20, 50)
height = IntegerRange(80, 120)

app/main.py Outdated
Comment on lines 58 to 62
def __init__(self) -> None:
super().__init__(IntegerRange(14, 61),
IntegerRange(50, 121),
IntegerRange(120, 221)
)
Copy link

Choose a reason for hiding this comment

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

Suggested change
def __init__(self) -> None:
super().__init__(IntegerRange(14, 61),
IntegerRange(50, 121),
IntegerRange(120, 221)
)
age = IntegerRange(14, 60)
weight = IntegerRange(50, 120)
height = IntegerRange(120, 220)

app/main.py Outdated
Comment on lines 71 to 79
return (
self.limitation_class.age_range.min_amount
<= visitor.age <= self.limitation_class.age_range.max_amount
and self.limitation_class.weight_range.min_amount
<= visitor.weight <= self.limitation_class.weight_range.max_amount
and self.limitation_class.height_range.min_amount
<= visitor.height
<= self.limitation_class.height_range.max_amount
)
Copy link

Choose a reason for hiding this comment

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

use try .. except here

app/main.py Outdated
Comment on lines 72 to 85
def can_access(self, visitor: Visitor) -> bool:
try:
return (
self.limitation_class.age_range.min_amount
<= visitor.age <= self.limitation_class.age_range.max_amount
and self.limitation_class.weight_range.min_amount
<= visitor.weight
<= self.limitation_class.weight_range.max_amount
and self.limitation_class.height_range.min_amount
<= visitor.height
<= self.limitation_class.height_range.max_amount
)
except Exception as e:
print(e)
Copy link

Choose a reason for hiding this comment

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

Suggested change
def can_access(self, visitor: Visitor) -> bool:
try:
return (
self.limitation_class.age_range.min_amount
<= visitor.age <= self.limitation_class.age_range.max_amount
and self.limitation_class.weight_range.min_amount
<= visitor.weight
<= self.limitation_class.weight_range.max_amount
and self.limitation_class.height_range.min_amount
<= visitor.height
<= self.limitation_class.height_range.max_amount
)
except Exception as e:
print(e)
def can_access(self, visitor: Visitor) -> bool:
try:
self.limitation_class(visitor.age, visitor.weight, visitor.height)
return True
except ValueError:
return False

app/main.py Outdated
Comment on lines 59 to 64
def __init__(self) -> None:
super().__init__(
age_range=IntegerRange(14, 60),
weight_range=IntegerRange(50, 120),
height_range=IntegerRange(120, 220)
)
Copy link

Choose a reason for hiding this comment

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

Suggested change
def __init__(self) -> None:
super().__init__(
age_range=IntegerRange(14, 60),
weight_range=IntegerRange(50, 120),
height_range=IntegerRange(120, 220)
)
age = IntegerRange(14, 60)
height = IntegerRange(120, 220)
weight = IntegerRange(50, 120)

app/main.py Outdated
Comment on lines 51 to 55
super().__init__(
age_range=IntegerRange(4, 14),
weight_range=IntegerRange(20, 50),
height_range=IntegerRange(80, 120)
)
Copy link

Choose a reason for hiding this comment

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

Suggested change
super().__init__(
age_range=IntegerRange(4, 14),
weight_range=IntegerRange(20, 50),
height_range=IntegerRange(80, 120)
)
age = IntegerRange(4, 14)
height = IntegerRange(80, 120)
weight = IntegerRange(20, 50)

app/main.py Outdated
f"Value must be between "
f"{self.min_amount} and {self.max_amount}"
)
instance.__dict__[self.name] = value
Copy link

Choose a reason for hiding this comment

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

please use setattr here

Copy link

@vsmutok vsmutok left a comment

Choose a reason for hiding this comment

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

Great!

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