Skip to content

refactor: add type annotations to utils/image.py#1832

Open
wkentaro wants to merge 4 commits intomainfrom
refactor/image-utils-type-annotations
Open

refactor: add type annotations to utils/image.py#1832
wkentaro wants to merge 4 commits intomainfrom
refactor/image-utils-type-annotations

Conversation

@wkentaro
Copy link
Owner

@wkentaro wkentaro commented Mar 5, 2026

Summary

Add full type annotations to all 9 functions in labelme/utils/image.py. No logic changes.

Changes

New imports

  • from numpy.typing import NDArray
  • Optional from qtpy import QtGui (with ImportError fallback; used only for the img_qt_to_arr annotation)

Annotated functions

Function Signature
img_data_to_pil (bytes) -> PIL.Image.Image
img_data_to_arr (bytes) -> NDArray[np.uint8]
img_b64_to_arr (str) -> NDArray[np.uint8]
img_pil_to_data (PIL.Image.Image) -> bytes
img_arr_to_b64 (NDArray[np.uint8]) -> str
img_arr_to_data (NDArray[np.uint8]) -> bytes
img_data_to_png_data (bytes) -> bytes
img_qt_to_arr (QtGui.QImage) -> NDArray[np.uint8]
apply_exif_orientation (PIL.Image.Image) -> PIL.Image.Image

Add full type annotations to all 9 functions in labelme/utils/image.py:

- img_data_to_pil(bytes) -> PIL.Image.Image
- img_data_to_arr(bytes) -> NDArray[np.uint8]
- img_b64_to_arr(str) -> NDArray[np.uint8]
- img_pil_to_data(PIL.Image.Image) -> bytes
- img_arr_to_b64(NDArray[np.uint8]) -> str
- img_arr_to_data(NDArray[np.uint8]) -> bytes
- img_data_to_png_data(bytes) -> bytes
- img_qt_to_arr(QtGui.QImage) -> NDArray[np.uint8]
- apply_exif_orientation(PIL.Image.Image) -> PIL.Image.Image

Also add:
- from numpy.typing import NDArray import
- optional qtpy.QtGui import (with fallback for type annotation use only)

No logic changes.
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