-
Notifications
You must be signed in to change notification settings - Fork 4
Sourcery refactored master branch #1
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: master
Are you sure you want to change the base?
Conversation
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 timed out performing refactorings.
Due to GitHub API limits, only the first 60 comments can be shown.
bin/hummingbot_quickstart.py
Outdated
| if hb.strategy_name and hb.strategy_file_name: | ||
| if not all_configs_complete(hb.strategy_name): | ||
| hb.status() | ||
| if ( | ||
| hb.strategy_name | ||
| and hb.strategy_file_name | ||
| and not all_configs_complete(hb.strategy_name) | ||
| ): | ||
| hb.status() |
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 quick_start refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs)
| if args.config_password is None: | ||
| if not login_prompt(): | ||
| return | ||
| if args.config_password is None and not login_prompt(): | ||
| 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.
Function main refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs)
| import sys | ||
| if "hummingbot-dist" in __file__: | ||
| # Dist environment. | ||
| import os | ||
| import sys |
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.
Lines 6-15 refactored with the following changes:
- Hoist repeated code outside conditional statement (
hoist-statement-from-if)
| if isinstance(n, decimal.Decimal): | ||
| n = round(n, FLOAT_PRINTOUT_PRECISION) | ||
| return format(n.normalize(), 'f') | ||
| else: | ||
| if not isinstance(n, decimal.Decimal): | ||
| return str(n) | ||
| n = round(n, FLOAT_PRINTOUT_PRECISION) | ||
| return format(n.normalize(), 'f') |
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 format_decimal refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| if self.placeholder_mode: | ||
| pass | ||
| else: | ||
| if not self.placeholder_mode: |
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 HummingbotApplication._handle_command refactored with the following changes:
- Swap if/else to remove empty if body (
remove-pass-body) - Simplify boolean if expression (
boolean-if-exp-identity) - Simplify comparison to boolean (
simplify-boolean-comparison)
This removes the following comments ( why? ):
# regular command
| for token, bal in bals.items(): | ||
| rows.append({"Asset": token, "Amount": round(bal, 4)}) | ||
| rows.extend( | ||
| {"Asset": token, "Amount": round(bal, 4)} | ||
| for token, bal in bals.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 BalanceCommand.ethereum_balances_df refactored with the following changes:
- Replace a for append loop with list extend (
for-append-to-extend)
| rows = [] | ||
| bals = await UserBalances.xdai_balances() | ||
| for token, bal in bals.items(): | ||
| rows.append({"Asset": token, "Amount": round(bal, 4)}) | ||
| rows = [ | ||
| {"Asset": token, "Amount": round(bal, 4)} | ||
| for token, bal in bals.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 BalanceCommand.xdai_balances_df refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block) - Convert for loop into list comprehension (
list-comprehension)
| rows = [] | ||
| for token, amount in asset_limit_conf.items(): | ||
| rows.append({"Asset": token, "Limit": round(Decimal(amount), 4)}) | ||
| rows = [ | ||
| {"Asset": token, "Limit": round(Decimal(amount), 4)} | ||
| for token, amount in asset_limit_conf.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 BalanceCommand.asset_limits_df refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension)
| lines = [" " + line for line in df.to_string(index=False).split("\n")] | ||
| lines = [f" {line}" for line in df.to_string(index=False).split("\n")] |
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 BalanceCommand.show_asset_limits refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| rows = [] | ||
| for asset, balance in paper_balances.items(): | ||
| rows.append({"Asset": asset, "Balance": round(Decimal(str(balance)), 4)}) | ||
| rows = [ | ||
| {"Asset": asset, "Balance": round(Decimal(str(balance)), 4)} | ||
| for asset, balance in paper_balances.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 BalanceCommand.paper_acccount_balance_df refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension)
| lines = [" " + line for line in df.to_string(index=False).split("\n")] | ||
| lines = [f" {line}" for line in df.to_string(index=False).split("\n")] |
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 BalanceCommand.show_paper_account_balance refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| lines = [" " + line for line in df.to_string(index=False, max_colwidth=50).split("\n")] | ||
| lines = [ | ||
| f" {line}" | ||
| for line in df.to_string(index=False, max_colwidth=50).split("\n") | ||
| ] | ||
|
|
||
| self._notify("\n".join(lines)) | ||
|
|
||
| data = [[cv.key, cv.value] for cv in global_config_map.values() | ||
| if cv.key in color_settings_to_display and not cv.is_secure] | ||
| df = map_df_to_str(pd.DataFrame(data=data, columns=columns)) | ||
| self._notify("\nColor Settings:") | ||
| lines = [" " + line for line in df.to_string(index=False, max_colwidth=50).split("\n")] | ||
| lines = [ | ||
| f" {line}" | ||
| for line in df.to_string(index=False, max_colwidth=50).split("\n") | ||
| ] | ||
|
|
||
| self._notify("\n".join(lines)) | ||
|
|
||
| if self.strategy_name is not None: | ||
| data = [[cv.printable_key or cv.key, cv.value] for cv in self.strategy_config_map.values() if not cv.is_secure] | ||
| df = map_df_to_str(pd.DataFrame(data=data, columns=columns)) | ||
| self._notify("\nStrategy Configurations:") | ||
| lines = [" " + line for line in df.to_string(index=False, max_colwidth=50).split("\n")] | ||
| lines = [ | ||
| f" {line}" | ||
| for line in df.to_string(index=False, max_colwidth=50).split("\n") | ||
| ] | ||
|
|
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 ConfigCommand.list_configs refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| if password != Security.password: | ||
| self._notify("Invalid password, please try again.") | ||
| return False | ||
| else: | ||
| if password == Security.password: | ||
| return True | ||
| self._notify("Invalid password, please try again.") | ||
| return False |
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 ConfigCommand.check_password refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| if isinstance(self.strategy, PureMarketMakingStrategy) or \ | ||
| isinstance(self.strategy, PerpetualMarketMakingStrategy): | ||
| if isinstance( | ||
| self.strategy, | ||
| (PureMarketMakingStrategy, PerpetualMarketMakingStrategy), | ||
| ): |
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 ConfigCommand._config_single_key refactored with the following changes:
- Merge isinstance calls (
merge-isinstance)
| api_key_config = [c for c in exchange_configs if "api_key" in c.key] | ||
| if api_key_config: | ||
| if api_key_config := [ | ||
| c for c in exchange_configs if "api_key" in c.key | ||
| ]: |
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 ConnectCommand.connect_exchange refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| lines = [] | ||
| base, quote = trading_pair.split("-") | ||
| lines.extend( | ||
| [f"\n{market} / {trading_pair}"] | ||
| ) | ||
|
|
||
| lines = list([f"\n{market} / {trading_pair}"]) |
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 HistoryCommand.report_performance_by_market refactored with the following changes:
- Merge extend into list declaration (
merge-list-extend) - Move assignment closer to its usage within a block (
move-assign-in-block) - Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| queried_trades = queried_trades + celo_trades | ||
| queried_trades += celo_trades |
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 HistoryCommand.list_trades refactored with the following changes:
- Replace assignment with augmented assignment (
aug-assign) - Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| example = f"{CONF_PREFIX}{short_strategy_name('pure_market_making')}_{1}.yml" | ||
| example = f'{CONF_PREFIX}{short_strategy_name("pure_market_making")}_1.yml' | ||
| file_name = await self.app.prompt(prompt=f'Enter path to your strategy file (e.g. "{example}") >>> ') | ||
| if self.app.to_stop_config: | ||
| return | ||
| file_path = os.path.join(CONF_FILE_PATH, file_name) | ||
| err_msg = validate_strategy_file(file_path) | ||
| if err_msg is not None: | ||
| self._notify(f"Error: {err_msg}") | ||
| return await self.prompt_a_file_name() | ||
| else: | ||
| if err_msg is None: | ||
| return file_name | ||
| self._notify(f"Error: {err_msg}") | ||
| return await self.prompt_a_file_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 ImportCommand.prompt_a_file_name refactored with the following changes:
- Simplify unnecessary nesting, casting and constant values in f-strings (
simplify-fstring-formatting) - Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| text_lines = [" " + line for line in joined_df.to_string(index=False).split("\n")] | ||
| text_lines = [ | ||
| f" {line}" for line in joined_df.to_string(index=False).split("\n") | ||
| ] | ||
|
|
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 OrderBookCommand.show_order_book.get_order_book refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| for _ in range(0, 3): | ||
| for _ in range(3): | ||
| await self.cls_display_delay(self.display_alert()) | ||
| hb_with_flower_1 = open(f"{RESOURCES_PATH}hb_with_flower_1.txt").readlines() | ||
| hb_with_flower_2 = open(f"{RESOURCES_PATH}hb_with_flower_2.txt").readlines() | ||
| hb_with_flower_up_close_1 = open(f"{RESOURCES_PATH}hb_with_flower_up_close_1.txt").readlines() | ||
| hb_with_flower_up_close_2 = open(f"{RESOURCES_PATH}hb_with_flower_up_close_2.txt").readlines() | ||
| for _ in range(0, 2): | ||
| for _ in range(0, 5): | ||
| for _ in range(2): | ||
| for _ in range(5): | ||
| await self.cls_display_delay(hb_with_flower_1, 0.125) | ||
| await self.cls_display_delay(hb_with_flower_2, 0.125) | ||
| for _ in range(0, 5): | ||
| for _ in range(5): |
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 SillyCommands.silly_hummingbot refactored with the following changes:
- Replace range(0, x) with range(x) (
remove-zero-from-range)
| for _ in range(0, 3): | ||
| for _ in range(3): | ||
| await self.cls_display_delay(self.display_alert("roger")) | ||
| roger_1 = open(f"{RESOURCES_PATH}roger_1.txt").readlines() | ||
| roger_2 = open(f"{RESOURCES_PATH}roger_2.txt").readlines() | ||
| roger_3 = open(f"{RESOURCES_PATH}roger_3.txt").readlines() | ||
| roger_4 = open(f"{RESOURCES_PATH}roger_4.txt").readlines() | ||
| for _ in range(0, 2): | ||
| for _ in range(0, 3): | ||
| for _ in range(2): | ||
| for _ in range(3): |
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 SillyCommands.silly_roger refactored with the following changes:
- Replace range(0, x) with range(x) (
remove-zero-from-range)
| for _ in range(0, 5): | ||
| for _ in range(0, 5): | ||
| for _ in range(5): | ||
| for _ in range(5): |
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 SillyCommands.silly_victor refactored with the following changes:
- Replace range(0, x) with range(x) (
remove-zero-from-range)
| for _ in range(0, 2): | ||
| for _ in range(2): | ||
| await self.cls_display_delay(self.display_alert("rein")) | ||
| rein_1 = open(f"{RESOURCES_PATH}rein_1.txt").readlines() | ||
| rein_2 = open(f"{RESOURCES_PATH}rein_2.txt").readlines() | ||
| rein_3 = open(f"{RESOURCES_PATH}rein_3.txt").readlines() | ||
| for _ in range(0, 2): | ||
| for _ in range(2): |
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 SillyCommands.silly_rein refactored with the following changes:
- Replace range(0, x) with range(x) (
remove-zero-from-range)
| dennis_loading_3 = open(f"{RESOURCES_PATH}dennis_loading_3.txt").readlines() | ||
| dennis_loading_4 = open(f"{RESOURCES_PATH}dennis_loading_4.txt").readlines() | ||
| for _ in range(0, 1): | ||
| for _ in range(1): |
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 SillyCommands.silly_dennis refactored with the following changes:
- Replace range(0, x) with range(x) (
remove-zero-from-range)
| func: Callable, *args, **kwargs): | ||
| while True: | ||
| all_ready = all([market.ready for market in self.markets.values()]) | ||
| all_ready = all(market.ready for market in self.markets.values()) |
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 StartCommand.wait_till_ready refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator)
| if inclusive: | ||
| if min_value is not None and max_value is not None: | ||
| if min_value is not None and max_value is not None: | ||
| if inclusive: | ||
| if not (min_value <= int_value <= max_value): | ||
| return f"Value must be between {min_value} and {max_value}." | ||
| elif min_value is not None and not int_value >= min_value: | ||
| return f"Value cannot be less than {min_value}." | ||
| elif max_value is not None and not int_value <= max_value: | ||
| return f"Value cannot be more than {max_value}." | ||
| else: | ||
| if min_value is not None and max_value is not None: | ||
| if not (min_value < int_value < max_value): | ||
| return f"Value must be between {min_value} and {max_value} (exclusive)." | ||
| elif min_value is not None and not int_value > min_value: | ||
| return f"Value must be more than {min_value}." | ||
| elif max_value is not None and not int_value < max_value: | ||
| return f"Value must be less than {max_value}." | ||
| elif not (min_value < int_value < max_value): | ||
| return f"Value must be between {min_value} and {max_value} (exclusive)." | ||
| elif min_value is not None and int_value < min_value: | ||
| return f"Value cannot be less than {min_value}." | ||
| elif max_value is not None and int_value > max_value: | ||
| return f"Value cannot be more than {max_value}." |
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 validate_int refactored with the following changes:
- Hoist repeated code outside conditional statement (
hoist-statement-from-if) - Simplify logical expression using De Morgan identities (
de-morgan) - Merge else clause's nested if statement into elif (
merge-else-if-into-elif)
| assert callable(self._validator) | ||
| assert callable(self._on_validated) | ||
| if self.required and (value is None or value == ""): | ||
| if self.required and (value is None or not value): |
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 ConfigVar.validate refactored with the following changes:
- Replaces an empty collection equality with a boolean operation. (
simplify-empty-collection-comparison)
| all_dict.update({f"{name}_percent_fee_token": new_fee_config_var(f"{name}_percent_fee_token", type_str="str")}) | ||
| all_dict.update( | ||
| {f"{name}_maker_percent_fee": new_fee_config_var(f"{name}_maker_percent_fee", type_str="decimal")} | ||
| all_dict[f"{name}_percent_fee_token"] = new_fee_config_var( | ||
| f"{name}_percent_fee_token", type_str="str" | ||
| ) | ||
| all_dict.update( | ||
| {f"{name}_taker_percent_fee": new_fee_config_var(f"{name}_taker_percent_fee", type_str="decimal")} | ||
|
|
||
| all_dict[f"{name}_maker_percent_fee"] = new_fee_config_var( | ||
| f"{name}_maker_percent_fee", type_str="decimal" | ||
| ) | ||
|
|
||
| all_dict[f"{name}_taker_percent_fee"] = new_fee_config_var( | ||
| f"{name}_taker_percent_fee", type_str="decimal" | ||
| ) | ||
|
|
||
| fee_application = f"{name}_buy_percent_fee_deducted_from_returns" | ||
| all_dict.update({fee_application: new_fee_config_var(fee_application, type_str="bool")}) | ||
| all_dict.update( | ||
| {f"{name}_maker_fixed_fees": new_fee_config_var(f"{name}_maker_fixed_fees", type_str="list")} | ||
| all_dict[fee_application] = new_fee_config_var( | ||
| fee_application, type_str="bool" | ||
| ) | ||
| all_dict.update( | ||
| {f"{name}_taker_fixed_fees": new_fee_config_var(f"{name}_taker_fixed_fees", type_str="list")} | ||
|
|
||
| all_dict[f"{name}_maker_fixed_fees"] = new_fee_config_var( | ||
| f"{name}_maker_fixed_fees", type_str="list" | ||
| ) | ||
|
|
||
| all_dict[f"{name}_taker_fixed_fees"] = new_fee_config_var( | ||
| f"{name}_taker_fixed_fees", type_str="list" | ||
| ) | ||
|
|
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 fee_overrides_dict refactored with the following changes:
- Add single value to dictionary directly rather than using update() (
simplify-dictionary-update)
|
|
||
| def generate_client_id() -> str: | ||
| vals = [random.choice(range(0, 256)) for i in range(0, 20)] | ||
| vals = [random.choice(range(256)) for _ in range(20)] |
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 generate_client_id refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore) - Replace range(0, x) with range(x) (
remove-zero-from-range)
| text_lines = ["" + line for line in joined_df.to_string(index=False).split("\n")] | ||
| text_lines = [ | ||
| f"{line}" for line in joined_df.to_string(index=False).split("\n") | ||
| ] | ||
|
|
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 OrderBookTab.display.get_order_book_text refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.36%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
4383d99 to
691913f
Compare
Branch
masterrefactored 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
masterbranch, then run:Help us improve this pull request!