-
Notifications
You must be signed in to change notification settings - Fork 32
Sourcery refactored main branch #18
base: main
Are you sure you want to change the base?
Conversation
if self.catalog.get(name): | ||
return self.catalog.get(name) | ||
return name | ||
return self.catalog.get(name) or name |
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.
Function BringData.convert_name
refactored with the following changes:
- Simplify if expression by using or (
or-if-exp-identity
) - Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
specification = name[name.index(" [") + 2 : len(name) - 1] | ||
name = name[0 : name.index(" [")] | ||
specification = name[name.index(" [") + 2:-1] | ||
name = name[:name.index(" [")] |
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.
Function ShoppingData.ha_to_shopping_item
refactored with the following changes:
- Simplify accessing last index of list (
simplify-negative-index
) - Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index
)
specification = name[name.index(" [") + 2 : len(name) - 1] | ||
name = name[0 : name.index(" [")] | ||
specification = name[name.index(" [") + 2:-1] | ||
name = name[:name.index(" [")] |
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.
Function ShoppingData.async_add
refactored with the following changes:
- Simplify accessing last index of list (
simplify-negative-index
) - Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index
)
specification = name[name.index(" [") + 2 : len(name) - 1] | ||
name = name[0 : name.index(" [")] | ||
specification = name[name.index(" [") + 2:-1] | ||
name = name[:name.index(" [")] |
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.
Function ShoppingData.async_update
refactored with the following changes:
- Simplify accessing last index of list (
simplify-negative-index
) - Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index
)
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.
Function BringApi.__init__
refactored with the following changes:
- Simplify if expression by using or (
or-if-exp-identity
)
message = None | ||
if result.get("errorCode"): | ||
message = result.get("error") | ||
|
||
raise Exception(message if message else result) | ||
message = result.get("error") if result.get("errorCode") else None | ||
raise Exception(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.
Function BringApi.check_response
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Move setting of default value for variable into
else
branch (introduce-default-else
) - Simplify if expression by using or (
or-if-exp-identity
)
for val, key in self.load_translations(locale).items(): | ||
if key == item: | ||
return val | ||
return item | ||
return next( | ||
( | ||
val | ||
for val, key in self.load_translations(locale).items() | ||
if key == item | ||
), | ||
item, | ||
) |
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.
Function BringApi.translate_to_ch
refactored with the following changes:
- Use the built-in function
next
instead of a for-loop (use-next
)
"These are the top {} items on your shopping list: {}".format( | ||
min(len(items), 5), | ||
", ".join(itm["name"] for itm in reversed(items)), | ||
) | ||
f'These are the top {min(len(items), 5)} items on your shopping list: {", ".join((itm["name"] for itm in reversed(items)))}' | ||
) | ||
|
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.
Function ListTopItemsIntent.async_handle
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
Branch
main
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
main
branch, then run:Help us improve this pull request!