diff --git a/stubs/pycocotools/METADATA.toml b/stubs/pycocotools/METADATA.toml index 424bb5bd8834..c0b37187dc44 100644 --- a/stubs/pycocotools/METADATA.toml +++ b/stubs/pycocotools/METADATA.toml @@ -1,4 +1,6 @@ version = "2.0.*" +# requires a version of numpy with a `py.typed` file +requires = ["numpy>=1.20"] [tool.stubtest] ignore_missing_stub = false diff --git a/stubs/pycocotools/pycocotools/coco.pyi b/stubs/pycocotools/pycocotools/coco.pyi index 1cb93c63f2e9..0087ba6a6012 100644 --- a/stubs/pycocotools/pycocotools/coco.pyi +++ b/stubs/pycocotools/pycocotools/coco.pyi @@ -4,14 +4,12 @@ from pathlib import Path from typing import Generic, TypeVar, overload from typing_extensions import Literal, TypeAlias, TypedDict -from . import _EncodedRLE +import numpy +import numpy.typing -# TODO: Use numpy types when #5768 is resolved. -# import numpy as np -# import numpy.typing as npt +from . import _EncodedRLE PYTHON_VERSION: Incomplete -_NDArray: TypeAlias = Incomplete class _Image(TypedDict): id: int @@ -82,13 +80,11 @@ class COCO: def showAnns(self, anns: Sequence[_Annotation], draw_bbox: bool = ...) -> None: ... def loadRes(self, resFile: str) -> COCO: ... def download(self, tarDir: str | None = ..., imgIds: Collection[int] = ...) -> Literal[-1] | None: ... - def loadNumpyAnnotations(self, data: _NDArray) -> list[_Annotation]: ... - # def loadNumpyAnnotations(self, data: npt.NDArray[np.float64]) -> list[_Annotation]: ... + def loadNumpyAnnotations(self, data: numpy.typing.NDArray[numpy.float64]) -> list[_Annotation]: ... @overload def annToRLE(self, ann: _AnnotationG[_RLE]) -> _RLE: ... @overload def annToRLE(self, ann: _AnnotationG[_EncodedRLE]) -> _EncodedRLE: ... @overload def annToRLE(self, ann: _AnnotationG[_TPolygonSegmentation]) -> _EncodedRLE: ... - def annToMask(self, ann: _Annotation) -> _NDArray: ... - # def annToMask(self, ann: _Annotation) -> npt.NDArray[np.uint8]: ... + def annToMask(self, ann: _Annotation) -> numpy.typing.NDArray[numpy.uint8]: ... diff --git a/stubs/pycocotools/pycocotools/cocoeval.pyi b/stubs/pycocotools/pycocotools/cocoeval.pyi index d9845c6cb712..b7d7a2f3730e 100644 --- a/stubs/pycocotools/pycocotools/cocoeval.pyi +++ b/stubs/pycocotools/pycocotools/cocoeval.pyi @@ -1,13 +1,10 @@ -from _typeshed import Incomplete from typing_extensions import Literal, TypeAlias, TypedDict -from .coco import COCO +import numpy +import numpy.typing -# TODO: Use numpy types when #5768 is resolved. -# import numpy as np -# import numpy.typing as npt +from .coco import COCO -_NDArray: TypeAlias = Incomplete _TIOU: TypeAlias = Literal["segm", "bbox", "keypoints"] class _EvaluationResult(TypedDict): @@ -17,15 +14,11 @@ class _EvaluationResult(TypedDict): maxDet: int dtIds: list[int] gtIds: list[int] - dtMatches: _NDArray - # dtMatches: npt.NDArray[np.float64] - gtMatches: _NDArray - # gtMatches: npt.NDArray[np.float64] + dtMatches: numpy.typing.NDArray[numpy.float64] + gtMatches: numpy.typing.NDArray[numpy.float64] dtScores: list[float] - gtIgnore: _NDArray - # gtIgnore: npt.NDArray[np.float64] - dtIgnore: _NDArray - # dtIgnore: npt.NDArray[np.float64] + gtIgnore: numpy.typing.NDArray[numpy.float64] + dtIgnore: numpy.typing.NDArray[numpy.float64] class COCOeval: cocoGt: COCO @@ -33,14 +26,12 @@ class COCOeval: evalImgs: list[_EvaluationResult] eval: _EvaluationResult params: Params - stats: _NDArray - # stats: npt.NDArray[np.float64] + stats: numpy.typing.NDArray[numpy.float64] ious: dict[tuple[int, int], list[float]] def __init__(self, cocoGt: COCO | None = ..., cocoDt: COCO | None = ..., iouType: _TIOU = ...) -> None: ... def evaluate(self) -> None: ... def computeIoU(self, imgId: int, catId: int) -> list[float]: ... - def computeOks(self, imgId: int, catId: int) -> _NDArray: ... - # def computeOks(self, imgId: int, catId: int) -> npt.NDArray[np.float64]: ... + def computeOks(self, imgId: int, catId: int) -> numpy.typing.NDArray[numpy.float64]: ... def evaluateImg(self, imgId: int, catId: int, aRng: list[int], maxDet: int) -> _EvaluationResult: ... def accumulate(self, p: Params | None = ...) -> None: ... def summarize(self) -> None: ... @@ -48,16 +39,13 @@ class COCOeval: class Params: imgIds: list[int] catIds: list[int] - iouThrs: _NDArray - # iouThrs: npt.NDArray[np.float64] - recThrs: _NDArray - # recThrs: npt.NDArray[np.float64] + iouThrs: numpy.typing.NDArray[numpy.float64] + recThrs: numpy.typing.NDArray[numpy.float64] maxDets: list[int] areaRng: list[int] areaRngLbl: list[str] useCats: int - kpt_oks_sigmas: _NDArray - # kpt_oks_sigmas: npt.NDArray[np.float64] + kpt_oks_sigmas: numpy.typing.NDArray[numpy.float64] iouType: _TIOU useSegm: int | None def __init__(self, iouType: _TIOU = ...) -> None: ... diff --git a/stubs/pycocotools/pycocotools/mask.pyi b/stubs/pycocotools/pycocotools/mask.pyi index 07d30d6624b9..cfdf6edb84e3 100644 --- a/stubs/pycocotools/pycocotools/mask.pyi +++ b/stubs/pycocotools/pycocotools/mask.pyi @@ -1,31 +1,22 @@ -from _typeshed import Incomplete from typing import Any, overload -from typing_extensions import TypeAlias -from . import _EncodedRLE - -# TODO: Use numpy types when #5768 is resolved. -# import numpy as np -# import numpy.typing as npt +import numpy -_NPUInt32: TypeAlias = Incomplete # np.uint32 -_NDArrayUInt8: TypeAlias = Incomplete # npt.NDArray[np.uint8] -_NDArrayUInt32: TypeAlias = Incomplete # npt.NDArray[np.uint32] -_NDArrayFloat64: TypeAlias = Incomplete # npt.NDArray[np.float64] +from . import _EncodedRLE def iou( - dt: _NDArrayUInt32 | list[float] | list[_EncodedRLE], - gt: _NDArrayUInt32 | list[float] | list[_EncodedRLE], - pyiscrowd: list[int] | _NDArrayUInt8, -) -> list[Any] | _NDArrayFloat64: ... + dt: numpy.typing.NDArray[numpy.uint32] | list[float] | list[_EncodedRLE], + gt: numpy.typing.NDArray[numpy.uint32] | list[float] | list[_EncodedRLE], + pyiscrowd: list[int] | numpy.typing.NDArray[numpy.uint8], +) -> list[Any] | numpy.typing.NDArray[numpy.float64]: ... def merge(rleObjs: list[_EncodedRLE], intersect: int = ...) -> _EncodedRLE: ... - -# ignore an "overlapping overloads" error due to _NDArrayInt32 being an alias for `Incomplete` for now @overload -def frPyObjects(pyobj: _NDArrayUInt32 | list[list[int]] | list[_EncodedRLE], h: int, w: int) -> list[_EncodedRLE]: ... # type: ignore[misc] +def frPyObjects( + pyobj: numpy.typing.NDArray[numpy.uint32] | list[list[int]] | list[_EncodedRLE], h: int, w: int +) -> list[_EncodedRLE]: ... @overload def frPyObjects(pyobj: list[int] | _EncodedRLE, h: int, w: int) -> _EncodedRLE: ... -def encode(bimask: _NDArrayUInt8) -> _EncodedRLE: ... -def decode(rleObjs: _EncodedRLE) -> _NDArrayUInt8: ... -def area(rleObjs: _EncodedRLE) -> _NPUInt32: ... -def toBbox(rleObjs: _EncodedRLE) -> _NDArrayFloat64: ... +def encode(bimask: numpy.typing.NDArray[numpy.uint8]) -> _EncodedRLE: ... +def decode(rleObjs: _EncodedRLE) -> numpy.typing.NDArray[numpy.uint8]: ... +def area(rleObjs: _EncodedRLE) -> numpy.uint32: ... +def toBbox(rleObjs: _EncodedRLE) -> numpy.typing.NDArray[numpy.float64]: ...