robotpy / robotpy-wpilib-utilities

Useful utility functions/objects for RobotPy
BSD 3-Clause "New" or "Revised" License
11 stars 19 forks source link

magicbot: Fix non-type annotation error for init #207

Closed auscompgeek closed 10 months ago

auscompgeek commented 10 months ago

Given the following component class:

class Component:
    def __init__(self, foo: 1): ...

An error message that didn't make much sense contextually would be raised:

Traceback (most recent call last):
  File ".../site-packages/wpilib/_impl/start.py", line 75, in start
    return self._start(robot_cls)
  File ".../site-packages/wpilib/_impl/start.py", line 163, in _start
    self.robot.startCompetition()
  File ".../site-packages/magicbot/magicrobot.py", line 361, in startCompetition
    self.robotInit()
  File ".../site-packages/magicbot/magicrobot.py", line 110, in robotInit
    self._create_components()
  File ".../site-packages/magicbot/magicrobot.py", line 616, in _create_components
    component = self._create_component(m, ctyp, injectables)
  File ".../site-packages/magicbot/magicrobot.py", line 683, in _create_component
    requests = get_injection_requests(type_hints, name)
  File ".../site-packages/magicbot/inject.py", line 42, in get_injection_requests
    raise TypeError(
TypeError: Component component1 has a non-type annotation foo: 1
Lone non-injection variable annotations are disallowed, did you want to assign a static variable?

This removes the bit about static variables when injecting into the __init__ method.

Whilst we're here, also split that bit into two sentences to make it easier to read.