Skip to content

Commit

Permalink
tunable: Make mypy happier with type narrowing
Browse files Browse the repository at this point in the history
  • Loading branch information
auscompgeek committed Oct 19, 2024
1 parent 7c77488 commit ba0e8fd
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions magicbot/magic_tunable.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ def __init__(
# Defer checks for empty sequences to check type hints.
# Report errors here when we can so the error points to the tunable line.
if default or not isinstance(default, collections.abc.Sequence):
self._topic_type = _get_topic_type_for_value(default)
if self._topic_type is None:
topic_type = _get_topic_type_for_value(default)
if topic_type is None:
checked_type: type = type(default)
raise TypeError(
f"tunable is not publishable to NetworkTables, type: {checked_type.__name__}"
)
self._topic_type = topic_type

def __set_name__(self, owner: type, name: str) -> None:
type_hint: Optional[type] = None
Expand Down

0 comments on commit ba0e8fd

Please sign in to comment.