You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.
It would be nice to use the board's human-readable name, Board.name, in the error message produced by BoardGroup.singular when the wrong number of boards are connected.
The relevant section of code in BoardGroup.singular:
name=self._backend_class.board.__name__raiseCommunicationError(f"expected exactly one {name} to be connected, but found {num}")
I'd like to write this as:
name: str=self._backend_class.board.name
...
However, I get a type error:
j5/boards/board.py:108: error: "Callable[[Backend], Type[Board]]" has no attribute "name"
This is because Backend.board is declared as an instance property rather than a class attribute (in order to get the effect of abstractmethod). This means that although the type of self._backend_class().board is Type[Board], the type of self._backend_class.board is actually Callable[[Backend], Type[Board]], because the property's descriptor hasn't kicked in.
This could be solved at the typechecking level by instead declaring Backend.board as a class attribute:
classBackend:
board: Type['Board']
but then we lose the effect of abstractmethod: Backends can now be instantiated even if they don't define a board attribute, like so:
classBadBackend(Backend):
@classmethoddefdiscover(cls) ->Set['Board']:
raiseNotImplementedErrorenvironment=Environment("MockEnvironment")
# board = Boardfirmware_version=NoneBadBackend() # shouldn't be allowed to succeed
I wonder if we can construct an "abstract attribute" mechanism that ties in with the standard abc mechanisms? Alternatively, maybe we can just convince the typechecker that the attribute is abstract without it having to be enforced at runtime?
The text was updated successfully, but these errors were encountered:
It would be nice to use the board's human-readable name,
Board.name
, in the error message produced byBoardGroup.singular
when the wrong number of boards are connected.The relevant section of code in
BoardGroup.singular
:I'd like to write this as:
However, I get a type error:
This is because
Backend.board
is declared as an instance property rather than a class attribute (in order to get the effect ofabstractmethod
). This means that although the type ofself._backend_class().board
isType[Board]
, the type ofself._backend_class.board
is actuallyCallable[[Backend], Type[Board]]
, because the property's descriptor hasn't kicked in.This could be solved at the typechecking level by instead declaring
Backend.board
as a class attribute:but then we lose the effect of
abstractmethod
:Backend
s can now be instantiated even if they don't define aboard
attribute, like so:I wonder if we can construct an "abstract attribute" mechanism that ties in with the standard
abc
mechanisms? Alternatively, maybe we can just convince the typechecker that the attribute is abstract without it having to be enforced at runtime?The text was updated successfully, but these errors were encountered: