Skip to content

refactor: use Protocol and singledispatch - #3607

Merged
mkoura merged 1 commit into
masterfrom
protocol_singledispatch_refactor
Aug 12, 2026
Merged

refactor: use Protocol and singledispatch#3607
mkoura merged 1 commit into
masterfrom
protocol_singledispatch_refactor

Conversation

@mkoura

@mkoura mkoura commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Prefer functional style over class inheritance:

  • Replace the BaseFilter base class with a structural ResourceFilter protocol. OneOf stores resources as a tuple so one-shot iterators survive repeated filter() calls in the cluster getter retry loop.
  • Split the isinstance chains in check_action_view and check_vote_view into functools.singledispatch handlers, removing the C901 suppressions. Behavior is unchanged, including the NotImplementedError fallback for unregistered action/vote types.

Prefer functional style over class inheritance:

- Replace the `BaseFilter` base class with a structural
  `ResourceFilter` protocol. `OneOf` stores resources as a tuple so
  one-shot iterators survive repeated `filter()` calls in the cluster
  getter retry loop.
- Split the isinstance chains in `check_action_view` and
  `check_vote_view` into `functools.singledispatch` handlers, removing
  the C901 suppressions. Behavior is unchanged, including the
  `NotImplementedError` fallback for unregistered action/vote types.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors cluster resource selection and governance view-check helpers to prefer structural typing and functional dispatch, reducing inheritance and large isinstance chains while keeping behavior the same.

Changes:

  • Replaced the BaseFilter class with a structural ResourceFilter Protocol, and updated OneOf to store resources as a tuple to avoid one-shot iterator exhaustion.
  • Refactored governance action/vote “view” checks to use functools.singledispatch handlers instead of long isinstance chains, removing prior complexity suppressions.
  • Updated cluster getter type hints to align with the new filter protocol.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
cardano_node_tests/utils/governance_utils.py Uses singledispatch to map action/vote types to expected CLI “view” output structures, replacing isinstance chains.
cardano_node_tests/cluster_management/resources_management.py Introduces ResourceFilter protocol and updates OneOf to eagerly materialize resource iterables.
cardano_node_tests/cluster_management/cluster_getter.py Adjusts return type annotations to reflect the new ResourceFilter protocol.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@mkoura
mkoura merged commit 69e57f1 into master Aug 12, 2026
4 checks passed
@mkoura
mkoura deleted the protocol_singledispatch_refactor branch August 12, 2026 15:41
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.

2 participants