Skip to content

Commit f469977

Browse files
authored
Merge pull request #161 from robotpy/warn-sensors
Warn about moved sensors classes
2 parents 1cf768c + 439839c commit f469977

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

ctre/__init__.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,19 @@
196196

197197
from .version import version as __version__
198198

199+
199200
# backwards compat
200201
# TODO: remove in 2024
201-
from .sensors import *
202+
def __getattr__(name):
203+
if name != "sensors":
204+
from .sensors import __all__ as sensors_all
205+
206+
if name in sensors_all:
207+
import warnings
208+
from . import sensors
209+
210+
message = f"{__name__}.{name} has moved to {__name__}.sensors"
211+
warnings.warn(message, FutureWarning, stacklevel=2)
212+
return getattr(sensors, name)
213+
214+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

tests/test_sensors.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pytest
2+
3+
import ctre.sensors
4+
5+
6+
def test_cancoder():
7+
enc = ctre.sensors.CANCoder(0)
8+
enc.getPosition()
9+
10+
11+
def test_deprecated_import():
12+
with pytest.warns(FutureWarning, match="moved"):
13+
from ctre import CANCoder
14+
15+
assert CANCoder is ctre.sensors.CANCoder

0 commit comments

Comments
 (0)