Skip to content

Commit c782b47

Browse files
authored
Update pyscreeze methods reusing locateAll (#10741)
1 parent 6ed18ec commit c782b47

File tree

1 file changed

+28
-31
lines changed

1 file changed

+28
-31
lines changed

stubs/PyScreeze/pyscreeze/__init__.pyi

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from _typeshed import Incomplete, StrOrBytesPath, Unused
1+
from _typeshed import Incomplete, ReadableBuffer, StrOrBytesPath, Unused
22
from collections.abc import Callable, Generator
33
from typing import NamedTuple, SupportsFloat, TypeVar, overload
44
from typing_extensions import Final, ParamSpec, SupportsIndex, TypeAlias
@@ -7,13 +7,9 @@ from PIL import Image
77

88
_P = ParamSpec("_P")
99
_R = TypeVar("_R")
10-
# TODO: cv2.Mat is not available as a type yet:
11-
# https://github.com/microsoft/python-type-stubs/issues/211
12-
# https://github.com/microsoft/python-type-stubs/tree/main/cv2
13-
# https://github.com/opencv/opencv/pull/20370
14-
# cv2.Mat is just an alias for a numpy NDArray, but can't import that either.
15-
# Because pyscreeze does not declare it as a dependency, stub_uploader won't let it.
16-
_Mat: TypeAlias = Incomplete
10+
# cv2.typing.MatLike: is an alias for `numpy.ndarray | cv2.mat_wrapper.Mat`, Mat extends ndarray.
11+
# But can't import either, because pyscreeze does not declare them as dependencies, stub_uploader won't let it.
12+
_MatLike: TypeAlias = Incomplete
1713

1814
useOpenCV: Final[bool]
1915
RUNNING_PYTHON_2: Final = False
@@ -40,21 +36,22 @@ class RGB(NamedTuple):
4036
class PyScreezeException(Exception): ...
4137
class ImageNotFoundException(PyScreezeException): ...
4238

43-
# _locateAll_opencv
4439
def requiresPyGetWindow(wrappedFunction: Callable[_P, _R]) -> Callable[_P, _R]: ...
40+
41+
# _locateAll_opencv
4542
@overload
4643
def locate(
47-
needleImage: str | Image.Image | _Mat,
48-
haystackImage: str | Image.Image | _Mat,
44+
needleImage: str | Image.Image | _MatLike,
45+
haystackImage: str | Image.Image | _MatLike,
4946
*,
5047
grayscale: bool | None = None,
5148
limit: Unused = 1,
5249
region: tuple[int, int, int, int] | None = None,
5350
step: int = 1,
54-
confidence: SupportsFloat | SupportsIndex | str = 0.999,
51+
confidence: SupportsFloat | SupportsIndex | str | ReadableBuffer = 0.999,
5552
) -> Box | None: ...
5653

57-
# _locateAll_python / _locateAll_pillow
54+
# _locateAll_pillow
5855
@overload
5956
def locate(
6057
needleImage: str | Image.Image,
@@ -70,17 +67,17 @@ def locate(
7067
# _locateAll_opencv
7168
@overload
7269
def locateOnScreen(
73-
image: str | Image.Image | _Mat,
70+
image: str | Image.Image | _MatLike,
7471
minSearchTime: float = 0,
7572
*,
7673
grayscale: bool | None = None,
7774
limit: Unused = 1,
7875
region: tuple[int, int, int, int] | None = None,
7976
step: int = 1,
80-
confidence: SupportsFloat | SupportsIndex | str = 0.999,
77+
confidence: SupportsFloat | SupportsIndex | str | ReadableBuffer = 0.999,
8178
) -> Box | None: ...
8279

83-
# _locateAll_python / _locateAll_pillow
80+
# _locateAll_pillow
8481
@overload
8582
def locateOnScreen(
8683
image: str | Image.Image,
@@ -96,16 +93,16 @@ def locateOnScreen(
9693
# _locateAll_opencv
9794
@overload
9895
def locateAllOnScreen(
99-
image: str | Image.Image | _Mat,
96+
image: str | Image.Image | _MatLike,
10097
*,
10198
grayscale: bool | None = None,
10299
limit: int = 1000,
103100
region: tuple[int, int, int, int] | None = None,
104101
step: int = 1,
105-
confidence: SupportsFloat | SupportsIndex | str = 0.999,
102+
confidence: SupportsFloat | SupportsIndex | str | ReadableBuffer = 0.999,
106103
) -> Generator[Box, None, None]: ...
107104

108-
# _locateAll_python / _locateAll_pillow
105+
# _locateAll_pillow
109106
@overload
110107
def locateAllOnScreen(
111108
image: str | Image.Image,
@@ -120,17 +117,17 @@ def locateAllOnScreen(
120117
# _locateAll_opencv
121118
@overload
122119
def locateCenterOnScreen(
123-
image: str | Image.Image | _Mat,
120+
image: str | Image.Image | _MatLike,
124121
*,
125122
minSearchTime: float,
126123
grayscale: bool | None = None,
127124
limit: Unused = 1,
128125
region: tuple[int, int, int, int] | None = None,
129126
step: int = 1,
130-
confidence: SupportsFloat | SupportsIndex | str = 0.999,
127+
confidence: SupportsFloat | SupportsIndex | str | ReadableBuffer = 0.999,
131128
) -> Point | None: ...
132129

133-
# _locateAll_python / _locateAll_pillow
130+
# _locateAll_pillow
134131
@overload
135132
def locateCenterOnScreen(
136133
image: str | Image.Image,
@@ -142,22 +139,22 @@ def locateCenterOnScreen(
142139
step: int = 1,
143140
confidence: None = None,
144141
) -> Point | None: ...
145-
def locateOnScreenNear(image: str | Image.Image | _Mat, x: int, y: int) -> Box: ...
146-
def locateCenterOnScreenNear(image: str | Image.Image | _Mat, x: int, y: int) -> Point | None: ...
142+
def locateOnScreenNear(image: str | Image.Image | _MatLike, x: int, y: int) -> Box: ...
143+
def locateCenterOnScreenNear(image: str | Image.Image | _MatLike, x: int, y: int) -> Point | None: ...
147144

148145
# _locateAll_opencv
149146
@overload
150147
def locateOnWindow(
151-
image: str | Image.Image | _Mat,
148+
image: str | Image.Image | _MatLike,
152149
title: str,
153150
*,
154151
grayscale: bool | None = None,
155152
limit: Unused = 1,
156153
step: int = 1,
157-
confidence: SupportsFloat | SupportsIndex | str = 0.999,
154+
confidence: SupportsFloat | SupportsIndex | str | ReadableBuffer = 0.999,
158155
) -> Box | None: ...
159156

160-
# _locateAll_python / _locateAll_pillow
157+
# _locateAll_pillow
161158
@overload
162159
def locateOnWindow(
163160
image: str | Image.Image,
@@ -181,16 +178,16 @@ def screenshot(imageFilename: StrOrBytesPath | None = None, region: tuple[int, i
181178
# _locateAll_opencv
182179
@overload
183180
def locateAll(
184-
needleImage: str | Image.Image | _Mat,
185-
haystackImage: str | Image.Image | _Mat,
181+
needleImage: str | Image.Image | _MatLike,
182+
haystackImage: str | Image.Image | _MatLike,
186183
grayscale: bool | None = None,
187184
limit: int = 1000,
188185
region: tuple[int, int, int, int] | None = None,
189186
step: int = 1,
190-
confidence: SupportsFloat | SupportsIndex | str = 0.999,
187+
confidence: SupportsFloat | SupportsIndex | str | ReadableBuffer = 0.999,
191188
) -> Generator[Box, None, None]: ...
192189

193-
# _locateAll_python / _locateAll_pillow
190+
# _locateAll_pillow
194191
@overload
195192
def locateAll(
196193
needleImage: str | Image.Image,

0 commit comments

Comments
 (0)