Skip to content

Commit a088f5d

Browse files
authored
Fix typing of deprecated aliases (#44)
1 parent 0608bb8 commit a088f5d

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

commands2/__init__.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
from .waituntilcommand import WaitUntilCommand
4949
from .wrappercommand import WrapperCommand
5050

51+
from typing import TYPE_CHECKING
52+
5153
__all__ = [
5254
"cmd",
5355
"Command",
@@ -98,18 +100,21 @@
98100
"Trigger", # was here in 2023
99101
]
100102

103+
if not TYPE_CHECKING:
101104

102-
def __getattr__(attr):
103-
if attr == "SubsystemBase":
104-
import warnings
105+
def __getattr__(attr):
106+
if attr == "SubsystemBase":
107+
import warnings
105108

106-
warnings.warn("SubsystemBase is deprecated", DeprecationWarning, stacklevel=2)
107-
return Subsystem
109+
warnings.warn(
110+
"SubsystemBase is deprecated", DeprecationWarning, stacklevel=2
111+
)
112+
return Subsystem
108113

109-
if attr == "CommandBase":
110-
import warnings
114+
if attr == "CommandBase":
115+
import warnings
111116

112-
warnings.warn("CommandBase is deprecated", DeprecationWarning, stacklevel=2)
113-
return Command
117+
warnings.warn("CommandBase is deprecated", DeprecationWarning, stacklevel=2)
118+
return Command
114119

115-
raise AttributeError("module {!r} has no attribute " "{!r}".format(__name__, attr))
120+
raise AttributeError(f"module {__name__!r} has no attribute {attr!r}")

commands2/subsystem.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
from typing import TYPE_CHECKING, Callable, Optional
6+
from typing_extensions import Self
67

78
if TYPE_CHECKING:
89
from .command import Command
@@ -28,7 +29,7 @@ class Subsystem(Sendable):
2829
base for user implementations that handles this.
2930
"""
3031

31-
def __new__(cls, *arg, **kwargs) -> "Subsystem":
32+
def __new__(cls, *arg, **kwargs) -> Self:
3233
instance = super().__new__(cls)
3334
super().__init__(instance)
3435
SendableRegistry.addLW(instance, cls.__name__, cls.__name__)

0 commit comments

Comments
 (0)