-
Notifications
You must be signed in to change notification settings - Fork 620
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
base: master
Are you sure you want to change the base?
Solution #282
Conversation
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) |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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
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 " |
No description provided.