-
Notifications
You must be signed in to change notification settings - Fork 34
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
add default_complete
option (Sourcery refactored)
#84
Conversation
@@ -162,7 +162,6 @@ def get_option_strings(parser): | |||
def recurse(parser, prefix): | |||
"""recurse through subparsers, appending to the return lists""" | |||
subparsers = [] | |||
option_strings = [] |
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 get_bash_commands.recurse
refactored with the following changes:
- Merge append into list declaration (
merge-list-append
) - Move assignment closer to its usage within a block (
move-assign-in-block
) - Use named expression to simplify assignment and conditional (
use-named-expression
) - Replace call to format with f-string [×10] (
use-fstring-for-formatting
) - Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
)
This removes the following comments ( why? ):
# optional arguments
return (('{nargs}{options}"[{help}]"' if isinstance( | ||
opt, FLAG_OPTION) else '{nargs}{options}"[{help}]:{dest}:{pattern}"').format( | ||
nargs=('"(- :)"' if isinstance(opt, OPTION_END) else | ||
'"*"' if isinstance(opt, OPTION_MULTI) else ""), | ||
options=("{{{}}}".format(",".join(opt.option_strings)) | ||
if len(opt.option_strings) > 1 else '"{}"'.format("".join( | ||
opt.option_strings))), | ||
return ( | ||
( | ||
'{nargs}{options}"[{help}]"' | ||
if isinstance(opt, FLAG_OPTION) | ||
else '{nargs}{options}"[{help}]:{dest}:{pattern}"' | ||
) | ||
.format( | ||
nargs=( | ||
'"(- :)"' | ||
if isinstance(opt, OPTION_END) | ||
else '"*"' | ||
if isinstance(opt, OPTION_MULTI) | ||
else "" | ||
), | ||
options=( | ||
"{{{}}}".format(",".join(opt.option_strings)) | ||
if len(opt.option_strings) > 1 | ||
else '"{}"'.format("".join(opt.option_strings)) | ||
), | ||
help=escape_zsh(opt.help or ""), | ||
dest=opt.dest, | ||
pattern=complete2pattern(opt.complete, "zsh", choice_type2fn) if hasattr( | ||
opt, "complete") else | ||
(choice_type2fn[opt.choices[0].type] if isinstance(opt.choices[0], Choice) else | ||
"({})".format(" ".join(map(str, opt.choices)))) if opt.choices else "", | ||
).replace('""', "")) | ||
pattern=complete2pattern(opt.complete, "zsh", choice_type2fn) | ||
if hasattr(opt, "complete") | ||
else ( | ||
choice_type2fn[opt.choices[0].type] | ||
if isinstance(opt.choices[0], Choice) | ||
else f'({" ".join(map(str, opt.choices))})' | ||
) | ||
if opt.choices | ||
else "", | ||
) | ||
.replace('""', "") | ||
) |
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 complete_zsh.format_optional
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
pattern=complete2pattern(opt.complete, "zsh", choice_type2fn) if hasattr( | ||
opt, "complete") else | ||
(choice_type2fn[opt.choices[0].type] if isinstance(opt.choices[0], Choice) else | ||
"({})".format(" ".join(map(str, opt.choices)))) if opt.choices else default_complete, | ||
pattern=complete2pattern(opt.complete, "zsh", choice_type2fn) | ||
if hasattr(opt, "complete") | ||
else ( | ||
choice_type2fn[opt.choices[0].type] | ||
if isinstance(opt.choices[0], Choice) | ||
else f'({" ".join(map(str, opt.choices))})' | ||
) | ||
if opt.choices | ||
else default_complete, |
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 complete_zsh.format_positional
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
if not sub.choices or not isinstance(sub.choices, dict): | ||
if not isinstance(sub.choices, dict): | ||
# positional argument | ||
all_commands[prefix]["arguments"].append(format_positional(sub)) | ||
else: # subparser | ||
log.debug("choices:{}:{}".format(prefix, sorted(sub.choices))) | ||
log.debug(f"choices:{prefix}:{sorted(sub.choices)}") |
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 complete_zsh.recurse
refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if
) - Replace call to format with f-string (
use-fstring-for-formatting
) - Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
)
commands = "\n ".join('"{}:{}"'.format(cmd, escape_zsh(opt["help"])) | ||
for cmd, opt in sorted(options["commands"].items())) | ||
commands = "\n ".join( | ||
f'"{cmd}:{escape_zsh(opt["help"])}"' | ||
for cmd, opt in sorted(options["commands"].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 complete_zsh.command_list
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
yield "'{}/{}/({})/'".format( | ||
arg_type, | ||
arg_sel, | ||
choice_strs, | ||
) | ||
else: | ||
arg_complete = getattr(arg, "complete", default_complete) | ||
if arg_complete: | ||
complete_fn = complete2pattern(arg_complete, 'tcsh', choice_type2fn) | ||
if complete_fn: | ||
yield "'{}/{}/{}/'".format(arg_type, arg_sel, complete_fn) | ||
yield f"'{arg_type}/{arg_sel}/({choice_strs})/'" | ||
elif arg_complete := getattr(arg, "complete", default_complete): | ||
if complete_fn := complete2pattern( | ||
arg_complete, 'tcsh', choice_type2fn | ||
): | ||
yield f"'{arg_type}/{arg_sel}/{complete_fn}/'" |
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 complete_tcsh.get_specials
refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif
) - Replace call to format with f-string [×2] (
use-fstring-for-formatting
) - Use named expression to simplify assignment and conditional [×2] (
use-named-expression
)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.07%.
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! |
Pull Request #83 refactored by Sourcery.
If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.
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
default_complete
branch, then run:Help us improve this pull request!