Skip to content

refactor(backends): Connector is an abstract class again, not a Protocol - #923

Open
petercorke wants to merge 1 commit into
mainfrom
refactor/connector-abc
Open

petercorke wants to merge 1 commit into
mainfrom
refactor/connector-abc

Conversation

@petercorke

Copy link
Copy Markdown
Owner

What

Connector goes back from a typing.Protocol to an abstract base class, as it was before #788.

  • Connector(ABC), with the same abstract methods and flags.
  • RTB's roboticstoolbox.backends.swift.Swift wrapper inherits it. Its _add_teach_panel now has the base class's signature (handle=None, block=True), which mypy required.
  • TestConnectorProtocol becomes TestConnector: a class that does not inherit is not a Connector, and the Swift wrapper is a subclass.
  • The "contract" paragraph in docs/source/arm_backend.rst no longer says any object with the methods qualifies.

Why

#788 made Connector a Protocol because upstream Swift does not depend on RTB and cannot inherit it. But load_backend returns RTB's own wrapper, which is RTB code and can inherit. The Protocol bought "any object with these methods qualifies", which no backend relies on, and it cost:

  • Adding a capability flag to Connector breaks the structural isinstance check for every backend that does not inherit.
  • A backend that leaves out a method (for example hold) fails only when plot() calls it, not when the backend is made.
  • A new flag cannot have a default that every backend picks up.

An abstract class fixes all three. It matters now because backends from outside the Toolbox (#903, #907) are being added, and the base class is easier to change before they exist. It is also the groundwork for registering backends by name (#902).

This touches the protocol contract that #676 lists, so it is worth a look from anyone with a backend of their own.

Behaviour

No change for the shipped backends. plot() never required inheritance, it calls methods. A backend that does not inherit Connector still works when it is used directly; it is no longer an instance of it.

Checks

  • mypy: no issues.
  • ruff: nothing new.
  • Full suite: 20 failures, the same 20 on main and on this branch (checked by diffing the lists).
  • Not run: Swift with a live browser. The wrapper's methods are unchanged apart from the default arguments of _add_teach_panel.

Refs #676, #902.

Written with the help of Claude Code (Claude Sonnet 5.5).

🤖 Generated with Claude Code

#788 made Connector a Protocol so that upstream Swift, which does not depend
on RTB, could count as one.  RTB's own Swift wrapper is RTB code and can
inherit, and no backend loaded by name is the upstream class.  An abstract
base class lets a new flag get a default that every backend inherits, and a
missing method is an error when the backend is made.

The Swift wrapper's _add_teach_panel now has the signature of the base class.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · -2 duplication

Metric Results
Complexity 0
Duplication -2

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

This branch has not been deployed

No deployments
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