Skip to content

Commit

Permalink
Try D3DShot post python#5768
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Jan 14, 2023
1 parent 1946907 commit c6e760b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 32 deletions.
2 changes: 1 addition & 1 deletion stubs/D3DShot/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version = "0.1.*"
requires = ["types-Pillow"]
requires = ["types-Pillow", "numpy", "torch"]

[tool.stubtest]
# TODO: figure out how to run stubtest for this package
Expand Down
17 changes: 7 additions & 10 deletions stubs/D3DShot/d3dshot/capture_output.pyi
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import enum
from _typeshed import Incomplete
from collections.abc import Sequence
from ctypes import _CVoidConstPLike
from typing import Any
from typing_extensions import Literal, TypeAlias

import numpy
import numpy.typing
from PIL import Image
from torch import Tensor

_Frame: TypeAlias = Image.Image | Incomplete
# TODO: Complete types once we can import non-types dependencies
# See: #5768
# 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
_Frame: TypeAlias = Image.Image | numpy.typing.NDArray[numpy.int32] | numpy.typing.NDArray[numpy.float32] | Tensor

class CaptureOutputs(enum.Enum):
PIL: int
Expand All @@ -39,6 +36,6 @@ class CaptureOutput:
height: int,
region: tuple[int, int, int, int],
rotation: int,
) -> _Frame: ...
) -> Any: ... # AnyOf[_Frame]
def to_pil(self, frame: _Frame) -> Image.Image: ...
def stack(self, frames: Sequence[_Frame], stack_dimension: Literal["first", "last"]) -> _Frame: ...
def stack(self, frames: Sequence[_Frame], stack_dimension: Literal["first", "last"]) -> Any: ... # AnyOf[_Frame]
16 changes: 7 additions & 9 deletions stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
from _typeshed import Incomplete
from collections.abc import Sequence
from ctypes import _CVoidConstPLike
from typing_extensions import Literal, TypeAlias

import numpy
import numpy.typing
from d3dshot.capture_output import CaptureOutput
from PIL import Image

# TODO: Complete types once we can import non-types dependencies
# See: #5768
# import numpy as np
# import numpy.typing as npt
# _NDArray: TypeAlias = npt.NDArray[np.int32]
_NDArray: TypeAlias = Incomplete
_NDArray: TypeAlias = numpy.typing.NDArray[numpy.int32]

class NumpyCaptureOutput(CaptureOutput):
def __init__(self) -> None: ...
Expand All @@ -25,5 +21,7 @@ class NumpyCaptureOutput(CaptureOutput):
region: tuple[int, int, int, int],
rotation: int,
) -> _NDArray: ...
def to_pil(self, frame: _NDArray) -> Image.Image: ...
def stack(self, frames: Sequence[_NDArray] | _NDArray, stack_dimension: Literal["first", "last"]) -> _NDArray: ...
def to_pil(self, frame: _NDArray) -> Image.Image: ... # type: ignore[override]
def stack( # type: ignore[override]
self, frames: Sequence[_NDArray] | _NDArray, stack_dimension: Literal["first", "last"]
) -> _NDArray: ...
15 changes: 5 additions & 10 deletions stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
from _typeshed import Incomplete
from collections.abc import Sequence
from ctypes import _CVoidConstPLike
from typing_extensions import Literal, TypeAlias
from typing_extensions import Literal

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
# from torch import Tensor
_Tensor: TypeAlias = Incomplete
from torch import Tensor

class PytorchCaptureOutput(CaptureOutput):
def __init__(self) -> None: ...
Expand All @@ -22,6 +17,6 @@ class PytorchCaptureOutput(CaptureOutput):
height: int,
region: tuple[int, int, int, int],
rotation: int,
) -> _Tensor: ...
def to_pil(self, frame: _Tensor) -> Image.Image: ...
def stack(self, frames: Sequence[_Tensor], stack_dimension: Literal["first", "last"]) -> _Tensor: ...
) -> Tensor: ...
def to_pil(self, frame: Tensor) -> Image.Image: ... # type: ignore[override]
def stack(self, frames: Sequence[Tensor], stack_dimension: Literal["first", "last"]) -> Tensor: ... # type: ignore[override]
4 changes: 2 additions & 2 deletions stubs/D3DShot/d3dshot/dll/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down

0 comments on commit c6e760b

Please sign in to comment.