Skip to content

refactor: add type annotations to Shape.__init__ and key methods#1836

Open
wkentaro wants to merge 3 commits intomainfrom
refactor/shape-type-annotations
Open

refactor: add type annotations to Shape.__init__ and key methods#1836
wkentaro wants to merge 3 commits intomainfrom
refactor/shape-type-annotations

Conversation

@wkentaro
Copy link
Owner

@wkentaro wkentaro commented Mar 5, 2026

Summary

Add type annotations to Shape.__init__ and key methods in labelme/shape.py. No logic changes.

Changes

  • __init__: annotated all parameters (label, line_color, shape_type, flags, group_id, description, mask) with proper Optional types
  • setShapeRefined: annotated shape_type: str, points: list[QtCore.QPointF], point_labels: list[int], mask: Optional[NDArray[np.bool_]]
  • addPoint: annotated point: QtCore.QPointF, label: int
  • insertPoint: annotated i: int, point: QtCore.QPointF, label: int
  • nearestVertex: annotated point: QtCore.QPointF, epsilon: floatOptional[int]
  • nearestEdge: annotated point: QtCore.QPointF, epsilon: floatOptional[int]
  • Added from typing import Optional and from numpy.typing import NDArray

Part of the ongoing type annotation effort (#1832, #1833).

Thomas (wkentaro agent) and others added 3 commits March 6, 2026 04:01
- Add Optional[str] to label, shape_type, description
- Add Optional[QtGui.QColor] to line_color
- Add Optional[dict[str, bool]] to flags
- Add Optional[int] to group_id
- Add Optional[NDArray[np.bool_]] to mask
- Add type annotations to addPoint, insertPoint, setShapeRefined
- Add type annotations to nearestVertex, nearestEdge (return Optional[int])
- Import Optional from typing, NDArray from numpy.typing

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