From a088f5d22bcd8a9761353d3e500403daa42df33f Mon Sep 17 00:00:00 2001 From: Vasista Vovveti Date: Thu, 18 Jan 2024 01:55:03 -0800 Subject: [PATCH] Fix typing of deprecated aliases (#44) --- commands2/__init__.py | 25 +++++++++++++++---------- commands2/subsystem.py | 3 ++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/commands2/__init__.py b/commands2/__init__.py index 4d9c2e8c..18b310d7 100644 --- a/commands2/__init__.py +++ b/commands2/__init__.py @@ -48,6 +48,8 @@ from .waituntilcommand import WaitUntilCommand from .wrappercommand import WrapperCommand +from typing import TYPE_CHECKING + __all__ = [ "cmd", "Command", @@ -98,18 +100,21 @@ "Trigger", # was here in 2023 ] +if not TYPE_CHECKING: -def __getattr__(attr): - if attr == "SubsystemBase": - import warnings + def __getattr__(attr): + if attr == "SubsystemBase": + import warnings - warnings.warn("SubsystemBase is deprecated", DeprecationWarning, stacklevel=2) - return Subsystem + warnings.warn( + "SubsystemBase is deprecated", DeprecationWarning, stacklevel=2 + ) + return Subsystem - if attr == "CommandBase": - import warnings + if attr == "CommandBase": + import warnings - warnings.warn("CommandBase is deprecated", DeprecationWarning, stacklevel=2) - return Command + warnings.warn("CommandBase is deprecated", DeprecationWarning, stacklevel=2) + return Command - raise AttributeError("module {!r} has no attribute " "{!r}".format(__name__, attr)) + raise AttributeError(f"module {__name__!r} has no attribute {attr!r}") diff --git a/commands2/subsystem.py b/commands2/subsystem.py index a3ba81ca..56724ebd 100644 --- a/commands2/subsystem.py +++ b/commands2/subsystem.py @@ -3,6 +3,7 @@ from __future__ import annotations from typing import TYPE_CHECKING, Callable, Optional +from typing_extensions import Self if TYPE_CHECKING: from .command import Command @@ -28,7 +29,7 @@ class Subsystem(Sendable): base for user implementations that handles this. """ - def __new__(cls, *arg, **kwargs) -> "Subsystem": + def __new__(cls, *arg, **kwargs) -> Self: instance = super().__new__(cls) super().__init__(instance) SendableRegistry.addLW(instance, cls.__name__, cls.__name__)