Skip to content

Commit ba0e8fd

Browse files
committed
tunable: Make mypy happier with type narrowing
1 parent 7c77488 commit ba0e8fd

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

magicbot/magic_tunable.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,13 @@ def __init__(
104104
# Defer checks for empty sequences to check type hints.
105105
# Report errors here when we can so the error points to the tunable line.
106106
if default or not isinstance(default, collections.abc.Sequence):
107-
self._topic_type = _get_topic_type_for_value(default)
108-
if self._topic_type is None:
107+
topic_type = _get_topic_type_for_value(default)
108+
if topic_type is None:
109109
checked_type: type = type(default)
110110
raise TypeError(
111111
f"tunable is not publishable to NetworkTables, type: {checked_type.__name__}"
112112
)
113+
self._topic_type = topic_type
113114

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

0 commit comments

Comments
 (0)