Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Nov 5, 2023

Conversation

auscompgeek
Copy link
Member

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.

@virtuald virtuald merged commit 5bcab9d into main Nov 5, 2023
18 checks passed
@virtuald virtuald deleted the magicbot-inject-init-non-type-msg branch November 5, 2023 02:16
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.

None yet

2 participants