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 #616

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 52 additions & 6 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,70 @@


class IntegerRange:

Choose a reason for hiding this comment

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

It is a good practice to provide a docstring for the class to explain its purpose and how it should be used.

pass
"""Descriptor data validation"""

def __init__(self, min_amount: int, max_amount: int) -> None:
self.min_amount = min_amount
self.max_amount = max_amount

def __set_name__(self, owner: object, name: str) -> None:
self.name = name
self.protected_name = f"_{name}"

def __get__(self, instance: object, owner: object) -> int:
return getattr(instance, self.protected_name)

def __set__(self, instance: object, value: int) -> None:
if not isinstance(value, int):
raise TypeError(f"{self.protected_name} must be an integer")
if not self.min_amount <= value <= self.max_amount:
raise ValueError(f"{value} must be in range:" # noqa
f" {self.min_amount} - {self.max_amount}")
setattr(instance, self.protected_name, value)


class Visitor:

Choose a reason for hiding this comment

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

The 'Visitor' class could use a docstring to explain its purpose and usage.

pass
def __init__(self,
name: str,
age: int,
weight: int,
height: int) -> None:
self.name = name
self.age = age
self.weight = weight
self.height = height
Comment on lines 27 to +36

Choose a reason for hiding this comment

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

This is a design issue. The Visitor class has no restrictions on the values of age, weight, and height. However, in your SlideLimitationValidator subclasses, you are imposing restrictions on these attributes. This could lead to inconsistencies or errors. You might want to consider using your IntegerRange descriptor in the Visitor class to ensure that the values of age, weight, and height are always within acceptable ranges.



class SlideLimitationValidator(ABC):

Choose a reason for hiding this comment

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

The 'SlideLimitationValidator' class could use a docstring to explain its purpose and usage.

Choose a reason for hiding this comment

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

The SlideLimitationValidator class is declared as an abstract base class (ABC) but it doesn't have any abstract methods. If you intend to use it as an interface, you should define some abstract methods.

pass
def __init__(self,
age: int,
weight: int,
height: int) -> None:

Choose a reason for hiding this comment

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

The SlideLimitationValidator class and its subclasses are not using the IntegerRange descriptor for age, weight, and height attributes. You should use them in these classes.

self.age = age
self.weight = weight
self.height = height


class ChildrenSlideLimitationValidator(SlideLimitationValidator):

Choose a reason for hiding this comment

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

The 'ChildrenSlideLimitationValidator' class could use a docstring to explain its purpose and usage.

pass
age = IntegerRange(4, 14)
height = IntegerRange(80, 120)
weight = IntegerRange(20, 50)


class AdultSlideLimitationValidator(SlideLimitationValidator):

Choose a reason for hiding this comment

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

The 'AdultSlideLimitationValidator' class could use a docstring to explain its purpose and usage.

pass
age = IntegerRange(14, 60)
height = IntegerRange(120, 220)
weight = IntegerRange(50, 120)


class Slide:

Choose a reason for hiding this comment

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

The 'Slide' class could use a docstring to explain its purpose and usage.

pass
def __init__(self, name: str, limitation_class: type) -> None:
self.name = name
self.limitation_class = limitation_class

def can_access(self, visitor: Visitor) -> bool:
try:
self.limitation_class(visitor.age, visitor.weight, visitor.height)

Choose a reason for hiding this comment

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

This line seems to be creating a new instance of a limitation class but does nothing with it. This is likely a bug, as it doesn't validate anything. You probably wanted to create an instance and then call a method on it to validate the visitor's parameters.

Choose a reason for hiding this comment

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

The limitation_class is being instantiated with visitor's age, weight, and height. However, the SlideLimitationValidator class and its subclasses don't have a logic to check these values in the constructor. You should move the logic from IntegerRange's set method to init method or add a new method to check these values.

except (ValueError, TypeError):
return False
return True
Loading