Skip to content

Commit

Permalink
Fix typing of deprecated aliases (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTripleV committed Jan 18, 2024
1 parent 0608bb8 commit a088f5d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
25 changes: 15 additions & 10 deletions commands2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
from .waituntilcommand import WaitUntilCommand
from .wrappercommand import WrapperCommand

from typing import TYPE_CHECKING

__all__ = [
"cmd",
"Command",
Expand Down Expand Up @@ -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}")
3 changes: 2 additions & 1 deletion commands2/subsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__)
Expand Down

0 comments on commit a088f5d

Please sign in to comment.