Conversation
| time_passed = 0 | ||
|
|
||
| while time_passed < 5: | ||
| for time_passed in range(5): |
There was a problem hiding this comment.
Function topper refactored with the following changes:
- Replace while with for (
while-to-for)
| if value: | ||
| level = logging.INFO | ||
| else: | ||
| level = logging.WARNING | ||
| level = logging.INFO if value else logging.WARNING |
There was a problem hiding this comment.
Function verbosity_callback refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| def validate_delay(cls, val): # pylint: disable=no-self-use,no-self-argument | ||
| def validate_delay(cls, val): # pylint: disable=no-self-use,no-self-argument | ||
| """Check if the delay used by user is values. If not, use closest logical values.""" | ||
| if val not in range(0, 101): | ||
| logging.warning("delay must be within 0 to 100 seconds") | ||
| if val > 100: | ||
| val = 100 | ||
| if val < 0: | ||
| val = 0 | ||
| val = min(val, 100) | ||
| val = max(val, 0) |
There was a problem hiding this comment.
Function PastSettings.validate_delay refactored with the following changes:
- Replace comparison with min/max call [×2] (
min-max-identity)
| tutorial_link = "Learn more http://bit.ly/configure-tgcf" | ||
|
|
||
| if CONFIG_FILE_NAME in os.listdir(): | ||
| logging.info(f"{CONFIG_FILE_NAME} detected") | ||
| return 1 | ||
| if os.getenv("TGCF_CONFIG"): | ||
| logging.info(f"env var {CONFIG_ENV_VAR_NAME} detected") | ||
| if not ".env" in os.listdir(): | ||
| return 2 | ||
| if not os.getenv("TGCF_CONFIG"): | ||
| return 0 | ||
| logging.info(f"env var {CONFIG_ENV_VAR_NAME} detected") | ||
| if ".env" not in os.listdir(): | ||
| return 2 | ||
|
|
||
| tutorial_link = "Learn more http://bit.ly/configure-tgcf" | ||
|
|
||
| logging.warning( | ||
| f"If you can create files in your system,\ | ||
| logging.warning( | ||
| f"If you can create files in your system,\ | ||
| you should use tgcf.config.yml and not .env to define configuration {tutorial_link}" | ||
| ) | ||
| sys.exit(1) | ||
| else: | ||
| return 0 | ||
| ) | ||
| sys.exit(1) |
There was a problem hiding this comment.
Function detect_config_type refactored with the following changes:
- Move assignments closer to their usage (
move-assign) - Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else) - Simplify logical expression using De Morgan identities (
de-morgan)
| if config_dict: | ||
| config = Config(**config_dict) | ||
| else: | ||
| config = Config() | ||
| config = Config(**config_dict) if config_dict else Config() |
There was a problem hiding this comment.
Function read_config refactored with the following changes:
- Simplify conditional into switch-like form (
switch) - Replace if statement with if expression (
assign-if-exp)
| if not len(splitted) == 2: | ||
| if len(splitted) != 2: | ||
| splitted = text.split("\n", 1) | ||
| if not len(splitted) == 2: | ||
| return "" | ||
| if len(splitted) != 2: | ||
| return "" |
There was a problem hiding this comment.
Function get_args refactored with the following changes:
- Simplify logical expression using De Morgan identities [×2] (
de-morgan) - Hoist conditional out of nested conditional (
hoist-if-from-if)
| def display_forwards(forwards: List[Forward]) -> str: | ||
| """Return a string that beautifully displays all current forwards.""" | ||
| if len(forwards) == 0: | ||
| if not forwards: |
There was a problem hiding this comment.
Function display_forwards refactored with the following changes:
- Simplify sequence length comparison (
simplify-len-comparison)
|
|
||
| try: | ||
| plugin_module = import_module("tgcf.plugins." + plugin_id) | ||
| plugin_module = import_module(f"tgcf.plugins.{plugin_id}") |
There was a problem hiding this comment.
Function load_plugins refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Simplify logical expression using De Morgan identities (
de-morgan) - Add single value to dictionary directly rather than using update() (
simplify-dictionary-update)
|
|
||
| async def modify(self, tm: TgcfMessage) -> TgcfMessage: | ||
| if not tm.file_type in ["gif", "video", "photo"]: | ||
| if tm.file_type not in ["gif", "video", "photo"]: |
There was a problem hiding this comment.
Function TgcfMark.modify refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan)
| async def modify(self, tm: TgcfMessage) -> TgcfMessage: | ||
|
|
||
| if not tm.file_type in ["photo"]: | ||
| if tm.file_type not in ["photo"]: |
There was a problem hiding this comment.
Function TgcfOcr.modify refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan)
Branch
mainrefactored 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
mainbranch, then run:Help us improve this pull request!