From 0a52d98ceef07aa87737bed946616817a10a46e4 Mon Sep 17 00:00:00 2001 From: Dustin Spicuzza Date: Tue, 5 Dec 2023 03:31:55 -0500 Subject: [PATCH 1/4] Add mypy checking to CI --- .github/workflows/dist.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/dist.yml b/.github/workflows/dist.yml index fc3d05b1..38cb4b91 100644 --- a/.github/workflows/dist.yml +++ b/.github/workflows/dist.yml @@ -17,3 +17,18 @@ jobs: secrets: META_REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} PYPI_API_TOKEN: ${{ secrets.PYPI_PASSWORD }} + + check-mypy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.12" + - name: Install requirements + run: | + pip --disable-pip-version-check install mypy setuptools wheel setuptools_scm + pip --disable-pip-version-check install --no-build-isolation -e . + - name: Run mypy + run: | + mypy commands2 \ No newline at end of file From 1025dfea4bb305dd1ae19ea096f970e6cd155daa Mon Sep 17 00:00:00 2001 From: Dustin Spicuzza Date: Tue, 5 Dec 2023 03:35:41 -0500 Subject: [PATCH 2/4] Fix mypy errors --- commands2/button/commandjoystick.py | 2 ++ commands2/button/commandps4controller.py | 2 ++ commands2/button/commandxboxcontroller.py | 2 ++ commands2/command.py | 6 ++++-- commands2/commandscheduler.py | 4 ++-- commands2/util.py | 6 +++--- commands2/wrappercommand.py | 1 + 7 files changed, 16 insertions(+), 7 deletions(-) diff --git a/commands2/button/commandjoystick.py b/commands2/button/commandjoystick.py index cdb84340..f5f28c51 100644 --- a/commands2/button/commandjoystick.py +++ b/commands2/button/commandjoystick.py @@ -13,6 +13,8 @@ class CommandJoystick(CommandGenericHID): A version of Joystick with Trigger factories for command-based. """ + _hid: Joystick + def __init__(self, port: int): """ Construct an instance of a controller. diff --git a/commands2/button/commandps4controller.py b/commands2/button/commandps4controller.py index 567ecf33..9b2da01d 100644 --- a/commands2/button/commandps4controller.py +++ b/commands2/button/commandps4controller.py @@ -13,6 +13,8 @@ class CommandPS4Controller(CommandGenericHID): A version of PS4Controller with Trigger factories for command-based. """ + _hid: PS4Controller + def __init__(self, port: int): """ Construct an instance of a device. diff --git a/commands2/button/commandxboxcontroller.py b/commands2/button/commandxboxcontroller.py index 50428d2d..2c613f4b 100644 --- a/commands2/button/commandxboxcontroller.py +++ b/commands2/button/commandxboxcontroller.py @@ -13,6 +13,8 @@ class CommandXboxController(CommandGenericHID): A version of XboxController with Trigger factories for command-based. """ + _hid: XboxController + def __init__(self, port: int): """ Construct an instance of a controller. diff --git a/commands2/command.py b/commands2/command.py index 39afad12..6c127adb 100644 --- a/commands2/command.py +++ b/commands2/command.py @@ -6,7 +6,7 @@ from enum import Enum from typing import TYPE_CHECKING, Any, Callable, Set -from typing_extensions import Self +from typing_extensions import Self, TypeAlias if TYPE_CHECKING: from .instantcommand import InstantCommand @@ -54,7 +54,9 @@ class Command(Sendable): This class is provided by the NewCommands VendorDep """ - InterruptionBehavior = InterruptionBehavior # type alias for 2023 location + InterruptionBehavior: TypeAlias = ( + InterruptionBehavior # type alias for 2023 location + ) requirements: Set[Subsystem] diff --git a/commands2/commandscheduler.py b/commands2/commandscheduler.py index fa7b41e7..ef51150c 100644 --- a/commands2/commandscheduler.py +++ b/commands2/commandscheduler.py @@ -21,9 +21,9 @@ class CommandScheduler: methods to be called and for their default commands to be scheduled. """ - _instance: Optional[Self] = None + _instance: Optional[CommandScheduler] = None - def __new__(cls) -> Self: + def __new__(cls) -> CommandScheduler: if cls._instance is None: return super().__new__(cls) return cls._instance diff --git a/commands2/util.py b/commands2/util.py index d60da8c2..617a5762 100644 --- a/commands2/util.py +++ b/commands2/util.py @@ -1,14 +1,14 @@ from __future__ import annotations -from typing import Iterable, Tuple, Union +from typing import Iterable, List, Tuple, Union from .command import Command def flatten_args_commands( *commands: Union[Command, Iterable[Command]] -) -> Tuple[Command]: - flattened_commands = [] +) -> Tuple[Command, ...]: + flattened_commands: List[Command] = [] for command in commands: if isinstance(command, Command): flattened_commands.append(command) diff --git a/commands2/wrappercommand.py b/commands2/wrappercommand.py index c61ffe60..43c50372 100644 --- a/commands2/wrappercommand.py +++ b/commands2/wrappercommand.py @@ -26,6 +26,7 @@ def __init__(self, command: Command): CommandScheduler.getInstance().registerComposedCommands([command]) self._command = command + self.setName(self._command.getName()) def initialize(self): """The initial subroutine of a command. Called once when the command is initially scheduled.""" From d829e4c8c8c208ca0ecdd7bd157824e3a74c80f5 Mon Sep 17 00:00:00 2001 From: Dustin Spicuzza Date: Tue, 5 Dec 2023 05:27:16 -0500 Subject: [PATCH 3/4] Fix Command __new__ initialization order --- commands2/command.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands2/command.py b/commands2/command.py index 6c127adb..e8b0546f 100644 --- a/commands2/command.py +++ b/commands2/command.py @@ -64,9 +64,9 @@ def __new__(cls, *args, **kwargs) -> Self: instance = super().__new__( cls, ) - instance.requirements = set() - SendableRegistry.add(instance, cls.__name__) super().__init__(instance) + SendableRegistry.add(instance, cls.__name__) + instance.requirements = set() return instance def __init__(self): From 5544c62245f0834f36e81254341a053d24ef6469 Mon Sep 17 00:00:00 2001 From: Dustin Spicuzza Date: Tue, 5 Dec 2023 05:33:11 -0500 Subject: [PATCH 4/4] Update github actions --- .github/workflows/dist.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dist.yml b/.github/workflows/dist.yml index 38cb4b91..b71c239e 100644 --- a/.github/workflows/dist.yml +++ b/.github/workflows/dist.yml @@ -11,7 +11,7 @@ on: jobs: ci: - uses: robotpy/build-actions/.github/workflows/package-pure.yml@v2024-alpha + uses: robotpy/build-actions/.github/workflows/package-pure.yml@v2024 with: enable_sphinx_check: false secrets: