Skip to content

Commit

Permalink
Merge pull request #161 from robotpy/warn-sensors
Browse files Browse the repository at this point in the history
Warn about moved sensors classes
  • Loading branch information
auscompgeek authored Feb 18, 2023
2 parents 1cf768c + 439839c commit f469977
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
15 changes: 14 additions & 1 deletion ctre/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,19 @@

from .version import version as __version__


# backwards compat
# TODO: remove in 2024
from .sensors import *
def __getattr__(name):
if name != "sensors":
from .sensors import __all__ as sensors_all

if name in sensors_all:
import warnings
from . import sensors

message = f"{__name__}.{name} has moved to {__name__}.sensors"
warnings.warn(message, FutureWarning, stacklevel=2)
return getattr(sensors, name)

raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
15 changes: 15 additions & 0 deletions tests/test_sensors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest

import ctre.sensors


def test_cancoder():
enc = ctre.sensors.CANCoder(0)
enc.getPosition()


def test_deprecated_import():
with pytest.warns(FutureWarning, match="moved"):
from ctre import CANCoder

assert CANCoder is ctre.sensors.CANCoder

0 comments on commit f469977

Please sign in to comment.