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

Fix typing of deprecated aliases #44

Merged
merged 6 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 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,23 @@
"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(
"module {!r} has no attribute " "{!r}".format(__name__, attr)
TheTripleV marked this conversation as resolved.
Show resolved Hide resolved
)
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