Skip to content

Commit 9c72375

Browse files
authored
Merge pull request #31 from robotpy/mypy
Add mypy checking to CI
2 parents f48b3fe + 5544c62 commit 9c72375

File tree

8 files changed

+34
-10
lines changed

8 files changed

+34
-10
lines changed

.github/workflows/dist.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,24 @@ on:
1111

1212
jobs:
1313
ci:
14-
uses: robotpy/build-actions/.github/workflows/package-pure.yml@v2024-alpha
14+
uses: robotpy/build-actions/.github/workflows/package-pure.yml@v2024
1515
with:
1616
enable_sphinx_check: false
1717
secrets:
1818
META_REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
1919
PYPI_API_TOKEN: ${{ secrets.PYPI_PASSWORD }}
20+
21+
check-mypy:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v3
25+
- uses: actions/setup-python@v4
26+
with:
27+
python-version: "3.12"
28+
- name: Install requirements
29+
run: |
30+
pip --disable-pip-version-check install mypy setuptools wheel setuptools_scm
31+
pip --disable-pip-version-check install --no-build-isolation -e .
32+
- name: Run mypy
33+
run: |
34+
mypy commands2

commands2/button/commandjoystick.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class CommandJoystick(CommandGenericHID):
1313
A version of Joystick with Trigger factories for command-based.
1414
"""
1515

16+
_hid: Joystick
17+
1618
def __init__(self, port: int):
1719
"""
1820
Construct an instance of a controller.

commands2/button/commandps4controller.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class CommandPS4Controller(CommandGenericHID):
1313
A version of PS4Controller with Trigger factories for command-based.
1414
"""
1515

16+
_hid: PS4Controller
17+
1618
def __init__(self, port: int):
1719
"""
1820
Construct an instance of a device.

commands2/button/commandxboxcontroller.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class CommandXboxController(CommandGenericHID):
1313
A version of XboxController with Trigger factories for command-based.
1414
"""
1515

16+
_hid: XboxController
17+
1618
def __init__(self, port: int):
1719
"""
1820
Construct an instance of a controller.

commands2/command.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from enum import Enum
77
from typing import TYPE_CHECKING, Any, Callable, Set
88

9-
from typing_extensions import Self
9+
from typing_extensions import Self, TypeAlias
1010

1111
if TYPE_CHECKING:
1212
from .instantcommand import InstantCommand
@@ -54,17 +54,19 @@ class Command(Sendable):
5454
This class is provided by the NewCommands VendorDep
5555
"""
5656

57-
InterruptionBehavior = InterruptionBehavior # type alias for 2023 location
57+
InterruptionBehavior: TypeAlias = (
58+
InterruptionBehavior # type alias for 2023 location
59+
)
5860

5961
requirements: Set[Subsystem]
6062

6163
def __new__(cls, *args, **kwargs) -> Self:
6264
instance = super().__new__(
6365
cls,
6466
)
65-
instance.requirements = set()
66-
SendableRegistry.add(instance, cls.__name__)
6767
super().__init__(instance)
68+
SendableRegistry.add(instance, cls.__name__)
69+
instance.requirements = set()
6870
return instance
6971

7072
def __init__(self):

commands2/commandscheduler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ class CommandScheduler:
2121
methods to be called and for their default commands to be scheduled.
2222
"""
2323

24-
_instance: Optional[Self] = None
24+
_instance: Optional[CommandScheduler] = None
2525

26-
def __new__(cls) -> Self:
26+
def __new__(cls) -> CommandScheduler:
2727
if cls._instance is None:
2828
return super().__new__(cls)
2929
return cls._instance

commands2/util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from __future__ import annotations
22

3-
from typing import Iterable, Tuple, Union
3+
from typing import Iterable, List, Tuple, Union
44

55
from .command import Command
66

77

88
def flatten_args_commands(
99
*commands: Union[Command, Iterable[Command]]
10-
) -> Tuple[Command]:
11-
flattened_commands = []
10+
) -> Tuple[Command, ...]:
11+
flattened_commands: List[Command] = []
1212
for command in commands:
1313
if isinstance(command, Command):
1414
flattened_commands.append(command)

commands2/wrappercommand.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def __init__(self, command: Command):
2626

2727
CommandScheduler.getInstance().registerComposedCommands([command])
2828
self._command = command
29+
self.setName(self._command.getName())
2930

3031
def initialize(self):
3132
"""The initial subroutine of a command. Called once when the command is initially scheduled."""

0 commit comments

Comments
 (0)