-
Notifications
You must be signed in to change notification settings - Fork 34
Apply Sourcery suggested refactoring. #448
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
base: main
Are you sure you want to change the base?
Conversation
TooManyConcurrentRequestsException, | ||
TooManyExecutionsException, | ||
TooManyRequestsException, | ||
UnknownException, |
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.
Sourcery - Raise specific exception instead of genericException
self._states = [State(**state) for state in states] | ||
else: | ||
self._states = [] | ||
self._states = [State(**state) for state in states] if states 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.
Sourcery - Replace if statement with if expression
self.event_listener_id: str | None = None | ||
|
||
self.session = session if session else ClientSession() | ||
self.session = session or ClientSession() |
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.
Sourcery - Simplify if expression by using or
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.
Indeed
# Request access token | ||
async with self.session.post( | ||
SOMFY_API + "/oauth/oauth/v2/token", | ||
f"{SOMFY_API}/oauth/oauth/v2/token", |
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.
Sourcery - Use f-string instead of string concatenation
# Request access token | ||
async with self.session.post( | ||
SOMFY_API + "/oauth/oauth/v2/token", | ||
f"{SOMFY_API}/oauth/oauth/v2/token", |
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.
Sourcery - Use f-string instead of string concatenation
if "Server is down for maintenance" in result: | ||
raise MaintenanceException("Server is down for maintenance") from error | ||
raise Exception( | ||
raise UnknownException( |
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.
Sourcery - Raise a specific error instead of the general Exception.
raise NotSuchTokenException(message) | ||
|
||
raise Exception(message if message else result) | ||
raise UnknownException(message or result) |
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.
Sourcery - Raise a specific error instead of the general Exception.
Sourcery - Simplify if expression by using or
pass | ||
|
||
|
||
class UnknownException(Exception): |
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.
Sourcery - Raise a specific error instead of the general Exception.
def obfuscate_string(input: str) -> str: | ||
"""Mask string""" | ||
return re.sub(r"[a-zA-Z0-9_.-]*", "*", str(input)) | ||
return re.sub(r"[a-zA-Z0-9_.-]*", "*", input) |
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.
Sourcery - Remove unnecessary casts to int, str, float or bool
jwt = jwt.strip('"') # Remove surrounding quotes | ||
|
||
return jwt | ||
return str(jwt) |
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.
mypy: pyoverkiz/client.py:302: error: Returning Any from function declared to return "str" [no-any-return]
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.
We should cast it if we know it is a string for sure.
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.
Nice! Let's see if we can implement a few of these changes / fixes :).
Not sure you want to appy that, so I'll make it a draft for now. But I think it's relevant!