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

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

Solution #282

wants to merge 5 commits into from

Conversation

AndriiYe
Copy link

No description provided.

app/main.py Outdated

def __set__(self, instance: Callable, value: int) -> None:
if value in range(self.min_value, self.max_value + 1):
setattr(instance, self.protected_name, True)

Choose a reason for hiding this comment

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

you need to set the value to the attribute, not True or False

app/main.py Outdated
def __set__(self, instance: Callable, value: int) -> None:
if value in range(self.min_value, self.max_value + 1):
setattr(instance, self.protected_name, True)
else:

Choose a reason for hiding this comment

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

Maybe you can consider a different approach to solve this task. You can raise ValueError in case if the value is not valid, and in the def can_access method you can catch the error using try/except blocks.

@AndriiYe
Copy link
Author

is it ok?

app/main.py Outdated

def __set__(self, instance: Callable, value: int) -> None:
if value not in range(self.min_value, self.max_value + 1):
raise ValueError

Choose a reason for hiding this comment

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

When raising a ValueError, provide a meaningful and descriptive error message.

app/main.py Outdated
def __set_name__(self, owner: SlideLimitationValidator, name: str) -> None:
self.protected_name = "_" + name

def __get__(self, instance: Callable, objtype: None = None) -> bool:

Choose a reason for hiding this comment

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

invalid typehint

app/main.py Outdated


class Slide:
pass
def __init__(self, name: str, limitation_class: Callable) -> None:

Choose a reason for hiding this comment

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

specify the limitation_class typehint

@AndriiYe
Copy link
Author

there is some issue with the type annotation in the "can_access" method flake8 says that everything is ok but IDE underlines it as: "'SlideLimitationValidator' object is not callable "

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.

4 participants