-
Notifications
You must be signed in to change notification settings - Fork 29
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
Apply Sourcery suggested refactoring. #448
base: main
Are you sure you want to change the base?
Conversation
@@ -48,6 +48,7 @@ | |||
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
@@ -119,7 +120,7 @@ def __init__( | |||
self.gateways: list[Gateway] = [] | |||
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
@@ -186,7 +187,7 @@ async def somfy_tahoma_get_access_token(self) -> str: | |||
""" | |||
# 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
@@ -230,7 +231,7 @@ async def refresh_token(self) -> None: | |||
# &grant_type=refresh_token&refresh_token=REFRESH_TOKEN | |||
# 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
@@ -764,7 +752,7 @@ async def check_response(response: ClientResponse) -> None: | |||
result = await response.text() | |||
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.
@@ -823,7 +811,7 @@ async def check_response(response: ClientResponse) -> None: | |||
if "Not such token with UUID: " in message: | |||
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
@@ -79,3 +79,7 @@ class SomfyBadCredentialsException(BadCredentialsException): | |||
|
|||
class SomfyServiceException(Exception): | |||
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.
@@ -19,7 +19,7 @@ def obfuscate_email(email: str | None) -> str: | |||
|
|||
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
@@ -298,7 +299,7 @@ async def cozytouch_login(self) -> str: | |||
|
|||
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!