Skip to content

Update control.py #5300

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Update control.py #5300

wants to merge 1 commit into from

Conversation

omamkaz
Copy link
Contributor

@omamkaz omamkaz commented May 12, 2025

Summary of Changes:

Unified Logic:

    Merged invoke_method and invoke_method_async logic into a single private method __invoke_method to eliminate code duplication.

Added Flexibility:

    Introduced is_async flag in __invoke_method to switch between sync and async method invocation.

Behavior Preserved:

    Existing functionality (assertion, argument cleaning, method dispatch) remains unchanged—just refactored for cleaner, more maintainable code.

Improved Maintainability:

    Any future changes to invocation logic now require updates in only one place instead of two.

Description

Refactored value parsing logic for attribute retrieval:

  • Moved str type check earlier to reduce repetitive isinstance calls.

  • Preserved behavior for all supported data_type cases (bool, bool?, float, int), including default fallback when needed.

  • Logic flow is now cleaner and slightly more performant due to early return on non-str values.

Refactored invoke_method and invoke_method_async to reduce duplication:

  • Moved shared logic into a private __invoke_method helper.

  • Introduced is_async flag to toggle between _invoke_method and
    _invoke_method_async.

  • Preserves assertion, argument filtering, and all functional behavior from the previous version.

Test Code

# Test code for the review of this PR

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I signed the CLA.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • New and existing tests pass locally with my changes
  • I have made corresponding changes to the documentation (if applicable)

Screenshots

Additional details

Summary by Sourcery

Refactor control.py to reduce code duplication and improve maintainability by unifying sync and async method invocation and streamlining attribute parsing

Enhancements:

  • Consolidate invoke_method and invoke_method_async into a single private __invoke_method with an is_async flag
  • Streamline _get_attr by performing an early non-str check and simplifying data type parsing
  • Simplify str implementation using a dict comprehension to build attribute dictionaries

- Moved: str type check earlier to reduce repetitive isinstance calls.
- Preserved behavior for all supported data_type cases (bool, bool?, float, int), including default fallback 
- Moved: shared logic into a private __invoke_method helper.
- Introduced is_async flag to toggle between _invoke_method and _invoke_method_async.
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