-
Notifications
You must be signed in to change notification settings - Fork 6
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
💥 remove SubAnalyser #92
Conversation
Reviewer's Guide by SourceryThis PR removes the SubAnalyser class and refactors the command parsing logic to use a flatter, more efficient data structure. The changes simplify the parsing process by removing nested result structures and using tuple-based paths to track command hierarchy. Updated class diagram for AnalyserclassDiagram
class Analyser {
+Alconna command
+Argv argv
+bool extra_allow
+dict default_main_only
+dict need_main_args
+dict compact_params
+dict default_value_result
+dict default_arg_result
+dict value_result
+dict args_result
+HeadResult header_result
+Exception _error
+dict _unvisited
+void reset()
+void update(Subcommand current, tuple path)
+Exception process(Argv argv, bool name_validated)
}
class Subcommand {
+list options
+dict _lookup_map
}
Analyser --> Subcommand : uses
Removed class diagram for SubAnalyserclassDiagram
class SubAnalyser {
-Subcommand command
-bool default_main_only
-bool need_main_args
-dict compile_params
-list compact_params
-_Args self_args
-dict subcommands_result
-dict options_result
-dict args_result
-HeadResult header_result
-Any value_result
-dict default_opt_result
-dict default_sub_result
-bool extra_allow
-bool soft_keyword
-void _clr()
-SubcommandResult result()
-void reset()
-Self process(Argv argv, bool name_validated)
-void compile()
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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've reviewed this pull request using the Sourcery rules engine. If you would also like our AI-powered code review then let us know.
if path == (): | ||
continue | ||
prefixes, key = path[:-1], path[-1] | ||
if not prefixes: |
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.
issue (code-quality): We've found these issues:
- Swap if/else branches [×2] (
swap-if-else-branches
) - Merge else clause's nested if statement into elif [×2] (
merge-else-if-into-elif
)
|
||
|
||
class Analyser(SubAnalyser): | ||
def _compile(ana: Analyser, sub: Subcommand, path: tuple[str, ...]): |
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.
issue (code-quality): Low code quality found in _compile - 23% (low-code-quality
)
Explanation
The quality score for this function is below the quality threshold of 25%.This score is a combination of the method length, cognitive complexity and working memory.
How can you solve this?
It might be worth refactoring this function to make it shorter and more readable.
- Reduce the function length by extracting pieces of functionality out into
their own functions. This is the most important thing you can do - ideally a
function should be less than 10 lines. - Reduce nesting, perhaps by introducing guard clauses to return early.
- Ensure that variables are tightly scoped, so that code using related concepts
sits together within the function rather than being scattered.
@@ -76,7 +74,7 @@ def _validate(argv: Argv, target: Arg[Any], value: Pattern[Any], result: dict[st | |||
result[target.name] = res._value # noqa | |||
|
|||
|
|||
def step_varpos(argv: Argv, args: _Args, slot: tuple[int | Literal["+", "*", "str"], Arg], result: dict[str, Any]): | |||
def step_varpos(ana: Analyser, argv: Argv, args: _Args, slot: tuple[int | Literal["+", "*", "str"], Arg], result: dict[str, Any]): |
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.
issue (code-quality): Low code quality found in step_varpos - 17% (low-code-quality
)
Explanation
The quality score for this function is below the quality threshold of 25%.This score is a combination of the method length, cognitive complexity and working memory.
How can you solve this?
It might be worth refactoring this function to make it shorter and more readable.
- Reduce the function length by extracting pieces of functionality out into
their own functions. This is the most important thing you can do - ideally a
function should be less than 10 lines. - Reduce nesting, perhaps by introducing guard clauses to return early.
- Ensure that variables are tightly scoped, so that code using related concepts
sits together within the function rather than being scattered.
@@ -217,11 +214,12 @@ def _raise(target: Arg, arg: Any, res: Any): | |||
raise InvalidParam(target.field.get_unmatch_tips(arg, res.error().args[0]), arg) | |||
|
|||
|
|||
def analyse_args(argv: Argv, args: _Args) -> dict[str, Any]: | |||
def analyse_args(analyser: Analyser, argv: Argv, args: _Args) -> dict[str, Any]: |
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.
issue (code-quality): Low code quality found in analyse_args - 14% (low-code-quality
)
Explanation
The quality score for this function is below the quality threshold of 25%.This score is a combination of the method length, cognitive complexity and working memory.
How can you solve this?
It might be worth refactoring this function to make it shorter and more readable.
- Reduce the function length by extracting pieces of functionality out into
their own functions. This is the most important thing you can do - ideally a
function should be less than 10 lines. - Reduce nesting, perhaps by introducing guard clauses to return early.
- Ensure that variables are tightly scoped, so that code using related concepts
sits together within the function rather than being scattered.
@@ -916,13 +920,13 @@ def test_conflict(): | |||
) | |||
res1 = core26.parse("core26 --foo bar --bar") |
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.
issue (code-quality): Extract duplicate code into function [×2] (extract-duplicate-method
)
Summary by Sourcery
Enhancements: