From 8c2613f098a340d9740a2cd1335ec36bcd445413 Mon Sep 17 00:00:00 2001 From: Avasam Date: Fri, 13 Jan 2023 21:58:43 -0500 Subject: [PATCH 1/2] Update numpy and 5768 comments --- stubs/D3DShot/d3dshot/capture_output.pyi | 4 +--- .../d3dshot/capture_outputs/numpy_capture_output.pyi | 3 +-- .../d3dshot/capture_outputs/numpy_float_capture_output.pyi | 4 ++-- .../d3dshot/capture_outputs/pytorch_capture_output.pyi | 3 +-- stubs/D3DShot/d3dshot/dll/__init__.pyi | 4 ++-- stubs/PyScreeze/pyscreeze/__init__.pyi | 7 ++++++- stubs/pycocotools/pycocotools/coco.pyi | 2 +- stubs/pycocotools/pycocotools/cocoeval.pyi | 2 +- stubs/pycocotools/pycocotools/mask.pyi | 2 +- .../PyInstaller/lib/modulegraph/modulegraph.pyi | 6 ++++-- tests/mypy_test.py | 2 +- 11 files changed, 21 insertions(+), 18 deletions(-) diff --git a/stubs/D3DShot/d3dshot/capture_output.pyi b/stubs/D3DShot/d3dshot/capture_output.pyi index aa68b092eb20..0fc75136e09d 100644 --- a/stubs/D3DShot/d3dshot/capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_output.pyi @@ -7,10 +7,8 @@ from typing_extensions import Literal, TypeAlias from PIL import Image _Frame: TypeAlias = Image.Image | Incomplete -# TODO: Complete types once we can import non-types dependencies -# See: #5768 +# stub_uploader doesn't allow numpy and torch because D3DShot doesn't declare it as a dependency # from torch import Tensor -# from comtypes import IUnknown # import numpy.typing as npt # _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | Tensor diff --git a/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi index 083eeb798560..0aec1bc85fd3 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi @@ -6,8 +6,7 @@ from typing_extensions import Literal, TypeAlias from d3dshot.capture_output import CaptureOutput from PIL import Image -# TODO: Complete types once we can import non-types dependencies -# See: #5768 +# stub_uploader doesn't allow numpy because D3DShot doesn't declare it as a dependency # import numpy as np # import numpy.typing as npt # _NDArray: TypeAlias = npt.NDArray[np.int32] diff --git a/stubs/D3DShot/d3dshot/capture_outputs/numpy_float_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/numpy_float_capture_output.pyi index 49d4e5d7ea75..2bf3331d48e5 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/numpy_float_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/numpy_float_capture_output.pyi @@ -1,5 +1,5 @@ from d3dshot.capture_outputs.numpy_capture_output import NumpyCaptureOutput -# TODO: Once we can import non-types dependencies, this CaptureOutput should be float based -# See: #5768 +# stub_uploader doesn't allow numpy because D3DShot doesn't declare it as a dependency +# this CaptureOutput should be float based class NumpyFloatCaptureOutput(NumpyCaptureOutput): ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi index 4498bd52f01a..9fc7df7e37c8 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi @@ -6,8 +6,7 @@ from typing_extensions import Literal, TypeAlias from d3dshot.capture_output import CaptureOutput from PIL import Image -# TODO: Complete types once we can import non-types dependencies -# See: https://github.com/python/typeshed/issues/5768 +# stub_uploader doesn't allow torch because D3DShot doesn't declare it as a dependency # from torch import Tensor _Tensor: TypeAlias = Incomplete diff --git a/stubs/D3DShot/d3dshot/dll/__init__.pyi b/stubs/D3DShot/d3dshot/dll/__init__.pyi index 56e0e35b58ae..82dc9b18bfa1 100644 --- a/stubs/D3DShot/d3dshot/dll/__init__.pyi +++ b/stubs/D3DShot/d3dshot/dll/__init__.pyi @@ -20,8 +20,8 @@ if sys.platform == "win32": else: _HRESULT: TypeAlias = Incomplete -# TODO: Use comtypes.IUnknown once we can import non-types dependencies -# See: #5768 +# comtypes is not typed +# from comtypes import IUnknown class _IUnknown(_CData): def QueryInterface(self, interface: type, iid: _CData | None = ...) -> _HRESULT: ... def AddRef(self) -> c_ulong: ... diff --git a/stubs/PyScreeze/pyscreeze/__init__.pyi b/stubs/PyScreeze/pyscreeze/__init__.pyi index 10bf651c0d08..6272d9ace6f1 100644 --- a/stubs/PyScreeze/pyscreeze/__init__.pyi +++ b/stubs/PyScreeze/pyscreeze/__init__.pyi @@ -9,8 +9,12 @@ from PIL import Image _Unused: TypeAlias = object _P = ParamSpec("_P") _R = TypeVar("_R") -# TODO: cv2.Mat is not available as a type yet: https://github.com/microsoft/python-type-stubs/issues/211 +# TODO: cv2.Mat is not available as a type yet: +# https://github.com/microsoft/python-type-stubs/issues/211 +# https://github.com/microsoft/python-type-stubs/tree/main/cv2 +# https://github.com/opencv/opencv/pull/20370 # cv2.Mat is just an alias for a numpy NDArray, but can't import that either. +# Because pyscreeze does not declare it as a dependency, stubsuploader won't let it. _Mat: TypeAlias = Incomplete useOpenCV: bool @@ -37,6 +41,7 @@ class RGB(NamedTuple): class PyScreezeException(Exception): ... class ImageNotFoundException(PyScreezeException): ... +# _locateAll_opencv def requiresPillow(wrappedFunction: Callable[_P, _R]) -> Callable[_P, _R]: ... @overload def locate( diff --git a/stubs/pycocotools/pycocotools/coco.pyi b/stubs/pycocotools/pycocotools/coco.pyi index 1cb93c63f2e9..e8e6650c7381 100644 --- a/stubs/pycocotools/pycocotools/coco.pyi +++ b/stubs/pycocotools/pycocotools/coco.pyi @@ -6,7 +6,7 @@ from typing_extensions import Literal, TypeAlias, TypedDict from . import _EncodedRLE -# TODO: Use numpy types when #5768 is resolved. +# stub_uploader doesn't allow numpy because pycocotools doesn't declare it as a dependency # import numpy as np # import numpy.typing as npt diff --git a/stubs/pycocotools/pycocotools/cocoeval.pyi b/stubs/pycocotools/pycocotools/cocoeval.pyi index d9845c6cb712..08d8d2d5760c 100644 --- a/stubs/pycocotools/pycocotools/cocoeval.pyi +++ b/stubs/pycocotools/pycocotools/cocoeval.pyi @@ -3,7 +3,7 @@ from typing_extensions import Literal, TypeAlias, TypedDict from .coco import COCO -# TODO: Use numpy types when #5768 is resolved. +# stub_uploader doesn't allow numpy because pycocotools doesn't declare it as a dependency # import numpy as np # import numpy.typing as npt diff --git a/stubs/pycocotools/pycocotools/mask.pyi b/stubs/pycocotools/pycocotools/mask.pyi index 07d30d6624b9..5101754f05ca 100644 --- a/stubs/pycocotools/pycocotools/mask.pyi +++ b/stubs/pycocotools/pycocotools/mask.pyi @@ -4,7 +4,7 @@ from typing_extensions import TypeAlias from . import _EncodedRLE -# TODO: Use numpy types when #5768 is resolved. +# stub_uploader doesn't allow numpy because pycocotools doesn't declare it as a dependency # import numpy as np # import numpy.typing as npt diff --git a/stubs/pyinstaller/PyInstaller/lib/modulegraph/modulegraph.pyi b/stubs/pyinstaller/PyInstaller/lib/modulegraph/modulegraph.pyi index ef9cfc5c97e6..ebc7e1c5a8cd 100644 --- a/stubs/pyinstaller/PyInstaller/lib/modulegraph/modulegraph.pyi +++ b/stubs/pyinstaller/PyInstaller/lib/modulegraph/modulegraph.pyi @@ -1,10 +1,12 @@ +# Partial typing of the vendored modulegraph package. +# We reference the vendored package rather than depending on the original untyped module. +# Anything not referenced in the PyInstaller stubs doesn't need to be added here. + from typing import Any, Protocol class _SupportsGraphident(Protocol): graphident: str -# TODO: For typing purposes, once #5768 is complete, it'll be easier to use the modulegraph package directly. - # code, filename and packagepath are always initialized to None. But they can be given a value later. class Node: # Compiled code. See stdlib.builtins.compile diff --git a/tests/mypy_test.py b/tests/mypy_test.py index a335f3832ffd..087f4136688f 100644 --- a/tests/mypy_test.py +++ b/tests/mypy_test.py @@ -264,7 +264,7 @@ def run_mypy( # Stub completion is checked by pyright (--allow-*-defs) "--allow-untyped-defs", "--allow-incomplete-defs", - "--allow-subclassing-any", # TODO: Do we still need this now that non-types dependencies are allowed? (#5768) + "--allow-subclassing-any", # See #9491 "--enable-error-code", "ignore-without-code", "--config-file", From 17da551f64afa41f5a2eae4e015c7469f9e5e6db Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 14 Jan 2023 07:45:32 -0500 Subject: [PATCH 2/2] Update comments --- stubs/Pillow/@tests/stubtest_allowlist.txt | 2 +- stubs/PyScreeze/pyscreeze/__init__.pyi | 2 +- stubs/pycocotools/pycocotools/coco.pyi | 2 +- stubs/pycocotools/pycocotools/cocoeval.pyi | 2 +- stubs/pycocotools/pycocotools/mask.pyi | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/stubs/Pillow/@tests/stubtest_allowlist.txt b/stubs/Pillow/@tests/stubtest_allowlist.txt index 815a47fb10f2..bf5158dc9c60 100644 --- a/stubs/Pillow/@tests/stubtest_allowlist.txt +++ b/stubs/Pillow/@tests/stubtest_allowlist.txt @@ -1,7 +1,7 @@ PIL.FpxImagePlugin PIL.ImageQt.ImageQt PIL.MicImagePlugin -# Requires Pyside or PyQt to be installed. +# Requires PySide or PyQt to be installed. # We don't install either in stubtest so it can't see it PIL.ImageQt.QImage PIL.ImageQt.QPixmap diff --git a/stubs/PyScreeze/pyscreeze/__init__.pyi b/stubs/PyScreeze/pyscreeze/__init__.pyi index 6272d9ace6f1..9821a253aa43 100644 --- a/stubs/PyScreeze/pyscreeze/__init__.pyi +++ b/stubs/PyScreeze/pyscreeze/__init__.pyi @@ -14,7 +14,7 @@ _R = TypeVar("_R") # https://github.com/microsoft/python-type-stubs/tree/main/cv2 # https://github.com/opencv/opencv/pull/20370 # cv2.Mat is just an alias for a numpy NDArray, but can't import that either. -# Because pyscreeze does not declare it as a dependency, stubsuploader won't let it. +# Because pyscreeze does not declare it as a dependency, stub_uploader won't let it. _Mat: TypeAlias = Incomplete useOpenCV: bool diff --git a/stubs/pycocotools/pycocotools/coco.pyi b/stubs/pycocotools/pycocotools/coco.pyi index e8e6650c7381..1cb93c63f2e9 100644 --- a/stubs/pycocotools/pycocotools/coco.pyi +++ b/stubs/pycocotools/pycocotools/coco.pyi @@ -6,7 +6,7 @@ from typing_extensions import Literal, TypeAlias, TypedDict from . import _EncodedRLE -# stub_uploader doesn't allow numpy because pycocotools doesn't declare it as a dependency +# TODO: Use numpy types when #5768 is resolved. # import numpy as np # import numpy.typing as npt diff --git a/stubs/pycocotools/pycocotools/cocoeval.pyi b/stubs/pycocotools/pycocotools/cocoeval.pyi index 08d8d2d5760c..d9845c6cb712 100644 --- a/stubs/pycocotools/pycocotools/cocoeval.pyi +++ b/stubs/pycocotools/pycocotools/cocoeval.pyi @@ -3,7 +3,7 @@ from typing_extensions import Literal, TypeAlias, TypedDict from .coco import COCO -# stub_uploader doesn't allow numpy because pycocotools doesn't declare it as a dependency +# TODO: Use numpy types when #5768 is resolved. # import numpy as np # import numpy.typing as npt diff --git a/stubs/pycocotools/pycocotools/mask.pyi b/stubs/pycocotools/pycocotools/mask.pyi index 5101754f05ca..07d30d6624b9 100644 --- a/stubs/pycocotools/pycocotools/mask.pyi +++ b/stubs/pycocotools/pycocotools/mask.pyi @@ -4,7 +4,7 @@ from typing_extensions import TypeAlias from . import _EncodedRLE -# stub_uploader doesn't allow numpy because pycocotools doesn't declare it as a dependency +# TODO: Use numpy types when #5768 is resolved. # import numpy as np # import numpy.typing as npt