Repository navigation
refactor(backends): Connector is an abstract class again, not a Protocol - #923
Open
petercorke wants to merge 1 commit into
Open
petercorke wants to merge 1 commit into
petercorke wants to merge 1 commit into
Conversation
#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>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | -2 |
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Connectorgoes back from atyping.Protocolto an abstract base class, as it was before #788.Connector(ABC), with the same abstract methods and flags.roboticstoolbox.backends.swift.Swiftwrapper inherits it. Its_add_teach_panelnow has the base class's signature (handle=None, block=True), which mypy required.TestConnectorProtocolbecomesTestConnector: a class that does not inherit is not aConnector, and the Swift wrapper is a subclass.docs/source/arm_backend.rstno longer says any object with the methods qualifies.Why
#788 made
Connectora Protocol because upstream Swift does not depend on RTB and cannot inherit it. Butload_backendreturns 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:Connectorbreaks the structuralisinstancecheck for every backend that does not inherit.hold) fails only whenplot()calls it, not when the backend is made.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 inheritConnectorstill works when it is used directly; it is no longer an instance of it.Checks
mypy: no issues.ruff: nothing new.mainand on this branch (checked by diffing the lists)._add_teach_panel.Refs #676, #902.
Written with the help of Claude Code (Claude Sonnet 5.5).
🤖 Generated with Claude Code