Skip to content

Commit 8eaf5ff

Browse files
committed
magicbot: Add type-hinted feedback struct support
1 parent 4f2427a commit 8eaf5ff

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

magicbot/magic_tunable.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import collections.abc
12
import functools
23
import inspect
34
import typing
@@ -244,6 +245,8 @@ def _get_topic_type(
244245
) -> Optional[Callable[[ntcore.Topic], typing.Any]]:
245246
if return_annotation in _topic_types:
246247
return _topic_types[return_annotation]
248+
if hasattr(return_annotation, "WPIStruct"):
249+
return lambda topic: ntcore.StructTopic(topic, return_annotation)
247250

248251
# Check for PEP 484 generic types
249252
origin = getattr(return_annotation, "__origin__", None)
@@ -256,6 +259,8 @@ def _get_topic_type(
256259
inner_type = args[0]
257260
if inner_type in _array_topic_types:
258261
return _array_topic_types[inner_type]
262+
if hasattr(inner_type, "WPIStruct"):
263+
return lambda topic: ntcore.StructArrayTopic(topic, inner_type)
259264

260265

261266
def collect_feedbacks(component, cname: str, prefix: Optional[str] = "components"):

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ zip_safe = False
2424
include_package_data = True
2525
packages = find:
2626
install_requires =
27-
wpilib>=2024.1.1.0,<2025
27+
wpilib>=2024.3.2.1,<2025
2828
setup_requires =
2929
setuptools_scm > 6
3030
python_requires = >=3.8

0 commit comments

Comments
 (0)