autodiscover opmodes + opmode example#260
Conversation
98427ce to
cf18107
Compare
|
|
||
|
|
||
| @overload | ||
| def autonomous(cls: _OpModeType, /) -> _OpModeType: ... |
There was a problem hiding this comment.
need docstrings for these decorators, should also document them in OpModeRobot
|
|
||
| def __init__(self): | ||
| super().__init__() | ||
| _discover_decorated_opmodes(self) |
There was a problem hiding this comment.
All of the associated code with this seems a bit messy, need to reorg it a bit
| """Provides one Gamepad per standard driver station port.""" | ||
|
|
||
| def __init__(self): | ||
| self._gamepads = tuple(Gamepad(port) for port in range(6)) |
There was a problem hiding this comment.
Suggest using the constant JOYSTICK_PORTS instead of a magic number
Also, why a tuple instead of an array? I don't know that it matters but I was curious if there are benefits I don't know about.
There was a problem hiding this comment.
The AI decided it was the right fit :)
Generally, a tuple is appropriate for something that shouldn't be changed, and a list is more appropriate for things that are mutable.
| user_controls: Any | None, | ||
| ) -> dict[str, Any]: | ||
| kwargs: dict[str, Any] = {} | ||
| initializer = opmodeCls.__dict__.get("__init__") |
There was a problem hiding this comment.
Is there a reason we explicitly look for __init__? Calling inspect.signature() on a type is perfectly valid, and would mean we don't have to remove the self parameter.
There was a problem hiding this comment.
If we don't grab __init__ out of the object dict, we can pass through a Callable instead. That should make the type checker happier below too.
| opmodeCls: Callable[..., OpMode], |
7226c87 to
d4937dd
Compare
9d96931 to
0a3ce73
Compare
0a3ce73 to
991fe2f
Compare
|
|
||
| def __init__(self): | ||
| super().__init__() | ||
| _discover_decorated_opmodes(self) |
There was a problem hiding this comment.
Should this be optional for testing purposes? It's slightly odd that this is defined as a module-level function rather than a method.
There was a problem hiding this comment.
Yeah, I agree that the placement of the function is a bit odd. Probably should make this so it can be optional.
This is purely vibe-coded, but this is at least an initial look at what this will look like