Skip to content
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

Merged
merged 5 commits into from
Oct 31, 2024
Merged

💥 remove SubAnalyser #92

merged 5 commits into from
Oct 31, 2024

Conversation

RF-Tar-Railt
Copy link
Member

@RF-Tar-Railt RF-Tar-Railt commented Oct 29, 2024

Summary by Sourcery

Enhancements:

  • Refactor the Analyser class to remove the SubAnalyser dependency, consolidating functionality into a single class.

Copy link

sourcery-ai bot commented Oct 29, 2024

Reviewer's Guide by Sourcery

This 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 Analyser

classDiagram
    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
Loading

Removed class diagram for SubAnalyser

classDiagram
    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()
    }
Loading

File-Level Changes

Change Details Files
Refactored command parsing to use a flatter data structure
  • Removed SubAnalyser class and merged functionality into main Analyser class
  • Changed result storage from nested dictionaries to flat dictionaries with tuple-based paths
  • Added value_result and args_result to store command parsing results
  • Simplified option and subcommand handling by using tuple paths instead of nested structures
src/arclet/alconna/ingedia/_analyser.py
src/arclet/alconna/ingedia/_handlers.py
Simplified command lookup and parameter tracking
  • Added _lookup_map to cache command option aliases
  • Removed ChainMap based parameter stack tracking
  • Removed filter_out functionality from Argv class
  • Updated parameter validation to use _unvisited map
src/arclet/alconna/ingedia/_argv.py
src/arclet/alconna/base.py
Reorganized utility functions and type definitions
  • Moved utility functions from _util.py to utils.py
  • Renamed typing.py to utils.py and consolidated utility code
  • Updated imports across codebase to reflect new module structure
src/arclet/alconna/ingedia/_util.py
src/arclet/alconna/typing.py
src/arclet/alconna/utils.py
Updated result handling and access patterns
  • Modified Arparma class to work with new flat result structure
  • Added property accessors for backward compatibility
  • Updated test cases to use new result access patterns
  • Added deprecation warnings for old attribute access methods
src/arclet/alconna/arparma.py
tests/analyser_test.py
tests/core_test.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a 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:
Copy link

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:

src/arclet/alconna/arparma.py Outdated Show resolved Hide resolved


class Analyser(SubAnalyser):
def _compile(ana: Analyser, sub: Subcommand, path: tuple[str, ...]):
Copy link

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)


ExplanationThe 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.

src/arclet/alconna/ingedia/_analyser.py Outdated Show resolved Hide resolved
@@ -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]):
Copy link

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)


ExplanationThe 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.

src/arclet/alconna/ingedia/_handlers.py Outdated Show resolved Hide resolved
@@ -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]:
Copy link

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)


ExplanationThe 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.

src/arclet/alconna/ingedia/_handlers.py Outdated Show resolved Hide resolved
@@ -916,13 +920,13 @@ def test_conflict():
)
res1 = core26.parse("core26 --foo bar --bar")
Copy link

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)

@RF-Tar-Railt RF-Tar-Railt merged commit 31f30c6 into dev Oct 31, 2024
6 checks passed
@RF-Tar-Railt RF-Tar-Railt deleted the feat/flatten_analyser branch October 31, 2024 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant