Skip to content

Fix TeleImage.__iter__ yielding fields in the wrong order - #13

Open
winklemad wants to merge 1 commit into
unitreerobotics:mainfrom
winklemad:fix/teleimage-iter-order
Open

winklemad wants to merge 1 commit into
unitreerobotics:mainfrom
winklemad:fix/teleimage-iter-order

Conversation

@winklemad

Copy link
Copy Markdown

Problem

TeleImage.__iter__ documents tuple-unpacking as:

""" Allow unpacking like: jpg, bgr, fps = teleimage_instance """

but yields the fields in a different order:

def __iter__(self):
    """ Allow unpacking like: jpg, bgr, fps = teleimage_instance """
    yield self.fps
    yield self.jpg
    yield (None if self._bgr is TeleImage._NOT_SET else self._bgr)

So a user who follows the documented usage gets every value bound to the wrong field:

img = TeleImage(fps=30.0, jpg=b"...", bgr=some_ndarray)
jpg, bgr, fps = img
# jpg -> 30.0            (the fps float)
# bgr -> b"..."          (the jpg bytes)
# fps -> some_ndarray    (the decoded image)

Fix

Yield jpg, bgr, fps so __iter__ matches its own docstring. This also matches the field order declared in __slots__ = ['jpg', '_bgr', 'fps']; the previous order followed the __init__ parameter order (fps, jpg, bgr) instead.

def __iter__(self):
    """ Allow unpacking like: jpg, bgr, fps = teleimage_instance """
    yield self.jpg
    yield (None if self._bgr is TeleImage._NOT_SET else self._bgr)
    yield self.fps

After the change, jpg, bgr, fps = img binds each name correctly.

If the intended contract was actually fps, jpg, bgr, the alternative fix would be to update the docstring instead — happy to switch to that if you prefer, but the __slots__ order suggests jpg, bgr, fps was intended.

TeleImage.__iter__ documents unpacking as `jpg, bgr, fps = teleimage_instance`
but yielded fps, jpg, bgr. Following the documented order therefore bound
every variable to the wrong value (jpg got the fps float, bgr got the jpg
bytes, fps got the decoded image). Yield jpg, bgr, fps to match the
docstring and the __slots__ order ['jpg', '_bgr', 'fps'].
@winklemad
winklemad force-pushed the fix/teleimage-iter-order branch from ad50b1c to aa21be3 Compare September 4, 2026 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant