From 31cc8111bede88326a7fdd0d45ac1c61ebefac4a Mon Sep 17 00:00:00 2001 From: Avasam Date: Tue, 30 Aug 2022 19:24:38 -0400 Subject: [PATCH 01/30] Added stubs for D3DShot --- stubs/D3DShot/METADATA.toml | 4 ++ stubs/D3DShot/d3dshot/__init__.pyi | 12 ++++ stubs/D3DShot/d3dshot/capture_output.pyi | 36 ++++++++++++ .../d3dshot/capture_outputs/__init__.pyi | 0 .../capture_outputs/numpy_capture_output.pyi | 18 ++++++ .../numpy_float_capture_output.pyi | 18 ++++++ .../capture_outputs/pil_capture_output.pyi | 15 +++++ .../pytorch_capture_output.pyi | 16 +++++ .../pytorch_float_capture_output.pyi | 16 +++++ .../pytorch_float_gpu_capture_output.pyi | 17 ++++++ .../pytorch_gpu_capture_output.pyi | 17 ++++++ stubs/D3DShot/d3dshot/d3dshot.pyi | 55 ++++++++++++++++++ stubs/D3DShot/d3dshot/display.pyi | 54 +++++++++++++++++ stubs/D3DShot/d3dshot/dll/__init__.pyi | 0 stubs/D3DShot/d3dshot/dll/d3d.pyi | 20 +++++++ stubs/D3DShot/d3dshot/dll/dxgi.pyi | 58 +++++++++++++++++++ stubs/D3DShot/d3dshot/dll/shcore.pyi | 1 + stubs/D3DShot/d3dshot/dll/user32.pyi | 10 ++++ 18 files changed, 367 insertions(+) create mode 100644 stubs/D3DShot/METADATA.toml create mode 100644 stubs/D3DShot/d3dshot/__init__.pyi create mode 100644 stubs/D3DShot/d3dshot/capture_output.pyi create mode 100644 stubs/D3DShot/d3dshot/capture_outputs/__init__.pyi create mode 100644 stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi create mode 100644 stubs/D3DShot/d3dshot/capture_outputs/numpy_float_capture_output.pyi create mode 100644 stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi create mode 100644 stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi create mode 100644 stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_capture_output.pyi create mode 100644 stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi create mode 100644 stubs/D3DShot/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi create mode 100644 stubs/D3DShot/d3dshot/d3dshot.pyi create mode 100644 stubs/D3DShot/d3dshot/display.pyi create mode 100644 stubs/D3DShot/d3dshot/dll/__init__.pyi create mode 100644 stubs/D3DShot/d3dshot/dll/d3d.pyi create mode 100644 stubs/D3DShot/d3dshot/dll/dxgi.pyi create mode 100644 stubs/D3DShot/d3dshot/dll/shcore.pyi create mode 100644 stubs/D3DShot/d3dshot/dll/user32.pyi diff --git a/stubs/D3DShot/METADATA.toml b/stubs/D3DShot/METADATA.toml new file mode 100644 index 000000000000..a8dd8c68c971 --- /dev/null +++ b/stubs/D3DShot/METADATA.toml @@ -0,0 +1,4 @@ +version = "0.1.*" + +[tool.stubtest] +ignore_missing_stub = false diff --git a/stubs/D3DShot/d3dshot/__init__.pyi b/stubs/D3DShot/d3dshot/__init__.pyi new file mode 100644 index 000000000000..17f1dd8e9f27 --- /dev/null +++ b/stubs/D3DShot/d3dshot/__init__.pyi @@ -0,0 +1,12 @@ +from d3dshot.capture_output import CaptureOutputs as CaptureOutputs +from d3dshot.d3dshot import D3DShot as D3DShot + +pil_is_available: bool +numpy_is_available: bool +pytorch_is_available: bool +pytorch_gpu_is_available: bool +capture_output_mapping: dict[str, CaptureOutputs] +capture_outputs: list[str] + +def determine_available_capture_outputs() -> list[CaptureOutputs]: ... +def create(capture_output: str = ..., frame_buffer_size: int = ...) -> D3DShot: ... diff --git a/stubs/D3DShot/d3dshot/capture_output.pyi b/stubs/D3DShot/d3dshot/capture_output.pyi new file mode 100644 index 000000000000..7dd61c094a01 --- /dev/null +++ b/stubs/D3DShot/d3dshot/capture_output.pyi @@ -0,0 +1,36 @@ +import enum +from _typeshed import Incomplete +from typing_extensions import TypeAlias + +import numpy as np +import numpy.typing as npt +from d3dshot import pytorch_is_available +from PIL.Image import Image + +if pytorch_is_available: + import torch + + Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | torch.Tensor +else: + Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] +Pointer: TypeAlias = Incomplete + +class CaptureOutputs(enum.Enum): + PIL: int + NUMPY: int + NUMPY_FLOAT: int + PYTORCH: int + PYTORCH_FLOAT: int + PYTORCH_GPU: int + PYTORCH_FLOAT_GPU: int + +class CaptureOutputError(BaseException): ... + +class CaptureOutput: + backend: CaptureOutput + def __init__(self, backend: CaptureOutputs = ...) -> None: ... + def process( + self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + ) -> Frame: ... + def to_pil(self, frame: Frame) -> Image: ... + def stack(self, frames: list[Frame], stack_dimension) -> Frame: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/__init__.pyi b/stubs/D3DShot/d3dshot/capture_outputs/__init__.pyi new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi new file mode 100644 index 000000000000..494591aa632f --- /dev/null +++ b/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi @@ -0,0 +1,18 @@ +from _typeshed import Incomplete +from typing_extensions import TypeAlias + +import numpy as np +import numpy.typing as npt +from d3dshot.capture_output import CaptureOutput as CaptureOutput +from PIL.Image import Image + +Pointer: TypeAlias = Incomplete +NDArray: TypeAlias = npt.NDArray[np.int32] + +class NumpyCaptureOutput(CaptureOutput): + def __init__(self) -> None: ... + def process( + self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + ) -> NDArray: ... + def to_pil(self, frame: NDArray) -> Image: ... + def stack(self, frames: list[NDArray] | NDArray, stack_dimension: int) -> NDArray: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/numpy_float_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/numpy_float_capture_output.pyi new file mode 100644 index 000000000000..3202aedcbee1 --- /dev/null +++ b/stubs/D3DShot/d3dshot/capture_outputs/numpy_float_capture_output.pyi @@ -0,0 +1,18 @@ +from _typeshed import Incomplete +from typing_extensions import TypeAlias + +import numpy as np +import numpy.typing as npt +from d3dshot.capture_output import CaptureOutput as CaptureOutput +from PIL.Image import Image + +Pointer: TypeAlias = Incomplete +NDArray: TypeAlias = npt.NDArray[np.float32] + +class NumpyFloatCaptureOutput(CaptureOutput): + def __init__(self) -> None: ... + def process( + self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + ) -> NDArray: ... + def to_pil(self, frame: NDArray) -> Image: ... + def stack(self, frames: list[NDArray] | NDArray, stack_dimension: int) -> NDArray: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi new file mode 100644 index 000000000000..0b37fe111d54 --- /dev/null +++ b/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi @@ -0,0 +1,15 @@ +from _typeshed import Incomplete +from typing_extensions import TypeAlias + +from d3dshot.capture_output import CaptureOutput as CaptureOutput +from PIL.Image import Image + +Pointer: TypeAlias = Incomplete + +class PILCaptureOutput(CaptureOutput): + def __init__(self) -> None: ... + def process( + self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + ) -> Image: ... + def to_pil(self, frame: Image) -> Image: ... + def stack(self, frames: list[Image], stack_dimension: int) -> list[Image]: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi new file mode 100644 index 000000000000..405ad2f12ec9 --- /dev/null +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi @@ -0,0 +1,16 @@ +from _typeshed import Incomplete +from typing_extensions import TypeAlias + +import torch +from d3dshot.capture_output import CaptureOutput as CaptureOutput +from PIL.Image import Image + +Pointer: TypeAlias = Incomplete + +class PytorchCaptureOutput(CaptureOutput): + def __init__(self) -> None: ... + def process( + self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + ) -> torch.Tensor: ... + def to_pil(self, frame: torch.Tensor) -> Image: ... + def stack(self, frames: list[torch.Tensor], stack_dimension: int) -> torch.Tensor: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_capture_output.pyi new file mode 100644 index 000000000000..0a065702d9cd --- /dev/null +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_capture_output.pyi @@ -0,0 +1,16 @@ +from _typeshed import Incomplete +from typing_extensions import TypeAlias + +import torch +from d3dshot.capture_output import CaptureOutput as CaptureOutput +from PIL.Image import Image + +Pointer: TypeAlias = Incomplete + +class PytorchFloatCaptureOutput(CaptureOutput): + def __init__(self) -> None: ... + def process( + self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + ) -> torch.Tensor: ... + def to_pil(self, frame: torch.Tensor) -> Image: ... + def stack(self, frames: list[torch.Tensor], stack_dimension: int) -> torch.Tensor: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi new file mode 100644 index 000000000000..8fef57d3782e --- /dev/null +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi @@ -0,0 +1,17 @@ +from _typeshed import Incomplete +from typing_extensions import TypeAlias + +import torch +from d3dshot.capture_output import CaptureOutput as CaptureOutput +from PIL.Image import Image + +Pointer: TypeAlias = Incomplete + +class PytorchFloatGPUCaptureOutput(CaptureOutput): + device: Incomplete + def __init__(self) -> None: ... + def process( + self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + ) -> torch.Tensor: ... + def to_pil(self, frame: torch.Tensor) -> Image: ... + def stack(self, frames: list[torch.Tensor], stack_dimension: int) -> torch.Tensor: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi new file mode 100644 index 000000000000..ff1d3e71ba9d --- /dev/null +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi @@ -0,0 +1,17 @@ +from _typeshed import Incomplete +from typing_extensions import TypeAlias + +import torch +from d3dshot.capture_output import CaptureOutput as CaptureOutput +from PIL.Image import Image + +Pointer: TypeAlias = Incomplete + +class PytorchGPUCaptureOutput(CaptureOutput): + device: torch.device + def __init__(self) -> None: ... + def process( + self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + ) -> torch.Tensor: ... + def to_pil(self, frame: torch.Tensor) -> Image: ... + def stack(self, frames: list[torch.Tensor], stack_dimension: int): ... diff --git a/stubs/D3DShot/d3dshot/d3dshot.pyi b/stubs/D3DShot/d3dshot/d3dshot.pyi new file mode 100644 index 000000000000..d29f9b20ff7a --- /dev/null +++ b/stubs/D3DShot/d3dshot/d3dshot.pyi @@ -0,0 +1,55 @@ +from _typeshed import Incomplete +from collections import deque +from typing_extensions import TypeAlias + +import numpy as np +import numpy.typing as npt +from d3dshot import pytorch_is_available +from d3dshot.capture_output import CaptureOutput as CaptureOutput, CaptureOutputs as CaptureOutputs +from d3dshot.display import Display as Display +from PIL.Image import Image + +if pytorch_is_available: + import torch + + Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | torch.Tensor +else: + Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] + +class D3DShot: + displays: list[Display] + display: Display + capture_output: CaptureOutput + frame_buffer_size: int + frame_buffer: deque[Frame] + previous_screenshot: Frame | None + region: tuple[int, int, int, int] | None + + def __init__( + self, + capture_output: CaptureOutputs = ..., + frame_buffer_size: int = ..., + pil_is_available: bool = ..., + numpy_is_available: bool = ..., + pytorch_is_available: bool = ..., + pytorch_gpu_is_available: bool = ..., + ) -> None: ... + @property + def is_capturing(self) -> bool: ... + def get_latest_frame(self) -> Frame | None: ... + def get_frame(self, frame_index: int) -> Frame | None: ... + def get_frames(self, frame_indices: list[int]) -> list[Frame]: ... + def get_frame_stack(self, frame_indices: list[int], stack_dimension: str | None = ...) -> Frame: ... + def screenshot(self, region: tuple[int, int, int, int] | None = ...) -> Frame | None: ... + def screenshot_to_disk( + self, directory: str | None = ..., file_name: str | None = ..., region: tuple[int, int, int, int] | None = ... + ) -> str: ... + def frame_buffer_to_disk(self, directory: str | None = ...) -> None: ... + def capture(self, target_fps: int = ..., region: tuple[int, int, int, int] | None = ...) -> bool: ... + def screenshot_every(self, interval: float, region: tuple[int, int, int, int] | None = ...) -> bool: ... + def screenshot_to_disk_every( + self, interval: float, directory: str | None = ..., region: tuple[int, int, int, int] | None = ... + ) -> bool: ... + def stop(self) -> bool: ... + def benchmark(self) -> None: ... + def detect_displays(self) -> None: ... diff --git a/stubs/D3DShot/d3dshot/display.pyi b/stubs/D3DShot/d3dshot/display.pyi new file mode 100644 index 000000000000..8892a6a0147b --- /dev/null +++ b/stubs/D3DShot/d3dshot/display.pyi @@ -0,0 +1,54 @@ +from _typeshed import Incomplete +from collections.abc import Callable +from typing import Literal +from typing_extensions import TypeAlias + +import numpy as np +import numpy.typing as npt +from d3dshot import pytorch_is_available +from PIL.Image import Image + +if pytorch_is_available: + import torch + + Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | torch.Tensor +else: + Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] +Pointer: TypeAlias = Incomplete + +class Display: + name: str + adapter_name: str + resolution: tuple[int, int] + position: dict[Literal["left", "top", "right", "bottom"], int] + rotation: int + scale_factor: int + is_primary: bool + hmonitor: int + dxgi_output: Incomplete | None + dxgi_adapter: Incomplete | None + d3d_device: Incomplete # ctypes.POINTER(ID3D11Device)() + d3d_device_context: Incomplete # ctypes.POINTER(ID3D11DeviceContext)() + dxgi_output_duplication: Incomplete # ctypes.POINTER(IDXGIOutputDuplication)() + + def __init__( + self, + name: str | None = ..., + adapter_name: str | None = ..., + resolution: tuple[int, int] | None = ..., + position: dict[Literal["left", "top", "right", "bottom"], int] | None = ..., + rotation: int | None = ..., + scale_factor: int | None = ..., + is_primary: bool = ..., + hmonitor: int | None = ..., + dxgi_output: Incomplete | None = ..., + dxgi_adapter: Incomplete | None = ..., + ) -> None: ... + def capture( + self, + # Incomplete: dxgi_mapped_rect.pBits + process_func: Callable[[Pointer, int, int, int, tuple[int, int, int, int], int], Frame | None] | None, + region: tuple[int, int, int, int] = ..., + ) -> Frame: ... + @classmethod + def discover_displays(cls) -> list[Display]: ... diff --git a/stubs/D3DShot/d3dshot/dll/__init__.pyi b/stubs/D3DShot/d3dshot/dll/__init__.pyi new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/stubs/D3DShot/d3dshot/dll/d3d.pyi b/stubs/D3DShot/d3dshot/dll/d3d.pyi new file mode 100644 index 000000000000..536e4c8ad70f --- /dev/null +++ b/stubs/D3DShot/d3dshot/dll/d3d.pyi @@ -0,0 +1,20 @@ +import ctypes +from _typeshed import Incomplete +from typing_extensions import TypeAlias + +import comtypes + +Pointer: TypeAlias = Incomplete + +class DXGI_SAMPLE_DESC(ctypes.Structure): ... +class D3D11_BOX(ctypes.Structure): ... +class D3D11_TEXTURE2D_DESC(ctypes.Structure): ... +class ID3D11DeviceChild(comtypes.IUnknown): ... +class ID3D11Resource(ID3D11DeviceChild): ... +class ID3D11Texture2D(ID3D11Resource): ... +class ID3D11DeviceContext(ID3D11DeviceChild): ... +class ID3D11Device(comtypes.IUnknown): ... + +def initialize_d3d_device(dxgi_adapter: Pointer) -> tuple[Pointer, Pointer]: ... +def describe_d3d11_texture_2d(d3d11_texture_2d: Pointer) -> D3D11_TEXTURE2D_DESC: ... +def prepare_d3d11_texture_2d_for_cpu(d3d11_texture_2d: Pointer, d3d_device: Pointer): ... diff --git a/stubs/D3DShot/d3dshot/dll/dxgi.pyi b/stubs/D3DShot/d3dshot/dll/dxgi.pyi new file mode 100644 index 000000000000..f96e95699b46 --- /dev/null +++ b/stubs/D3DShot/d3dshot/dll/dxgi.pyi @@ -0,0 +1,58 @@ +import ctypes +from _typeshed import Incomplete +from collections.abc import Callable +from typing_extensions import TypeAlias + +import comtypes +import numpy as np +import numpy.typing as npt +from d3dshot import pytorch_is_available +from d3dshot.dll.d3d import ( + ID3D11Device as ID3D11Device, + ID3D11DeviceContext as ID3D11DeviceContext, + ID3D11Texture2D as ID3D11Texture2D, + prepare_d3d11_texture_2d_for_cpu as prepare_d3d11_texture_2d_for_cpu, +) +from PIL.Image import Image + +if pytorch_is_available: + import torch + + Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | torch.Tensor +else: + Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] +Pointer: TypeAlias = Incomplete + +class LUID(ctypes.Structure): ... +class DXGI_ADAPTER_DESC1(ctypes.Structure): ... +class DXGI_OUTPUT_DESC(ctypes.Structure): ... +class DXGI_OUTDUPL_POINTER_POSITION(ctypes.Structure): ... +class DXGI_OUTDUPL_FRAME_INFO(ctypes.Structure): ... +class DXGI_MAPPED_RECT(ctypes.Structure): ... +class IDXGIObject(comtypes.IUnknown): ... +class IDXGIDeviceSubObject(IDXGIObject): ... +class IDXGIResource(IDXGIDeviceSubObject): ... +class IDXGISurface(IDXGIDeviceSubObject): ... +class IDXGIOutputDuplication(IDXGIObject): ... +class IDXGIOutput(IDXGIObject): ... +class IDXGIOutput1(IDXGIOutput): ... +class IDXGIAdapter(IDXGIObject): ... +class IDXGIAdapter1(IDXGIAdapter): ... +class IDXGIFactory(IDXGIObject): ... +class IDXGIFactory1(IDXGIFactory): ... + +def initialize_dxgi_factory() -> Pointer: ... # ctypes.POINTER(IDXGIFactory1)(handle.value) +def discover_dxgi_adapters(dxgi_factory: Pointer) -> list[Pointer]: ... +def describe_dxgi_adapter(dxgi_adapter: Pointer): ... +def discover_dxgi_outputs(dxgi_adapter: Pointer): ... +def describe_dxgi_output(dxgi_output: Pointer): ... +def initialize_dxgi_output_duplication(dxgi_output: Pointer, d3d_device: Pointer): ... +def get_dxgi_output_duplication_frame( + dxgi_output_duplication: Pointer, + d3d_device: Pointer, + process_func: Callable[[Pointer, int, int, int, tuple[int, int, int, int], int], Frame | None] | None = ..., + width: int = ..., + height: int = ..., + region: tuple[int, int, int, int] | None = ..., + rotation: int = ..., +): ... diff --git a/stubs/D3DShot/d3dshot/dll/shcore.pyi b/stubs/D3DShot/d3dshot/dll/shcore.pyi new file mode 100644 index 000000000000..15a24dba3c4e --- /dev/null +++ b/stubs/D3DShot/d3dshot/dll/shcore.pyi @@ -0,0 +1 @@ +def get_scale_factor_for_monitor(hmonitor: int) -> float: ... diff --git a/stubs/D3DShot/d3dshot/dll/user32.pyi b/stubs/D3DShot/d3dshot/dll/user32.pyi new file mode 100644 index 000000000000..15a34fd38c33 --- /dev/null +++ b/stubs/D3DShot/d3dshot/dll/user32.pyi @@ -0,0 +1,10 @@ +import ctypes +from _typeshed import Incomplete +from typing_extensions import TypeAlias + +Pointer: TypeAlias = Incomplete + +class DISPLAY_DEVICE(ctypes.Structure): ... + +def get_display_device_name_mapping() -> dict[str, tuple[str, bool]]: ... +def get_hmonitor_by_point(x: int, y: int) -> Pointer: ... # ctypes.windll.user32.MonitorFromPoint(point, 0) From 6e08d8dc42eae57a0d4cf2e59c80e2f14cf767b1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 30 Aug 2022 23:34:44 +0000 Subject: [PATCH 02/30] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stubs/D3DShot/d3dshot/d3dshot.pyi | 1 - 1 file changed, 1 deletion(-) diff --git a/stubs/D3DShot/d3dshot/d3dshot.pyi b/stubs/D3DShot/d3dshot/d3dshot.pyi index d29f9b20ff7a..7af8cea63126 100644 --- a/stubs/D3DShot/d3dshot/d3dshot.pyi +++ b/stubs/D3DShot/d3dshot/d3dshot.pyi @@ -1,4 +1,3 @@ -from _typeshed import Incomplete from collections import deque from typing_extensions import TypeAlias From 04f783c9a0b05ed539ed05c45d274b8474642afd Mon Sep 17 00:00:00 2001 From: Avasam Date: Tue, 30 Aug 2022 19:47:36 -0400 Subject: [PATCH 03/30] Added missing requires --- stubs/D3DShot/METADATA.toml | 1 + stubs/D3DShot/d3dshot/capture_output.pyi | 12 +++--------- stubs/D3DShot/d3dshot/d3dshot.pyi | 14 +++----------- stubs/D3DShot/d3dshot/display.pyi | 14 +++----------- stubs/D3DShot/d3dshot/dll/dxgi.pyi | 13 +++---------- 5 files changed, 13 insertions(+), 41 deletions(-) diff --git a/stubs/D3DShot/METADATA.toml b/stubs/D3DShot/METADATA.toml index a8dd8c68c971..a435aebff9df 100644 --- a/stubs/D3DShot/METADATA.toml +++ b/stubs/D3DShot/METADATA.toml @@ -1,4 +1,5 @@ version = "0.1.*" +requires = ["numpy", "torch", "comtypes"] [tool.stubtest] ignore_missing_stub = false diff --git a/stubs/D3DShot/d3dshot/capture_output.pyi b/stubs/D3DShot/d3dshot/capture_output.pyi index 7dd61c094a01..e5078d83289c 100644 --- a/stubs/D3DShot/d3dshot/capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_output.pyi @@ -1,18 +1,12 @@ import enum from _typeshed import Incomplete +from typing import Any from typing_extensions import TypeAlias -import numpy as np -import numpy.typing as npt -from d3dshot import pytorch_is_available from PIL.Image import Image -if pytorch_is_available: - import torch - - Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | torch.Tensor -else: - Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] +Frame: TypeAlias = Any +# Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | torch.Tensor Pointer: TypeAlias = Incomplete class CaptureOutputs(enum.Enum): diff --git a/stubs/D3DShot/d3dshot/d3dshot.pyi b/stubs/D3DShot/d3dshot/d3dshot.pyi index d29f9b20ff7a..9bee4770ed60 100644 --- a/stubs/D3DShot/d3dshot/d3dshot.pyi +++ b/stubs/D3DShot/d3dshot/d3dshot.pyi @@ -1,20 +1,12 @@ -from _typeshed import Incomplete from collections import deque +from typing import Any from typing_extensions import TypeAlias -import numpy as np -import numpy.typing as npt -from d3dshot import pytorch_is_available from d3dshot.capture_output import CaptureOutput as CaptureOutput, CaptureOutputs as CaptureOutputs from d3dshot.display import Display as Display -from PIL.Image import Image -if pytorch_is_available: - import torch - - Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | torch.Tensor -else: - Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] +Frame: TypeAlias = Any +# Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | torch.Tensor class D3DShot: displays: list[Display] diff --git a/stubs/D3DShot/d3dshot/display.pyi b/stubs/D3DShot/d3dshot/display.pyi index 8892a6a0147b..45a2b5f3d11b 100644 --- a/stubs/D3DShot/d3dshot/display.pyi +++ b/stubs/D3DShot/d3dshot/display.pyi @@ -1,19 +1,11 @@ from _typeshed import Incomplete from collections.abc import Callable -from typing import Literal +from typing import Any, Literal from typing_extensions import TypeAlias -import numpy as np -import numpy.typing as npt -from d3dshot import pytorch_is_available -from PIL.Image import Image -if pytorch_is_available: - import torch - - Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | torch.Tensor -else: - Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] +Frame: TypeAlias = Any +# Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | torch.Tensor Pointer: TypeAlias = Incomplete class Display: diff --git a/stubs/D3DShot/d3dshot/dll/dxgi.pyi b/stubs/D3DShot/d3dshot/dll/dxgi.pyi index f96e95699b46..a1f4fa97f550 100644 --- a/stubs/D3DShot/d3dshot/dll/dxgi.pyi +++ b/stubs/D3DShot/d3dshot/dll/dxgi.pyi @@ -1,26 +1,19 @@ import ctypes from _typeshed import Incomplete from collections.abc import Callable +from typing import Any from typing_extensions import TypeAlias import comtypes -import numpy as np -import numpy.typing as npt -from d3dshot import pytorch_is_available from d3dshot.dll.d3d import ( ID3D11Device as ID3D11Device, ID3D11DeviceContext as ID3D11DeviceContext, ID3D11Texture2D as ID3D11Texture2D, prepare_d3d11_texture_2d_for_cpu as prepare_d3d11_texture_2d_for_cpu, ) -from PIL.Image import Image -if pytorch_is_available: - import torch - - Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | torch.Tensor -else: - Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] +Frame: TypeAlias = Any +# Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | torch.Tensor Pointer: TypeAlias = Incomplete class LUID(ctypes.Structure): ... From f72704e8fd7a7338d44145745cc496b49054669a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 30 Aug 2022 23:49:22 +0000 Subject: [PATCH 04/30] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stubs/D3DShot/d3dshot/display.pyi | 1 - 1 file changed, 1 deletion(-) diff --git a/stubs/D3DShot/d3dshot/display.pyi b/stubs/D3DShot/d3dshot/display.pyi index 45a2b5f3d11b..f81ff3d0d4dd 100644 --- a/stubs/D3DShot/d3dshot/display.pyi +++ b/stubs/D3DShot/d3dshot/display.pyi @@ -3,7 +3,6 @@ from collections.abc import Callable from typing import Any, Literal from typing_extensions import TypeAlias - Frame: TypeAlias = Any # Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | torch.Tensor Pointer: TypeAlias = Incomplete From 85c4c95ec340238cfd3ce9f4e044e1232b81b772 Mon Sep 17 00:00:00 2001 From: Avasam Date: Tue, 30 Aug 2022 20:01:05 -0400 Subject: [PATCH 05/30] Fixed missing Unknowns --- pyrightconfig.stricter.json | 3 ++- stubs/D3DShot/d3dshot/dll/d3d.pyi | 2 +- stubs/D3DShot/d3dshot/dll/dxgi.pyi | 10 +++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index 2a335d75f698..5e11c32ce27d 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -90,7 +90,8 @@ "stubs/tzlocal/tzlocal/utils.pyi", "stubs/ttkthemes", "stubs/urllib3", - "stubs/vobject" + "stubs/vobject", + "stubs/D3DShot" ], "typeCheckingMode": "basic", "strictListInference": true, diff --git a/stubs/D3DShot/d3dshot/dll/d3d.pyi b/stubs/D3DShot/d3dshot/dll/d3d.pyi index 536e4c8ad70f..438e18bc677c 100644 --- a/stubs/D3DShot/d3dshot/dll/d3d.pyi +++ b/stubs/D3DShot/d3dshot/dll/d3d.pyi @@ -17,4 +17,4 @@ class ID3D11Device(comtypes.IUnknown): ... def initialize_d3d_device(dxgi_adapter: Pointer) -> tuple[Pointer, Pointer]: ... def describe_d3d11_texture_2d(d3d11_texture_2d: Pointer) -> D3D11_TEXTURE2D_DESC: ... -def prepare_d3d11_texture_2d_for_cpu(d3d11_texture_2d: Pointer, d3d_device: Pointer): ... +def prepare_d3d11_texture_2d_for_cpu(d3d11_texture_2d: Pointer, d3d_device: Pointer) -> Pointer: ... diff --git a/stubs/D3DShot/d3dshot/dll/dxgi.pyi b/stubs/D3DShot/d3dshot/dll/dxgi.pyi index a1f4fa97f550..63c235baf6be 100644 --- a/stubs/D3DShot/d3dshot/dll/dxgi.pyi +++ b/stubs/D3DShot/d3dshot/dll/dxgi.pyi @@ -36,10 +36,10 @@ class IDXGIFactory1(IDXGIFactory): ... def initialize_dxgi_factory() -> Pointer: ... # ctypes.POINTER(IDXGIFactory1)(handle.value) def discover_dxgi_adapters(dxgi_factory: Pointer) -> list[Pointer]: ... -def describe_dxgi_adapter(dxgi_adapter: Pointer): ... -def discover_dxgi_outputs(dxgi_adapter: Pointer): ... -def describe_dxgi_output(dxgi_output: Pointer): ... -def initialize_dxgi_output_duplication(dxgi_output: Pointer, d3d_device: Pointer): ... +def describe_dxgi_adapter(dxgi_adapter: Pointer) -> Pointer: ... +def discover_dxgi_outputs(dxgi_adapter: Pointer) -> list[Pointer]: ... +def describe_dxgi_output(dxgi_output: Pointer) -> Pointer: ... +def initialize_dxgi_output_duplication(dxgi_output: Pointer, d3d_device: Pointer) -> Pointer: ... def get_dxgi_output_duplication_frame( dxgi_output_duplication: Pointer, d3d_device: Pointer, @@ -48,4 +48,4 @@ def get_dxgi_output_duplication_frame( height: int = ..., region: tuple[int, int, int, int] | None = ..., rotation: int = ..., -): ... +) -> Frame: ... From 642d58b32cf5776a0e4c25f12ab2c53440beee34 Mon Sep 17 00:00:00 2001 From: Avasam Date: Tue, 30 Aug 2022 20:49:30 -0400 Subject: [PATCH 06/30] Unused imports --- stubs/D3DShot/d3dshot/capture_output.pyi | 15 ++++--- .../capture_outputs/numpy_capture_output.pyi | 13 +++--- .../numpy_float_capture_output.pyi | 13 +++--- .../capture_outputs/pil_capture_output.pyi | 4 +- .../pytorch_capture_output.pyi | 15 ++++--- .../pytorch_float_capture_output.pyi | 15 ++++--- .../pytorch_float_gpu_capture_output.pyi | 18 ++++---- .../pytorch_gpu_capture_output.pyi | 19 +++++---- stubs/D3DShot/d3dshot/d3dshot.pyi | 20 ++++----- stubs/D3DShot/d3dshot/display.pyi | 12 +++--- stubs/D3DShot/d3dshot/dll/d3d.pyi | 17 ++++---- stubs/D3DShot/d3dshot/dll/dxgi.pyi | 41 +++++++++---------- stubs/D3DShot/d3dshot/dll/user32.pyi | 4 +- 13 files changed, 113 insertions(+), 93 deletions(-) diff --git a/stubs/D3DShot/d3dshot/capture_output.pyi b/stubs/D3DShot/d3dshot/capture_output.pyi index e5078d83289c..d9d654d505c2 100644 --- a/stubs/D3DShot/d3dshot/capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_output.pyi @@ -1,13 +1,12 @@ import enum from _typeshed import Incomplete -from typing import Any from typing_extensions import TypeAlias from PIL.Image import Image -Frame: TypeAlias = Any -# Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | torch.Tensor -Pointer: TypeAlias = Incomplete +_Frame: TypeAlias = Incomplete +# _Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | _Tensor +_Pointer: TypeAlias = Incomplete class CaptureOutputs(enum.Enum): PIL: int @@ -24,7 +23,7 @@ class CaptureOutput: backend: CaptureOutput def __init__(self, backend: CaptureOutputs = ...) -> None: ... def process( - self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int - ) -> Frame: ... - def to_pil(self, frame: Frame) -> Image: ... - def stack(self, frames: list[Frame], stack_dimension) -> Frame: ... + self, pointer: _Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + ) -> _Frame: ... + def to_pil(self, frame: _Frame) -> Image: ... + def stack(self, frames: list[_Frame], stack_dimension) -> _Frame: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi index 494591aa632f..656e69bac140 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi @@ -1,18 +1,21 @@ from _typeshed import Incomplete from typing_extensions import TypeAlias -import numpy as np -import numpy.typing as npt from d3dshot.capture_output import CaptureOutput as CaptureOutput from PIL.Image import Image -Pointer: TypeAlias = Incomplete -NDArray: TypeAlias = npt.NDArray[np.int32] +# TODO: Complete types once we can import non-types dependencies +# See: https://github.com/python/typeshed/issues/5768 +# import numpy as np +# import numpy.typing as npt +# NDArray: TypeAlias = npt.NDArray[np.int32] +NDArray: TypeAlias = Incomplete +_Pointer: TypeAlias = Incomplete class NumpyCaptureOutput(CaptureOutput): def __init__(self) -> None: ... def process( - self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + self, pointer: _Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int ) -> NDArray: ... def to_pil(self, frame: NDArray) -> Image: ... def stack(self, frames: list[NDArray] | NDArray, stack_dimension: int) -> NDArray: ... 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 3202aedcbee1..734e489b29ac 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/numpy_float_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/numpy_float_capture_output.pyi @@ -1,18 +1,21 @@ from _typeshed import Incomplete from typing_extensions import TypeAlias -import numpy as np -import numpy.typing as npt from d3dshot.capture_output import CaptureOutput as CaptureOutput from PIL.Image import Image -Pointer: TypeAlias = Incomplete -NDArray: TypeAlias = npt.NDArray[np.float32] +# TODO: Complete types once we can import non-types dependencies +# See: https://github.com/python/typeshed/issues/5768 +# import numpy as np +# import numpy.typing as npt +# NDArray: TypeAlias = npt.NDArray[np.float32] +NDArray: TypeAlias = Incomplete +_Pointer: TypeAlias = Incomplete class NumpyFloatCaptureOutput(CaptureOutput): def __init__(self) -> None: ... def process( - self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + self, pointer: _Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int ) -> NDArray: ... def to_pil(self, frame: NDArray) -> Image: ... def stack(self, frames: list[NDArray] | NDArray, stack_dimension: int) -> NDArray: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi index 0b37fe111d54..8c13fa23c8f2 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi @@ -4,12 +4,12 @@ from typing_extensions import TypeAlias from d3dshot.capture_output import CaptureOutput as CaptureOutput from PIL.Image import Image -Pointer: TypeAlias = Incomplete +_Pointer: TypeAlias = Incomplete class PILCaptureOutput(CaptureOutput): def __init__(self) -> None: ... def process( - self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + self, pointer: _Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int ) -> Image: ... def to_pil(self, frame: Image) -> Image: ... def stack(self, frames: list[Image], stack_dimension: int) -> list[Image]: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi index 405ad2f12ec9..f36166f3b871 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi @@ -1,16 +1,19 @@ from _typeshed import Incomplete from typing_extensions import TypeAlias -import torch from d3dshot.capture_output import CaptureOutput as CaptureOutput from PIL.Image import Image -Pointer: TypeAlias = Incomplete +# 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 +_Pointer: TypeAlias = Incomplete class PytorchCaptureOutput(CaptureOutput): def __init__(self) -> None: ... def process( - self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int - ) -> torch.Tensor: ... - def to_pil(self, frame: torch.Tensor) -> Image: ... - def stack(self, frames: list[torch.Tensor], stack_dimension: int) -> torch.Tensor: ... + self, pointer: _Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + ) -> _Tensor: ... + def to_pil(self, frame: _Tensor) -> Image: ... + def stack(self, frames: list[_Tensor], stack_dimension: int) -> _Tensor: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_capture_output.pyi index 0a065702d9cd..ef9c93c0e005 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_capture_output.pyi @@ -1,16 +1,19 @@ from _typeshed import Incomplete from typing_extensions import TypeAlias -import torch from d3dshot.capture_output import CaptureOutput as CaptureOutput from PIL.Image import Image -Pointer: TypeAlias = Incomplete +# 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 +_Pointer: TypeAlias = Incomplete class PytorchFloatCaptureOutput(CaptureOutput): def __init__(self) -> None: ... def process( - self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int - ) -> torch.Tensor: ... - def to_pil(self, frame: torch.Tensor) -> Image: ... - def stack(self, frames: list[torch.Tensor], stack_dimension: int) -> torch.Tensor: ... + self, pointer: _Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + ) -> _Tensor: ... + def to_pil(self, frame: _Tensor) -> Image: ... + def stack(self, frames: list[_Tensor], stack_dimension: int) -> _Tensor: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi index 8fef57d3782e..69a9eadc6641 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi @@ -1,17 +1,21 @@ from _typeshed import Incomplete from typing_extensions import TypeAlias -import torch from d3dshot.capture_output import CaptureOutput as CaptureOutput from PIL.Image import Image -Pointer: TypeAlias = Incomplete +# TODO: Complete types once we can import non-types dependencies +# See: https://github.com/python/typeshed/issues/5768 +# from torch import device, Tensor +_Tensor: TypeAlias = Incomplete +_device: TypeAlias = Incomplete +_Pointer: TypeAlias = Incomplete class PytorchFloatGPUCaptureOutput(CaptureOutput): - device: Incomplete + device: _device def __init__(self) -> None: ... def process( - self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int - ) -> torch.Tensor: ... - def to_pil(self, frame: torch.Tensor) -> Image: ... - def stack(self, frames: list[torch.Tensor], stack_dimension: int) -> torch.Tensor: ... + self, pointer: _Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + ) -> _Tensor: ... + def to_pil(self, frame: _Tensor) -> Image: ... + def stack(self, frames: list[_Tensor], stack_dimension: int) -> _Tensor: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi index ff1d3e71ba9d..2e1f3f66eec1 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi @@ -1,17 +1,22 @@ from _typeshed import Incomplete from typing_extensions import TypeAlias -import torch from d3dshot.capture_output import CaptureOutput as CaptureOutput from PIL.Image import Image -Pointer: TypeAlias = Incomplete +# TODO: Complete types once we can import non-types dependencies +# See: https://github.com/python/typeshed/issues/5768 +# from torch import device, Tensor +_Tensor: TypeAlias = Incomplete +_device: TypeAlias = Incomplete + +_Pointer: TypeAlias = Incomplete class PytorchGPUCaptureOutput(CaptureOutput): - device: torch.device + device: _device def __init__(self) -> None: ... def process( - self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int - ) -> torch.Tensor: ... - def to_pil(self, frame: torch.Tensor) -> Image: ... - def stack(self, frames: list[torch.Tensor], stack_dimension: int): ... + self, pointer: _Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + ) -> _Tensor: ... + def to_pil(self, frame: _Tensor) -> Image: ... + def stack(self, frames: list[_Tensor], stack_dimension: int): ... diff --git a/stubs/D3DShot/d3dshot/d3dshot.pyi b/stubs/D3DShot/d3dshot/d3dshot.pyi index 9bee4770ed60..6eefd855b620 100644 --- a/stubs/D3DShot/d3dshot/d3dshot.pyi +++ b/stubs/D3DShot/d3dshot/d3dshot.pyi @@ -1,20 +1,20 @@ +from _typeshed import Incomplete from collections import deque -from typing import Any from typing_extensions import TypeAlias from d3dshot.capture_output import CaptureOutput as CaptureOutput, CaptureOutputs as CaptureOutputs from d3dshot.display import Display as Display -Frame: TypeAlias = Any -# Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | torch.Tensor +_Frame: TypeAlias = Incomplete +# _Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | _Tensor class D3DShot: displays: list[Display] display: Display capture_output: CaptureOutput frame_buffer_size: int - frame_buffer: deque[Frame] - previous_screenshot: Frame | None + frame_buffer: deque[_Frame] + previous_screenshot: _Frame | None region: tuple[int, int, int, int] | None def __init__( @@ -28,11 +28,11 @@ class D3DShot: ) -> None: ... @property def is_capturing(self) -> bool: ... - def get_latest_frame(self) -> Frame | None: ... - def get_frame(self, frame_index: int) -> Frame | None: ... - def get_frames(self, frame_indices: list[int]) -> list[Frame]: ... - def get_frame_stack(self, frame_indices: list[int], stack_dimension: str | None = ...) -> Frame: ... - def screenshot(self, region: tuple[int, int, int, int] | None = ...) -> Frame | None: ... + def get_latest_frame(self) -> _Frame | None: ... + def get_frame(self, frame_index: int) -> _Frame | None: ... + def get_frames(self, frame_indices: list[int]) -> list[_Frame]: ... + def get_frame_stack(self, frame_indices: list[int], stack_dimension: str | None = ...) -> _Frame: ... + def screenshot(self, region: tuple[int, int, int, int] | None = ...) -> _Frame | None: ... def screenshot_to_disk( self, directory: str | None = ..., file_name: str | None = ..., region: tuple[int, int, int, int] | None = ... ) -> str: ... diff --git a/stubs/D3DShot/d3dshot/display.pyi b/stubs/D3DShot/d3dshot/display.pyi index f81ff3d0d4dd..a237d6fe496e 100644 --- a/stubs/D3DShot/d3dshot/display.pyi +++ b/stubs/D3DShot/d3dshot/display.pyi @@ -1,11 +1,11 @@ from _typeshed import Incomplete from collections.abc import Callable -from typing import Any, Literal +from typing import Literal from typing_extensions import TypeAlias -Frame: TypeAlias = Any -# Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | torch.Tensor -Pointer: TypeAlias = Incomplete +_Frame: TypeAlias = Incomplete +# _Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | _Tensor +_Pointer: TypeAlias = Incomplete class Display: name: str @@ -38,8 +38,8 @@ class Display: def capture( self, # Incomplete: dxgi_mapped_rect.pBits - process_func: Callable[[Pointer, int, int, int, tuple[int, int, int, int], int], Frame | None] | None, + process_func: Callable[[_Pointer, int, int, int, tuple[int, int, int, int], int], _Frame | None] | None, region: tuple[int, int, int, int] = ..., - ) -> Frame: ... + ) -> _Frame: ... @classmethod def discover_displays(cls) -> list[Display]: ... diff --git a/stubs/D3DShot/d3dshot/dll/d3d.pyi b/stubs/D3DShot/d3dshot/dll/d3d.pyi index 438e18bc677c..0ef566ff7fbe 100644 --- a/stubs/D3DShot/d3dshot/dll/d3d.pyi +++ b/stubs/D3DShot/d3dshot/dll/d3d.pyi @@ -2,19 +2,22 @@ import ctypes from _typeshed import Incomplete from typing_extensions import TypeAlias -import comtypes +# TODO: Complete types once we can import non-types dependencies +# See: https://github.com/python/typeshed/issues/5768 +# import comtypes +_IUnknown: TypeAlias = Incomplete -Pointer: TypeAlias = Incomplete +_Pointer: TypeAlias = Incomplete class DXGI_SAMPLE_DESC(ctypes.Structure): ... class D3D11_BOX(ctypes.Structure): ... class D3D11_TEXTURE2D_DESC(ctypes.Structure): ... -class ID3D11DeviceChild(comtypes.IUnknown): ... +class ID3D11DeviceChild(_IUnknown): ... class ID3D11Resource(ID3D11DeviceChild): ... class ID3D11Texture2D(ID3D11Resource): ... class ID3D11DeviceContext(ID3D11DeviceChild): ... -class ID3D11Device(comtypes.IUnknown): ... +class ID3D11Device(_IUnknown): ... -def initialize_d3d_device(dxgi_adapter: Pointer) -> tuple[Pointer, Pointer]: ... -def describe_d3d11_texture_2d(d3d11_texture_2d: Pointer) -> D3D11_TEXTURE2D_DESC: ... -def prepare_d3d11_texture_2d_for_cpu(d3d11_texture_2d: Pointer, d3d_device: Pointer) -> Pointer: ... +def initialize_d3d_device(dxgi_adapter: _Pointer) -> tuple[_Pointer, _Pointer]: ... +def describe_d3d11_texture_2d(d3d11_texture_2d: _Pointer) -> D3D11_TEXTURE2D_DESC: ... +def prepare_d3d11_texture_2d_for_cpu(d3d11_texture_2d: _Pointer, d3d_device: _Pointer) -> _Pointer: ... diff --git a/stubs/D3DShot/d3dshot/dll/dxgi.pyi b/stubs/D3DShot/d3dshot/dll/dxgi.pyi index 63c235baf6be..eb7bcccc2d91 100644 --- a/stubs/D3DShot/d3dshot/dll/dxgi.pyi +++ b/stubs/D3DShot/d3dshot/dll/dxgi.pyi @@ -1,20 +1,17 @@ import ctypes from _typeshed import Incomplete from collections.abc import Callable -from typing import Any from typing_extensions import TypeAlias -import comtypes -from d3dshot.dll.d3d import ( - ID3D11Device as ID3D11Device, - ID3D11DeviceContext as ID3D11DeviceContext, - ID3D11Texture2D as ID3D11Texture2D, - prepare_d3d11_texture_2d_for_cpu as prepare_d3d11_texture_2d_for_cpu, -) +# TODO: Complete types once we can import non-types dependencies +# See: https://github.com/python/typeshed/issues/5768 +# from torch import Tensor +# import comtypes +_IUnknown: TypeAlias = Incomplete -Frame: TypeAlias = Any -# Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | torch.Tensor -Pointer: TypeAlias = Incomplete +_Frame: TypeAlias = Incomplete +# _Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | Tensor +_Pointer: TypeAlias = Incomplete class LUID(ctypes.Structure): ... class DXGI_ADAPTER_DESC1(ctypes.Structure): ... @@ -22,7 +19,7 @@ class DXGI_OUTPUT_DESC(ctypes.Structure): ... class DXGI_OUTDUPL_POINTER_POSITION(ctypes.Structure): ... class DXGI_OUTDUPL_FRAME_INFO(ctypes.Structure): ... class DXGI_MAPPED_RECT(ctypes.Structure): ... -class IDXGIObject(comtypes.IUnknown): ... +class IDXGIObject(_IUnknown): ... class IDXGIDeviceSubObject(IDXGIObject): ... class IDXGIResource(IDXGIDeviceSubObject): ... class IDXGISurface(IDXGIDeviceSubObject): ... @@ -34,18 +31,18 @@ class IDXGIAdapter1(IDXGIAdapter): ... class IDXGIFactory(IDXGIObject): ... class IDXGIFactory1(IDXGIFactory): ... -def initialize_dxgi_factory() -> Pointer: ... # ctypes.POINTER(IDXGIFactory1)(handle.value) -def discover_dxgi_adapters(dxgi_factory: Pointer) -> list[Pointer]: ... -def describe_dxgi_adapter(dxgi_adapter: Pointer) -> Pointer: ... -def discover_dxgi_outputs(dxgi_adapter: Pointer) -> list[Pointer]: ... -def describe_dxgi_output(dxgi_output: Pointer) -> Pointer: ... -def initialize_dxgi_output_duplication(dxgi_output: Pointer, d3d_device: Pointer) -> Pointer: ... +def initialize_dxgi_factory() -> _Pointer: ... # ctypes.POINTER(IDXGIFactory1)(handle.value) +def discover_dxgi_adapters(dxgi_factory: _Pointer) -> list[_Pointer]: ... +def describe_dxgi_adapter(dxgi_adapter: _Pointer) -> _Pointer: ... +def discover_dxgi_outputs(dxgi_adapter: _Pointer) -> list[_Pointer]: ... +def describe_dxgi_output(dxgi_output: _Pointer) -> _Pointer: ... +def initialize_dxgi_output_duplication(dxgi_output: _Pointer, d3d_device: _Pointer) -> _Pointer: ... def get_dxgi_output_duplication_frame( - dxgi_output_duplication: Pointer, - d3d_device: Pointer, - process_func: Callable[[Pointer, int, int, int, tuple[int, int, int, int], int], Frame | None] | None = ..., + dxgi_output_duplication: _Pointer, + d3d_device: _Pointer, + process_func: Callable[[_Pointer, int, int, int, tuple[int, int, int, int], int], _Frame | None] | None = ..., width: int = ..., height: int = ..., region: tuple[int, int, int, int] | None = ..., rotation: int = ..., -) -> Frame: ... +) -> _Frame: ... diff --git a/stubs/D3DShot/d3dshot/dll/user32.pyi b/stubs/D3DShot/d3dshot/dll/user32.pyi index 15a34fd38c33..96523dc7e0a4 100644 --- a/stubs/D3DShot/d3dshot/dll/user32.pyi +++ b/stubs/D3DShot/d3dshot/dll/user32.pyi @@ -2,9 +2,9 @@ import ctypes from _typeshed import Incomplete from typing_extensions import TypeAlias -Pointer: TypeAlias = Incomplete +_Pointer: TypeAlias = Incomplete class DISPLAY_DEVICE(ctypes.Structure): ... def get_display_device_name_mapping() -> dict[str, tuple[str, bool]]: ... -def get_hmonitor_by_point(x: int, y: int) -> Pointer: ... # ctypes.windll.user32.MonitorFromPoint(point, 0) +def get_hmonitor_by_point(x: int, y: int) -> _Pointer: ... # ctypes.windll.user32.MonitorFromPoint(point, 0) From b7793e868a72750249974c175549e647ce6f0554 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 31 Aug 2022 03:18:07 -0400 Subject: [PATCH 07/30] Try fixing missing pillow types --- stubs/D3DShot/METADATA.toml | 2 +- stubs/D3DShot/d3dshot/capture_output.pyi | 6 +++--- .../d3dshot/capture_outputs/numpy_capture_output.pyi | 4 ++-- .../capture_outputs/numpy_float_capture_output.pyi | 4 ++-- .../d3dshot/capture_outputs/pil_capture_output.pyi | 8 ++++---- .../d3dshot/capture_outputs/pytorch_capture_output.pyi | 4 ++-- .../capture_outputs/pytorch_float_capture_output.pyi | 4 ++-- .../capture_outputs/pytorch_float_gpu_capture_output.pyi | 8 ++++---- .../capture_outputs/pytorch_gpu_capture_output.pyi | 8 ++++---- stubs/D3DShot/d3dshot/d3dshot.pyi | 2 +- stubs/D3DShot/d3dshot/display.pyi | 5 ++--- stubs/D3DShot/d3dshot/dll/dxgi.pyi | 2 +- 12 files changed, 28 insertions(+), 29 deletions(-) diff --git a/stubs/D3DShot/METADATA.toml b/stubs/D3DShot/METADATA.toml index a435aebff9df..beb02b01908b 100644 --- a/stubs/D3DShot/METADATA.toml +++ b/stubs/D3DShot/METADATA.toml @@ -1,5 +1,5 @@ version = "0.1.*" -requires = ["numpy", "torch", "comtypes"] +requires = ["types-Pillow"] [tool.stubtest] ignore_missing_stub = false diff --git a/stubs/D3DShot/d3dshot/capture_output.pyi b/stubs/D3DShot/d3dshot/capture_output.pyi index d9d654d505c2..5091c9dce2db 100644 --- a/stubs/D3DShot/d3dshot/capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_output.pyi @@ -2,10 +2,10 @@ import enum from _typeshed import Incomplete from typing_extensions import TypeAlias -from PIL.Image import Image +from PIL import Image _Frame: TypeAlias = Incomplete -# _Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | _Tensor +# _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | _Tensor _Pointer: TypeAlias = Incomplete class CaptureOutputs(enum.Enum): @@ -25,5 +25,5 @@ class CaptureOutput: def process( self, pointer: _Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int ) -> _Frame: ... - def to_pil(self, frame: _Frame) -> Image: ... + def to_pil(self, frame: _Frame) -> Image.Image: ... def stack(self, frames: list[_Frame], stack_dimension) -> _Frame: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi index 656e69bac140..07a51f112ba5 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi @@ -2,7 +2,7 @@ from _typeshed import Incomplete from typing_extensions import TypeAlias from d3dshot.capture_output import CaptureOutput as CaptureOutput -from PIL.Image import Image +from PIL import Image # TODO: Complete types once we can import non-types dependencies # See: https://github.com/python/typeshed/issues/5768 @@ -17,5 +17,5 @@ class NumpyCaptureOutput(CaptureOutput): def process( self, pointer: _Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int ) -> NDArray: ... - def to_pil(self, frame: NDArray) -> Image: ... + def to_pil(self, frame: NDArray) -> Image.Image: ... def stack(self, frames: list[NDArray] | NDArray, stack_dimension: int) -> NDArray: ... 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 734e489b29ac..051bdc3614bc 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/numpy_float_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/numpy_float_capture_output.pyi @@ -2,7 +2,7 @@ from _typeshed import Incomplete from typing_extensions import TypeAlias from d3dshot.capture_output import CaptureOutput as CaptureOutput -from PIL.Image import Image +from PIL import Image # TODO: Complete types once we can import non-types dependencies # See: https://github.com/python/typeshed/issues/5768 @@ -17,5 +17,5 @@ class NumpyFloatCaptureOutput(CaptureOutput): def process( self, pointer: _Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int ) -> NDArray: ... - def to_pil(self, frame: NDArray) -> Image: ... + def to_pil(self, frame: NDArray) -> Image.Image: ... def stack(self, frames: list[NDArray] | NDArray, stack_dimension: int) -> NDArray: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi index 8c13fa23c8f2..94aa991d6963 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi @@ -2,7 +2,7 @@ from _typeshed import Incomplete from typing_extensions import TypeAlias from d3dshot.capture_output import CaptureOutput as CaptureOutput -from PIL.Image import Image +from PIL import Image _Pointer: TypeAlias = Incomplete @@ -10,6 +10,6 @@ class PILCaptureOutput(CaptureOutput): def __init__(self) -> None: ... def process( self, pointer: _Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int - ) -> Image: ... - def to_pil(self, frame: Image) -> Image: ... - def stack(self, frames: list[Image], stack_dimension: int) -> list[Image]: ... + ) -> Image.Image: ... + def to_pil(self, frame: Image.Image) -> Image.Image: ... + def stack(self, frames: list[Image.Image], stack_dimension: int) -> list[Image.Image]: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi index f36166f3b871..d687ae5e2067 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi @@ -2,7 +2,7 @@ from _typeshed import Incomplete from typing_extensions import TypeAlias from d3dshot.capture_output import CaptureOutput as CaptureOutput -from PIL.Image import Image +from PIL import Image # TODO: Complete types once we can import non-types dependencies # See: https://github.com/python/typeshed/issues/5768 @@ -15,5 +15,5 @@ class PytorchCaptureOutput(CaptureOutput): def process( self, pointer: _Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int ) -> _Tensor: ... - def to_pil(self, frame: _Tensor) -> Image: ... + def to_pil(self, frame: _Tensor) -> Image.Image: ... def stack(self, frames: list[_Tensor], stack_dimension: int) -> _Tensor: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_capture_output.pyi index ef9c93c0e005..1e9b3c20310e 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_capture_output.pyi @@ -2,7 +2,7 @@ from _typeshed import Incomplete from typing_extensions import TypeAlias from d3dshot.capture_output import CaptureOutput as CaptureOutput -from PIL.Image import Image +from PIL import Image # TODO: Complete types once we can import non-types dependencies # See: https://github.com/python/typeshed/issues/5768 @@ -15,5 +15,5 @@ class PytorchFloatCaptureOutput(CaptureOutput): def process( self, pointer: _Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int ) -> _Tensor: ... - def to_pil(self, frame: _Tensor) -> Image: ... + def to_pil(self, frame: _Tensor) -> Image.Image: ... def stack(self, frames: list[_Tensor], stack_dimension: int) -> _Tensor: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi index 69a9eadc6641..d8ad62977fac 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi @@ -2,20 +2,20 @@ from _typeshed import Incomplete from typing_extensions import TypeAlias from d3dshot.capture_output import CaptureOutput as CaptureOutput -from PIL.Image import Image +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 device, Tensor _Tensor: TypeAlias = Incomplete -_device: TypeAlias = Incomplete +_Device: TypeAlias = Incomplete _Pointer: TypeAlias = Incomplete class PytorchFloatGPUCaptureOutput(CaptureOutput): - device: _device + device: _Device def __init__(self) -> None: ... def process( self, pointer: _Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int ) -> _Tensor: ... - def to_pil(self, frame: _Tensor) -> Image: ... + def to_pil(self, frame: _Tensor) -> Image.Image: ... def stack(self, frames: list[_Tensor], stack_dimension: int) -> _Tensor: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi index 2e1f3f66eec1..e06b881912d2 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi @@ -2,21 +2,21 @@ from _typeshed import Incomplete from typing_extensions import TypeAlias from d3dshot.capture_output import CaptureOutput as CaptureOutput -from PIL.Image import Image +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 device, Tensor _Tensor: TypeAlias = Incomplete -_device: TypeAlias = Incomplete +_Device: TypeAlias = Incomplete _Pointer: TypeAlias = Incomplete class PytorchGPUCaptureOutput(CaptureOutput): - device: _device + device: _Device def __init__(self) -> None: ... def process( self, pointer: _Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int ) -> _Tensor: ... - def to_pil(self, frame: _Tensor) -> Image: ... + def to_pil(self, frame: _Tensor) -> Image.Image: ... def stack(self, frames: list[_Tensor], stack_dimension: int): ... diff --git a/stubs/D3DShot/d3dshot/d3dshot.pyi b/stubs/D3DShot/d3dshot/d3dshot.pyi index 6eefd855b620..777412f9357b 100644 --- a/stubs/D3DShot/d3dshot/d3dshot.pyi +++ b/stubs/D3DShot/d3dshot/d3dshot.pyi @@ -6,7 +6,7 @@ from d3dshot.capture_output import CaptureOutput as CaptureOutput, CaptureOutput from d3dshot.display import Display as Display _Frame: TypeAlias = Incomplete -# _Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | _Tensor +# _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | _Tensor class D3DShot: displays: list[Display] diff --git a/stubs/D3DShot/d3dshot/display.pyi b/stubs/D3DShot/d3dshot/display.pyi index a237d6fe496e..eef51e043246 100644 --- a/stubs/D3DShot/d3dshot/display.pyi +++ b/stubs/D3DShot/d3dshot/display.pyi @@ -1,10 +1,9 @@ from _typeshed import Incomplete from collections.abc import Callable -from typing import Literal -from typing_extensions import TypeAlias +from typing_extensions import Literal, TypeAlias _Frame: TypeAlias = Incomplete -# _Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | _Tensor +# _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | _Tensor _Pointer: TypeAlias = Incomplete class Display: diff --git a/stubs/D3DShot/d3dshot/dll/dxgi.pyi b/stubs/D3DShot/d3dshot/dll/dxgi.pyi index eb7bcccc2d91..2602d473da32 100644 --- a/stubs/D3DShot/d3dshot/dll/dxgi.pyi +++ b/stubs/D3DShot/d3dshot/dll/dxgi.pyi @@ -10,7 +10,7 @@ from typing_extensions import TypeAlias _IUnknown: TypeAlias = Incomplete _Frame: TypeAlias = Incomplete -# _Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | Tensor +# _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | Tensor _Pointer: TypeAlias = Incomplete class LUID(ctypes.Structure): ... From 84fc12a248b89ff3db5a25e3c3a83dcf254ab323 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 31 Aug 2022 10:37:05 -0400 Subject: [PATCH 08/30] stubtest --- stubs/D3DShot/@tests/stubtest_allowlist.txt | 16 ++++++++++++++++ stubs/D3DShot/d3dshot/dll/user32.pyi | 9 ++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 stubs/D3DShot/@tests/stubtest_allowlist.txt diff --git a/stubs/D3DShot/@tests/stubtest_allowlist.txt b/stubs/D3DShot/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000000..09a9f30f7bfc --- /dev/null +++ b/stubs/D3DShot/@tests/stubtest_allowlist.txt @@ -0,0 +1,16 @@ +# Cannot import COMError on linux, which the CI runs on +# ImportError: cannot import name 'COMError' from '_ctypes' +d3dshot +d3dshot.capture_output +d3dshot.capture_outputs +d3dshot.capture_outputs.numpy_capture_output +d3dshot.capture_outputs.numpy_float_capture_output +d3dshot.capture_outputs.pil_capture_output +d3dshot.capture_outputs.pytorch_capture_output +d3dshot.capture_outputs.pytorch_float_capture_output +d3dshot.capture_outputs.pytorch_float_gpu_capture_output +d3dshot.capture_outputs.pytorch_gpu_capture_output +d3dshot.d3dshot +d3dshot.display +d3dshot.dll.d3d +d3dshot.dll.dxgi diff --git a/stubs/D3DShot/d3dshot/dll/user32.pyi b/stubs/D3DShot/d3dshot/dll/user32.pyi index 96523dc7e0a4..56e109d1e4a5 100644 --- a/stubs/D3DShot/d3dshot/dll/user32.pyi +++ b/stubs/D3DShot/d3dshot/dll/user32.pyi @@ -1,10 +1,17 @@ import ctypes from _typeshed import Incomplete +from ctypes import wintypes from typing_extensions import TypeAlias _Pointer: TypeAlias = Incomplete -class DISPLAY_DEVICE(ctypes.Structure): ... +class DISPLAY_DEVICE(ctypes.Structure): + cb: wintypes.DWORD + DeviceName: wintypes.WCHAR + DeviceString: wintypes.WCHAR + StateFlags: wintypes.DWORD + DeviceID: wintypes.WCHAR + DeviceKey: wintypes.WCHAR def get_display_device_name_mapping() -> dict[str, tuple[str, bool]]: ... def get_hmonitor_by_point(x: int, y: int) -> _Pointer: ... # ctypes.windll.user32.MonitorFromPoint(point, 0) From d34640349d0550f38cb915a4f7b270a561431b39 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 4 Sep 2022 16:56:25 -0400 Subject: [PATCH 09/30] Filled in all ctypes --- .flake8 | 3 +- stubs/D3DShot/d3dshot/capture_output.pyi | 2 +- .../capture_outputs/numpy_capture_output.pyi | 12 +- .../numpy_float_capture_output.pyi | 12 +- .../capture_outputs/pil_capture_output.pyi | 4 +- .../pytorch_capture_output.pyi | 4 +- .../pytorch_float_capture_output.pyi | 4 +- .../pytorch_float_gpu_capture_output.pyi | 4 +- .../pytorch_gpu_capture_output.pyi | 4 +- stubs/D3DShot/d3dshot/d3dshot.pyi | 4 + stubs/D3DShot/d3dshot/display.pyi | 3 +- stubs/D3DShot/d3dshot/dll/d3d.pyi | 202 +++++++++++++++++- stubs/D3DShot/d3dshot/dll/dxgi.pyi | 144 +++++++++++-- 13 files changed, 345 insertions(+), 57 deletions(-) diff --git a/.flake8 b/.flake8 index de09afb1411f..ac705d7f8730 100644 --- a/.flake8 +++ b/.flake8 @@ -7,6 +7,7 @@ # Some rules are considered irrelevant to stub files: # E701 multiple statements on one line (colon) -- disallows "..." on the same line +# E704 multiple statements on one line (def) -- disallows "..." on the same line # F401 imported but unused -- does not recognize re-exports # https://github.com/PyCQA/pyflakes/issues/474 # F822 undefined name in __all__ -- flake8 does not recognize 'foo: Any' @@ -29,7 +30,7 @@ [flake8] per-file-ignores = *.py: E203, E301, E302, E305, E501 - *.pyi: E301, E302, E305, E501, E701, E741, NQA102, F401, F403, F405, F822, Y037 + *.pyi: E301, E302, E305, E501, E701, E704, E741, NQA102, F401, F403, F405, F822, Y037 # Since typing.pyi defines "overload" this is not recognized by flake8 as typing.overload. # Unfortunately, flake8 does not allow to "noqa" just a specific error inside the file itself. # https://github.com/PyCQA/flake8/issues/1079 diff --git a/stubs/D3DShot/d3dshot/capture_output.pyi b/stubs/D3DShot/d3dshot/capture_output.pyi index 5091c9dce2db..92138878f25d 100644 --- a/stubs/D3DShot/d3dshot/capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_output.pyi @@ -23,7 +23,7 @@ class CaptureOutput: backend: CaptureOutput def __init__(self, backend: CaptureOutputs = ...) -> None: ... def process( - self, pointer: _Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + self, pointer: _Pointer, pitch: int, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int ) -> _Frame: ... def to_pil(self, frame: _Frame) -> Image.Image: ... def stack(self, frames: list[_Frame], stack_dimension) -> _Frame: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi index 07a51f112ba5..ba2edeb85b2a 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi @@ -1,7 +1,7 @@ from _typeshed import Incomplete from typing_extensions import TypeAlias -from d3dshot.capture_output import CaptureOutput as CaptureOutput +from d3dshot.capture_output import CaptureOutput from PIL import Image # TODO: Complete types once we can import non-types dependencies @@ -9,13 +9,13 @@ from PIL import Image # import numpy as np # import numpy.typing as npt # NDArray: TypeAlias = npt.NDArray[np.int32] -NDArray: TypeAlias = Incomplete +_NDArray: TypeAlias = Incomplete _Pointer: TypeAlias = Incomplete class NumpyCaptureOutput(CaptureOutput): def __init__(self) -> None: ... def process( - self, pointer: _Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int - ) -> NDArray: ... - def to_pil(self, frame: NDArray) -> Image.Image: ... - def stack(self, frames: list[NDArray] | NDArray, stack_dimension: int) -> NDArray: ... + self, pointer: _Pointer, pitch: int, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + ) -> _NDArray: ... + def to_pil(self, frame: _NDArray) -> Image.Image: ... + def stack(self, frames: list[_NDArray] | _NDArray, stack_dimension: int) -> _NDArray: ... 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 051bdc3614bc..383b4681281c 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/numpy_float_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/numpy_float_capture_output.pyi @@ -1,7 +1,7 @@ from _typeshed import Incomplete from typing_extensions import TypeAlias -from d3dshot.capture_output import CaptureOutput as CaptureOutput +from d3dshot.capture_output import CaptureOutput from PIL import Image # TODO: Complete types once we can import non-types dependencies @@ -9,13 +9,13 @@ from PIL import Image # import numpy as np # import numpy.typing as npt # NDArray: TypeAlias = npt.NDArray[np.float32] -NDArray: TypeAlias = Incomplete +_NDArray: TypeAlias = Incomplete _Pointer: TypeAlias = Incomplete class NumpyFloatCaptureOutput(CaptureOutput): def __init__(self) -> None: ... def process( - self, pointer: _Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int - ) -> NDArray: ... - def to_pil(self, frame: NDArray) -> Image.Image: ... - def stack(self, frames: list[NDArray] | NDArray, stack_dimension: int) -> NDArray: ... + self, pointer: _Pointer, pitch: int, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + ) -> _NDArray: ... + def to_pil(self, frame: _NDArray) -> Image.Image: ... + def stack(self, frames: list[_NDArray] | _NDArray, stack_dimension: int) -> _NDArray: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi index 94aa991d6963..2eef26134688 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi @@ -1,7 +1,7 @@ from _typeshed import Incomplete from typing_extensions import TypeAlias -from d3dshot.capture_output import CaptureOutput as CaptureOutput +from d3dshot.capture_output import CaptureOutput from PIL import Image _Pointer: TypeAlias = Incomplete @@ -9,7 +9,7 @@ _Pointer: TypeAlias = Incomplete class PILCaptureOutput(CaptureOutput): def __init__(self) -> None: ... def process( - self, pointer: _Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + self, pointer: _Pointer, pitch: int, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int ) -> Image.Image: ... def to_pil(self, frame: Image.Image) -> Image.Image: ... def stack(self, frames: list[Image.Image], stack_dimension: int) -> list[Image.Image]: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi index d687ae5e2067..92c755149d9e 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi @@ -1,7 +1,7 @@ from _typeshed import Incomplete from typing_extensions import TypeAlias -from d3dshot.capture_output import CaptureOutput as CaptureOutput +from d3dshot.capture_output import CaptureOutput from PIL import Image # TODO: Complete types once we can import non-types dependencies @@ -13,7 +13,7 @@ _Pointer: TypeAlias = Incomplete class PytorchCaptureOutput(CaptureOutput): def __init__(self) -> None: ... def process( - self, pointer: _Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + self, pointer: _Pointer, pitch: int, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int ) -> _Tensor: ... def to_pil(self, frame: _Tensor) -> Image.Image: ... def stack(self, frames: list[_Tensor], stack_dimension: int) -> _Tensor: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_capture_output.pyi index 1e9b3c20310e..00bff76dae54 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_capture_output.pyi @@ -1,7 +1,7 @@ from _typeshed import Incomplete from typing_extensions import TypeAlias -from d3dshot.capture_output import CaptureOutput as CaptureOutput +from d3dshot.capture_output import CaptureOutput from PIL import Image # TODO: Complete types once we can import non-types dependencies @@ -13,7 +13,7 @@ _Pointer: TypeAlias = Incomplete class PytorchFloatCaptureOutput(CaptureOutput): def __init__(self) -> None: ... def process( - self, pointer: _Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + self, pointer: _Pointer, pitch: int, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int ) -> _Tensor: ... def to_pil(self, frame: _Tensor) -> Image.Image: ... def stack(self, frames: list[_Tensor], stack_dimension: int) -> _Tensor: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi index d8ad62977fac..a2a95c591b9d 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi @@ -1,7 +1,7 @@ from _typeshed import Incomplete from typing_extensions import TypeAlias -from d3dshot.capture_output import CaptureOutput as CaptureOutput +from d3dshot.capture_output import CaptureOutput from PIL import Image # TODO: Complete types once we can import non-types dependencies @@ -15,7 +15,7 @@ class PytorchFloatGPUCaptureOutput(CaptureOutput): device: _Device def __init__(self) -> None: ... def process( - self, pointer: _Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + self, pointer: _Pointer, pitch: int, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int ) -> _Tensor: ... def to_pil(self, frame: _Tensor) -> Image.Image: ... def stack(self, frames: list[_Tensor], stack_dimension: int) -> _Tensor: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi index e06b881912d2..65a3da25bc10 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi @@ -1,7 +1,7 @@ from _typeshed import Incomplete from typing_extensions import TypeAlias -from d3dshot.capture_output import CaptureOutput as CaptureOutput +from d3dshot.capture_output import CaptureOutput from PIL import Image # TODO: Complete types once we can import non-types dependencies @@ -16,7 +16,7 @@ class PytorchGPUCaptureOutput(CaptureOutput): device: _Device def __init__(self) -> None: ... def process( - self, pointer: _Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + self, pointer: _Pointer, pitch: int, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int ) -> _Tensor: ... def to_pil(self, frame: _Tensor) -> Image.Image: ... def stack(self, frames: list[_Tensor], stack_dimension: int): ... diff --git a/stubs/D3DShot/d3dshot/d3dshot.pyi b/stubs/D3DShot/d3dshot/d3dshot.pyi index 777412f9357b..80a25c324e01 100644 --- a/stubs/D3DShot/d3dshot/d3dshot.pyi +++ b/stubs/D3DShot/d3dshot/d3dshot.pyi @@ -1,5 +1,6 @@ from _typeshed import Incomplete from collections import deque +from typing import Any from typing_extensions import TypeAlias from d3dshot.capture_output import CaptureOutput as CaptureOutput, CaptureOutputs as CaptureOutputs @@ -8,6 +9,9 @@ from d3dshot.display import Display as Display _Frame: TypeAlias = Incomplete # _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | _Tensor +class Singleton(type): + def __call__(cls, *args: Any, **kwargs: Any) -> Any: ... + class D3DShot: displays: list[Display] display: Display diff --git a/stubs/D3DShot/d3dshot/display.pyi b/stubs/D3DShot/d3dshot/display.pyi index eef51e043246..a1b994f46178 100644 --- a/stubs/D3DShot/d3dshot/display.pyi +++ b/stubs/D3DShot/d3dshot/display.pyi @@ -36,9 +36,8 @@ class Display: ) -> None: ... def capture( self, - # Incomplete: dxgi_mapped_rect.pBits process_func: Callable[[_Pointer, int, int, int, tuple[int, int, int, int], int], _Frame | None] | None, - region: tuple[int, int, int, int] = ..., + region: tuple[int, int, int, int] | None = ..., ) -> _Frame: ... @classmethod def discover_displays(cls) -> list[Display]: ... diff --git a/stubs/D3DShot/d3dshot/dll/d3d.pyi b/stubs/D3DShot/d3dshot/dll/d3d.pyi index 0ef566ff7fbe..e794f76765f9 100644 --- a/stubs/D3DShot/d3dshot/dll/d3d.pyi +++ b/stubs/D3DShot/d3dshot/dll/d3d.pyi @@ -1,6 +1,7 @@ -import ctypes from _typeshed import Incomplete +from ctypes import HRESULT, Structure, c_int32, c_uint, wintypes from typing_extensions import TypeAlias +from collections.abc import Callable # TODO: Complete types once we can import non-types dependencies # See: https://github.com/python/typeshed/issues/5768 @@ -9,14 +10,197 @@ _IUnknown: TypeAlias = Incomplete _Pointer: TypeAlias = Incomplete -class DXGI_SAMPLE_DESC(ctypes.Structure): ... -class D3D11_BOX(ctypes.Structure): ... -class D3D11_TEXTURE2D_DESC(ctypes.Structure): ... -class ID3D11DeviceChild(_IUnknown): ... -class ID3D11Resource(ID3D11DeviceChild): ... -class ID3D11Texture2D(ID3D11Resource): ... -class ID3D11DeviceContext(ID3D11DeviceChild): ... -class ID3D11Device(_IUnknown): ... +class DXGI_SAMPLE_DESC(Structure): + Count: wintypes.UINT + Quality: wintypes.UINT + +class D3D11_BOX(Structure): + left: wintypes.UINT + top: wintypes.UINT + front: wintypes.UINT + right: wintypes.UINT + bottom: wintypes.UINT + back: wintypes.UINT + +class D3D11_TEXTURE2D_DESC(Structure): + Width: wintypes.UINT + Height: wintypes.UINT + MipLevels: wintypes.UINT + ArraySize: wintypes.UINT + Format: wintypes.UINT + SampleDesc: DXGI_SAMPLE_DESC + Usage: wintypes.UINT + BindFlags: wintypes.UINT + CPUAccessFlags: wintypes.UINT + MiscFlags: wintypes.UINT + +class ID3D11DeviceChild(_IUnknown): + GetDevice: Callable[[], None] + GetPrivateData: Callable[[], HRESULT] + SetPrivateData: Callable[[], HRESULT] + SetPrivateDataInterface: Callable[[], HRESULT] + +class ID3D11Resource(ID3D11DeviceChild): + GetType: Callable[[], None] + SetEvictionPriority: Callable[[], None] + GetEvictionPriority: Callable[[], wintypes.UINT] + +class ID3D11Texture2D(ID3D11Resource): + GetDesc: Callable[[_Pointer], None] + +class ID3D11DeviceContext(ID3D11DeviceChild): + VSSetConstantBuffers: Callable[[], None] + PSSetShaderResources: Callable[[], None] + PSSetShader: Callable[[], None] + PSSetSamplers: Callable[[], None] + VSSetShader: Callable[[], None] + DrawIndexed: Callable[[], None] + Draw: Callable[[], None] + Map: Callable[[], HRESULT] + Unmap: Callable[[], None] + PSSetConstantBuffers: Callable[[], None] + IASetInputLayout: Callable[[], None] + IASetVertexBuffers: Callable[[], None] + IASetIndexBuffer: Callable[[], None] + DrawIndexedInstanced: Callable[[], None] + DrawInstanced: Callable[[], None] + GSSetConstantBuffers: Callable[[], None] + GSSetShader: Callable[[], None] + IASetPrimitiveTopology: Callable[[], None] + VSSetShaderResources: Callable[[], None] + VSSetSamplers: Callable[[], None] + Begin: Callable[[], None] + End: Callable[[], None] + GetData: Callable[[], HRESULT] + SetPredication: Callable[[], None] + GSSetShaderResources: Callable[[], None] + GSSetSamplers: Callable[[], None] + OMSetRenderTargets: Callable[[], None] + OMSetRenderTargetsAndUnorderedAccessViews: Callable[[], None] + OMSetBlendState: Callable[[], None] + OMSetDepthStencilState: Callable[[], None] + SOSetTargets: Callable[[], None] + DrawAuto: Callable[[], None] + DrawIndexedInstancedIndirect: Callable[[], None] + DrawInstancedIndirect: Callable[[], None] + Dispatch: Callable[[], None] + DispatchIndirect: Callable[[], None] + RSSetState: Callable[[], None] + RSSetViewports: Callable[[], None] + RSSetScissorRects: Callable[[], None] + CopySubresourceRegion: Callable[ + [_Pointer, wintypes.UINT, wintypes.UINT, wintypes.UINT, wintypes.UINT, _Pointer, wintypes.UINT, _Pointer], None + ] + CopyResource: Callable[[_Pointer, _Pointer], None] + UpdateSubresource: Callable[[], None] + CopyStructureCount: Callable[[], None] + ClearRenderTargetView: Callable[[], None] + ClearUnorderedAccessViewUint: Callable[[], None] + ClearUnorderedAccessViewFloat: Callable[[], None] + ClearDepthStencilView: Callable[[], None] + GenerateMips: Callable[[], None] + SetResourceMinLOD: Callable[[], None] + GetResourceMinLOD: Callable[[], wintypes.FLOAT] + ResolveSubresource: Callable[[], None] + ExecuteCommandList: Callable[[], None] + HSSetShaderResources: Callable[[], None] + HSSetShader: Callable[[], None] + HSSetSamplers: Callable[[], None] + HSSetConstantBuffers: Callable[[], None] + DSSetShaderResources: Callable[[], None] + DSSetShader: Callable[[], None] + DSSetSamplers: Callable[[], None] + DSSetConstantBuffers: Callable[[], None] + CSSetShaderResources: Callable[[], None] + CSSetUnorderedAccessViews: Callable[[], None] + CSSetShader: Callable[[], None] + CSSetSamplers: Callable[[], None] + CSSetConstantBuffers: Callable[[], None] + VSGetConstantBuffers: Callable[[], None] + PSGetShaderResources: Callable[[], None] + PSGetShader: Callable[[], None] + PSGetSamplers: Callable[[], None] + VSGetShader: Callable[[], None] + PSGetConstantBuffers: Callable[[], None] + IAGetInputLayout: Callable[[], None] + IAGetVertexBuffers: Callable[[], None] + IAGetIndexBuffer: Callable[[], None] + GSGetConstantBuffers: Callable[[], None] + GSGetShader: Callable[[], None] + IAGetPrimitiveTopology: Callable[[], None] + VSGetShaderResources: Callable[[], None] + VSGetSamplers: Callable[[], None] + GetPredication: Callable[[], None] + GSGetShaderResources: Callable[[], None] + GSGetSamplers: Callable[[], None] + OMGetRenderTargets: Callable[[], None] + OMGetRenderTargetsAndUnorderedAccessViews: Callable[[], None] + OMGetBlendState: Callable[[], None] + OMGetDepthStencilState: Callable[[], None] + SOGetTargets: Callable[[], None] + RSGetState: Callable[[], None] + RSGetViewports: Callable[[], None] + RSGetScissorRects: Callable[[], None] + HSGetShaderResources: Callable[[], None] + HSGetShader: Callable[[], None] + HSGetSamplers: Callable[[], None] + HSGetConstantBuffers: Callable[[], None] + DSGetShaderResources: Callable[[], None] + DSGetShader: Callable[[], None] + DSGetSamplers: Callable[[], None] + DSGetConstantBuffers: Callable[[], None] + CSGetShaderResources: Callable[[], None] + CSGetUnorderedAccessViews: Callable[[], None] + CSGetShader: Callable[[], None] + CSGetSamplers: Callable[[], None] + CSGetConstantBuffers: Callable[[], None] + ClearState: Callable[[], None] + Flush: Callable[[], None] + GetType: Callable[[], None] + GetContextFlags: Callable[[], wintypes.UINT] + FinishCommandList: Callable[[], HRESULT] + +class ID3D11Device(_IUnknown): + CreateBuffer: Callable[[], HRESULT] + CreateTexture1D: Callable[[], HRESULT] + CreateTexture2D: Callable[[_Pointer, _Pointer, _Pointer], HRESULT] + CreateTexture3D: Callable[[], HRESULT] + CreateShaderResourceView: Callable[[], HRESULT] + CreateUnorderedAccessView: Callable[[], HRESULT] + CreateRenderTargetView: Callable[[], HRESULT] + CreateDepthStencilView: Callable[[], HRESULT] + CreateInputLayout: Callable[[], HRESULT] + CreateVertexShader: Callable[[], HRESULT] + CreateGeometryShader: Callable[[], HRESULT] + CreateGeometryShaderWithStreamOutput: Callable[[], HRESULT] + CreatePixelShader: Callable[[], HRESULT] + CreateHullShader: Callable[[], HRESULT] + CreateDomainShader: Callable[[], HRESULT] + CreateComputeShader: Callable[[], HRESULT] + CreateClassLinkage: Callable[[], HRESULT] + CreateBlendState: Callable[[], HRESULT] + CreateDepthStencilState: Callable[[], HRESULT] + CreateRasterizerState: Callable[[], HRESULT] + CreateSamplerState: Callable[[], HRESULT] + CreateQuery: Callable[[], HRESULT] + CreatePredicate: Callable[[], HRESULT] + CreateCounter: Callable[[], HRESULT] + CreateDeferredContext: Callable[[], HRESULT] + OpenSharedResource: Callable[[], HRESULT] + CheckFormatSupport: Callable[[], HRESULT] + CheckMultisampleQualityLevels: Callable[[], HRESULT] + CheckCounterInfo: Callable[[], HRESULT] + CheckCounter: Callable[[], HRESULT] + CheckFeatureSupport: Callable[[], HRESULT] + GetPrivateData: Callable[[], HRESULT] + SetPrivateData: Callable[[], HRESULT] + SetPrivateDataInterface: Callable[[], HRESULT] + GetFeatureLevel: Callable[[], c_int32] + GetCreationFlags: Callable[[], c_uint] + GetDeviceRemovedReason: Callable[[], HRESULT] + GetImmediateContext: Callable[[_Pointer], None] + SetExceptionMode: Callable[[], HRESULT] + GetExceptionMode: Callable[[], c_uint] def initialize_d3d_device(dxgi_adapter: _Pointer) -> tuple[_Pointer, _Pointer]: ... def describe_d3d11_texture_2d(d3d11_texture_2d: _Pointer) -> D3D11_TEXTURE2D_DESC: ... diff --git a/stubs/D3DShot/d3dshot/dll/dxgi.pyi b/stubs/D3DShot/d3dshot/dll/dxgi.pyi index 2602d473da32..d6adcc163ea2 100644 --- a/stubs/D3DShot/d3dshot/dll/dxgi.pyi +++ b/stubs/D3DShot/d3dshot/dll/dxgi.pyi @@ -1,37 +1,137 @@ -import ctypes from _typeshed import Incomplete from collections.abc import Callable +from ctypes import HRESULT, _CArgObject, _CData, Array, Structure, c_uint, c_ulong, wintypes from typing_extensions import TypeAlias # TODO: Complete types once we can import non-types dependencies # See: https://github.com/python/typeshed/issues/5768 # from torch import Tensor # import comtypes -_IUnknown: TypeAlias = Incomplete - +# import numpy.typing as npt +# _IUnknown: TypeAlias = Incomplete +_STDMETHOD: TypeAlias = Callable[[Callable[[_CData, int], _CArgObject]], None] _Frame: TypeAlias = Incomplete # _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | Tensor + +# From comtypes.IUnknown +class _IUnknown: + def QueryInterface(self, interface: _Pointer, iid: _Pointer | None = ...) -> HRESULT: ... + def AddRef(self) -> c_ulong: ... + def Release(self) -> c_ulong: ... + _Pointer: TypeAlias = Incomplete -class LUID(ctypes.Structure): ... -class DXGI_ADAPTER_DESC1(ctypes.Structure): ... -class DXGI_OUTPUT_DESC(ctypes.Structure): ... -class DXGI_OUTDUPL_POINTER_POSITION(ctypes.Structure): ... -class DXGI_OUTDUPL_FRAME_INFO(ctypes.Structure): ... -class DXGI_MAPPED_RECT(ctypes.Structure): ... -class IDXGIObject(_IUnknown): ... -class IDXGIDeviceSubObject(IDXGIObject): ... -class IDXGIResource(IDXGIDeviceSubObject): ... -class IDXGISurface(IDXGIDeviceSubObject): ... -class IDXGIOutputDuplication(IDXGIObject): ... -class IDXGIOutput(IDXGIObject): ... -class IDXGIOutput1(IDXGIOutput): ... -class IDXGIAdapter(IDXGIObject): ... -class IDXGIAdapter1(IDXGIAdapter): ... -class IDXGIFactory(IDXGIObject): ... -class IDXGIFactory1(IDXGIFactory): ... - -def initialize_dxgi_factory() -> _Pointer: ... # ctypes.POINTER(IDXGIFactory1)(handle.value) +class LUID(Structure): + LowPart: wintypes.DWORD + HighPart: wintypes.LONG + +class DXGI_ADAPTER_DESC1(Structure): + Description: Array[wintypes.WCHAR] + VendorId: wintypes.UINT + DeviceId: wintypes.UINT + SubSysId: wintypes.UINT + Revision: wintypes.UINT + DedicatedVideoMemory: wintypes.ULARGE_INTEGER + DedicatedSystemMemory: wintypes.ULARGE_INTEGER + SharedSystemMemory: wintypes.ULARGE_INTEGER + AdapterLuid: LUID + Flags: wintypes.UINT + +class DXGI_OUTPUT_DESC(Structure): + DeviceName: Array[wintypes.WCHAR] + DesktopCoordinates: wintypes.RECT + AttachedToDesktop: wintypes.BOOL + Rotation: wintypes.UINT + Monitor: wintypes.HMONITOR + +class DXGI_OUTDUPL_POINTER_POSITION(Structure): + Position: wintypes.POINT + Visible: wintypes.BOOL + +class DXGI_OUTDUPL_FRAME_INFO(Structure): + LastPresentTime: wintypes.LARGE_INTEGER + LastMouseUpdateTime: wintypes.LARGE_INTEGER + AccumulatedFrames: wintypes.UINT + RectsCoalesced: wintypes.BOOL + ProtectedContentMaskedOut: wintypes.BOOL + PointerPosition: DXGI_OUTDUPL_POINTER_POSITION + TotalMetadataBufferSize: wintypes.UINT + PointerShapeBufferSize: wintypes.UINT + +class DXGI_MAPPED_RECT(Structure): + Pitch: wintypes.INT + pBits: _Pointer + +class IDXGIObject(_IUnknown): + SetPrivateData: Callable[[], HRESULT] + SetPrivateDataInterface: Callable[[], HRESULT] + GetPrivateData: Callable[[], HRESULT] + GetParent: Callable[[], HRESULT] + +class IDXGIDeviceSubObject(IDXGIObject): + GetDevice: Callable[[], HRESULT] + +class IDXGIResource(IDXGIDeviceSubObject): + GetSharedHandle: Callable[[], HRESULT] + GetUsage: Callable[[], HRESULT] + SetEvictionPriority: Callable[[], HRESULT] + GetEvictionPriority: Callable[[], HRESULT] + +class IDXGISurface(IDXGIDeviceSubObject): + GetDesc: Callable[[], HRESULT] + Map: Callable[[_Pointer, wintypes.UINT], HRESULT] + Unmap: Callable[[], HRESULT] + +class IDXGIOutputDuplication(IDXGIObject): + GetDesc: Callable[[], None] + AcquireNextFrame: Callable[[wintypes.UINT, _Pointer, _Pointer], HRESULT] + GetFrameDirtyRects: Callable[[], HRESULT] + GetFrameMoveRects: Callable[[], HRESULT] + GetFramePointerShape: Callable[[], HRESULT] + MapDesktopSurface: Callable[[], HRESULT] + UnMapDesktopSurface: Callable[[], HRESULT] + ReleaseFrame: Callable[[], HRESULT] + +class IDXGIOutput(IDXGIObject): + GetDesc: Callable[[_Pointer], HRESULT] + GetDisplayModeList: Callable[[], HRESULT] + FindClosestMatchingMode: Callable[[], HRESULT] + WaitForVBlank: Callable[[], HRESULT] + TakeOwnership: Callable[[], HRESULT] + ReleaseOwnership: Callable[[], None] + GetGammaControlCapabilities: Callable[[], HRESULT] + SetGammaControl: Callable[[], HRESULT] + GetGammaControl: Callable[[], HRESULT] + SetDisplaySurface: Callable[[], HRESULT] + GetDisplaySurfaceData: Callable[[], HRESULT] + GetFrameStatistics: Callable[[], HRESULT] + +class IDXGIOutput1(IDXGIOutput): + GetDisplayModeList1: Callable[[], HRESULT] + FindClosestMatchingMode1: Callable[[], HRESULT] + GetDisplaySurfaceData1: Callable[[], HRESULT] + DuplicateOutput: Callable[[_Pointer, _Pointer], HRESULT] + +class IDXGIAdapter(IDXGIObject): + EnumOutputs: Callable[[wintypes.UINT, _Pointer], HRESULT] + GetDesc: Callable[[], HRESULT] + CheckInterfaceSupport: Callable[[], HRESULT] + +class IDXGIAdapter1(IDXGIAdapter): + GetDesc1: Callable[[_Pointer], HRESULT] + +class IDXGIFactory(IDXGIObject): + EnumAdapters: Callable[[], HRESULT] + MakeWindowAssociation: Callable[[], HRESULT] + GetWindowAssociation: Callable[[], HRESULT] + CreateSwapChain: Callable[[], HRESULT] + CreateSoftwareAdapter: Callable[[], HRESULT] + +class IDXGIFactory1(IDXGIFactory): + EnumAdapters1: Callable[[c_uint, _Pointer], HRESULT] + IsCurrent: Callable[[], wintypes.BOOL] + +def initialize_dxgi_factory() -> _Pointer: ... def discover_dxgi_adapters(dxgi_factory: _Pointer) -> list[_Pointer]: ... def describe_dxgi_adapter(dxgi_adapter: _Pointer) -> _Pointer: ... def discover_dxgi_outputs(dxgi_adapter: _Pointer) -> list[_Pointer]: ... From c197b154b2ff1b4a9ca4f890cd0de691228915fc Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 4 Sep 2022 19:09:44 -0400 Subject: [PATCH 10/30] Completed all _Pointer --- stubs/D3DShot/d3dshot/capture_output.pyi | 13 ++++- .../capture_outputs/numpy_capture_output.pyi | 13 ++++- .../numpy_float_capture_output.pyi | 22 +------ .../capture_outputs/pil_capture_output.pyi | 17 ++++-- .../pytorch_capture_output.pyi | 11 +++- .../pytorch_float_capture_output.pyi | 20 +------ .../pytorch_float_gpu_capture_output.pyi | 22 +------ .../pytorch_gpu_capture_output.pyi | 23 +------- stubs/D3DShot/d3dshot/d3dshot.pyi | 3 +- stubs/D3DShot/d3dshot/display.pyi | 13 +++-- stubs/D3DShot/d3dshot/dll/d3d.pyi | 23 ++++---- stubs/D3DShot/d3dshot/dll/dxgi.pyi | 57 ++++++++++++------- stubs/D3DShot/d3dshot/dll/user32.pyi | 6 +- 13 files changed, 106 insertions(+), 137 deletions(-) diff --git a/stubs/D3DShot/d3dshot/capture_output.pyi b/stubs/D3DShot/d3dshot/capture_output.pyi index 92138878f25d..c4f7bc129e37 100644 --- a/stubs/D3DShot/d3dshot/capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_output.pyi @@ -1,12 +1,12 @@ +from ctypes import _CVoidConstPLike import enum from _typeshed import Incomplete from typing_extensions import TypeAlias from PIL import Image -_Frame: TypeAlias = Incomplete +_Frame: TypeAlias = Image.Image | Incomplete # _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | _Tensor -_Pointer: TypeAlias = Incomplete class CaptureOutputs(enum.Enum): PIL: int @@ -23,7 +23,14 @@ class CaptureOutput: backend: CaptureOutput def __init__(self, backend: CaptureOutputs = ...) -> None: ... def process( - self, pointer: _Pointer, pitch: int, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + self, + pointer: _CVoidConstPLike, + pitch: int, + size: int, + width: int, + height: int, + region: tuple[int, int, int, int], + rotation: int, ) -> _Frame: ... def to_pil(self, frame: _Frame) -> Image.Image: ... def stack(self, frames: list[_Frame], stack_dimension) -> _Frame: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi index ba2edeb85b2a..d3f43794c045 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi @@ -1,4 +1,5 @@ from _typeshed import Incomplete +from ctypes import _CVoidConstPLike from typing_extensions import TypeAlias from d3dshot.capture_output import CaptureOutput @@ -8,14 +9,20 @@ from PIL import Image # See: https://github.com/python/typeshed/issues/5768 # import numpy as np # import numpy.typing as npt -# NDArray: TypeAlias = npt.NDArray[np.int32] +# _NDArray: TypeAlias = npt.NDArray[np.int32] _NDArray: TypeAlias = Incomplete -_Pointer: TypeAlias = Incomplete class NumpyCaptureOutput(CaptureOutput): def __init__(self) -> None: ... def process( - self, pointer: _Pointer, pitch: int, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + self, + pointer: _CVoidConstPLike, + pitch: int, + size: int, + width: int, + height: int, + region: tuple[int, int, int, int], + rotation: int, ) -> _NDArray: ... def to_pil(self, frame: _NDArray) -> Image.Image: ... def stack(self, frames: list[_NDArray] | _NDArray, stack_dimension: int) -> _NDArray: ... 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 383b4681281c..677785053e16 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/numpy_float_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/numpy_float_capture_output.pyi @@ -1,21 +1,3 @@ -from _typeshed import Incomplete -from typing_extensions import TypeAlias +from d3dshot.capture_outputs.numpy_capture_output import NumpyCaptureOutput -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 -# import numpy as np -# import numpy.typing as npt -# NDArray: TypeAlias = npt.NDArray[np.float32] -_NDArray: TypeAlias = Incomplete -_Pointer: TypeAlias = Incomplete - -class NumpyFloatCaptureOutput(CaptureOutput): - def __init__(self) -> None: ... - def process( - self, pointer: _Pointer, pitch: int, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int - ) -> _NDArray: ... - def to_pil(self, frame: _NDArray) -> Image.Image: ... - def stack(self, frames: list[_NDArray] | _NDArray, stack_dimension: int) -> _NDArray: ... +class NumpyFloatCaptureOutput(NumpyCaptureOutput): ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi index 2eef26134688..3ee8ea291238 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi @@ -1,15 +1,22 @@ -from _typeshed import Incomplete -from typing_extensions import TypeAlias +from ctypes import _CVoidConstPLike +from typing import TypeVar from d3dshot.capture_output import CaptureOutput from PIL import Image -_Pointer: TypeAlias = Incomplete +_T = TypeVar("_T") class PILCaptureOutput(CaptureOutput): def __init__(self) -> None: ... def process( - self, pointer: _Pointer, pitch: int, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + self, + pointer: _CVoidConstPLike, + pitch: int, + size: int, + width: int, + height: int, + region: tuple[int, int, int, int], + rotation: int, ) -> Image.Image: ... - def to_pil(self, frame: Image.Image) -> Image.Image: ... + def to_pil(self, frame: _T) -> _T: ... def stack(self, frames: list[Image.Image], stack_dimension: int) -> list[Image.Image]: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi index 92c755149d9e..51733009706b 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi @@ -1,4 +1,5 @@ from _typeshed import Incomplete +from ctypes import _CVoidConstPLike from typing_extensions import TypeAlias from d3dshot.capture_output import CaptureOutput @@ -8,12 +9,18 @@ from PIL import Image # See: https://github.com/python/typeshed/issues/5768 # from torch import Tensor _Tensor: TypeAlias = Incomplete -_Pointer: TypeAlias = Incomplete class PytorchCaptureOutput(CaptureOutput): def __init__(self) -> None: ... def process( - self, pointer: _Pointer, pitch: int, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + self, + pointer: _CVoidConstPLike, + pitch: int, + size: int, + width: int, + height: int, + region: tuple[int, int, int, int], + rotation: int, ) -> _Tensor: ... def to_pil(self, frame: _Tensor) -> Image.Image: ... def stack(self, frames: list[_Tensor], stack_dimension: int) -> _Tensor: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_capture_output.pyi index 00bff76dae54..53e7a73d7a51 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_capture_output.pyi @@ -1,19 +1,3 @@ -from _typeshed import Incomplete -from typing_extensions import TypeAlias +from d3dshot.capture_outputs.pytorch_capture_output import PytorchCaptureOutput -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 -_Pointer: TypeAlias = Incomplete - -class PytorchFloatCaptureOutput(CaptureOutput): - def __init__(self) -> None: ... - def process( - self, pointer: _Pointer, pitch: int, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int - ) -> _Tensor: ... - def to_pil(self, frame: _Tensor) -> Image.Image: ... - def stack(self, frames: list[_Tensor], stack_dimension: int) -> _Tensor: ... +class PytorchFloatCaptureOutput(PytorchCaptureOutput): ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi index a2a95c591b9d..2e7c6c105a12 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi @@ -1,21 +1,3 @@ -from _typeshed import Incomplete -from typing_extensions import TypeAlias +from d3dshot.capture_outputs.pytorch_gpu_capture_output import PytorchGPUCaptureOutput -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 device, Tensor -_Tensor: TypeAlias = Incomplete -_Device: TypeAlias = Incomplete -_Pointer: TypeAlias = Incomplete - -class PytorchFloatGPUCaptureOutput(CaptureOutput): - device: _Device - def __init__(self) -> None: ... - def process( - self, pointer: _Pointer, pitch: int, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int - ) -> _Tensor: ... - def to_pil(self, frame: _Tensor) -> Image.Image: ... - def stack(self, frames: list[_Tensor], stack_dimension: int) -> _Tensor: ... +class PytorchFloatGPUCaptureOutput(PytorchGPUCaptureOutput): ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi index 65a3da25bc10..d78cc60eb247 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi @@ -1,22 +1,3 @@ -from _typeshed import Incomplete -from typing_extensions import TypeAlias +from d3dshot.capture_outputs.pytorch_capture_output import PytorchCaptureOutput -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 device, Tensor -_Tensor: TypeAlias = Incomplete -_Device: TypeAlias = Incomplete - -_Pointer: TypeAlias = Incomplete - -class PytorchGPUCaptureOutput(CaptureOutput): - device: _Device - def __init__(self) -> None: ... - def process( - self, pointer: _Pointer, pitch: int, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int - ) -> _Tensor: ... - def to_pil(self, frame: _Tensor) -> Image.Image: ... - def stack(self, frames: list[_Tensor], stack_dimension: int): ... +class PytorchGPUCaptureOutput(PytorchCaptureOutput): ... diff --git a/stubs/D3DShot/d3dshot/d3dshot.pyi b/stubs/D3DShot/d3dshot/d3dshot.pyi index 80a25c324e01..29643c5cc98b 100644 --- a/stubs/D3DShot/d3dshot/d3dshot.pyi +++ b/stubs/D3DShot/d3dshot/d3dshot.pyi @@ -2,11 +2,12 @@ from _typeshed import Incomplete from collections import deque from typing import Any from typing_extensions import TypeAlias +from PIL import Image from d3dshot.capture_output import CaptureOutput as CaptureOutput, CaptureOutputs as CaptureOutputs from d3dshot.display import Display as Display -_Frame: TypeAlias = Incomplete +_Frame: TypeAlias = Image.Image | Incomplete # _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | _Tensor class Singleton(type): diff --git a/stubs/D3DShot/d3dshot/display.pyi b/stubs/D3DShot/d3dshot/display.pyi index a1b994f46178..89295b3d208c 100644 --- a/stubs/D3DShot/d3dshot/display.pyi +++ b/stubs/D3DShot/d3dshot/display.pyi @@ -1,10 +1,11 @@ from _typeshed import Incomplete from collections.abc import Callable +from ctypes.wintypes import PFLOAT from typing_extensions import Literal, TypeAlias +from PIL import Image -_Frame: TypeAlias = Incomplete +_Frame: TypeAlias = Image.Image | Incomplete # _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | _Tensor -_Pointer: TypeAlias = Incomplete class Display: name: str @@ -17,9 +18,9 @@ class Display: hmonitor: int dxgi_output: Incomplete | None dxgi_adapter: Incomplete | None - d3d_device: Incomplete # ctypes.POINTER(ID3D11Device)() - d3d_device_context: Incomplete # ctypes.POINTER(ID3D11DeviceContext)() - dxgi_output_duplication: Incomplete # ctypes.POINTER(IDXGIOutputDuplication)() + d3d_device: Incomplete + d3d_device_context: Incomplete + dxgi_output_duplication: Incomplete def __init__( self, @@ -36,7 +37,7 @@ class Display: ) -> None: ... def capture( self, - process_func: Callable[[_Pointer, int, int, int, tuple[int, int, int, int], int], _Frame | None] | None, + process_func: Callable[[PFLOAT, int, int, int, tuple[int, int, int, int], int], _Frame | None] | None, region: tuple[int, int, int, int] | None = ..., ) -> _Frame: ... @classmethod diff --git a/stubs/D3DShot/d3dshot/dll/d3d.pyi b/stubs/D3DShot/d3dshot/dll/d3d.pyi index e794f76765f9..9204ed109a74 100644 --- a/stubs/D3DShot/d3dshot/dll/d3d.pyi +++ b/stubs/D3DShot/d3dshot/dll/d3d.pyi @@ -1,15 +1,15 @@ from _typeshed import Incomplete -from ctypes import HRESULT, Structure, c_int32, c_uint, wintypes +from ctypes import HRESULT, _CArgObject, Structure, c_int32, c_uint, c_void_p, wintypes from typing_extensions import TypeAlias from collections.abc import Callable +from d3dshot.dll.dxgi import IDXGIAdapter + # TODO: Complete types once we can import non-types dependencies # See: https://github.com/python/typeshed/issues/5768 # import comtypes _IUnknown: TypeAlias = Incomplete -_Pointer: TypeAlias = Incomplete - class DXGI_SAMPLE_DESC(Structure): Count: wintypes.UINT Quality: wintypes.UINT @@ -46,7 +46,7 @@ class ID3D11Resource(ID3D11DeviceChild): GetEvictionPriority: Callable[[], wintypes.UINT] class ID3D11Texture2D(ID3D11Resource): - GetDesc: Callable[[_Pointer], None] + GetDesc: Callable[[D3D11_TEXTURE2D_DESC], None] class ID3D11DeviceContext(ID3D11DeviceChild): VSSetConstantBuffers: Callable[[], None] @@ -89,9 +89,10 @@ class ID3D11DeviceContext(ID3D11DeviceChild): RSSetViewports: Callable[[], None] RSSetScissorRects: Callable[[], None] CopySubresourceRegion: Callable[ - [_Pointer, wintypes.UINT, wintypes.UINT, wintypes.UINT, wintypes.UINT, _Pointer, wintypes.UINT, _Pointer], None + [ID3D11Resource, wintypes.UINT, wintypes.UINT, wintypes.UINT, wintypes.UINT, ID3D11Resource, wintypes.UINT, D3D11_BOX], + None, ] - CopyResource: Callable[[_Pointer, _Pointer], None] + CopyResource: Callable[[ID3D11Resource, ID3D11Resource], None] UpdateSubresource: Callable[[], None] CopyStructureCount: Callable[[], None] ClearRenderTargetView: Callable[[], None] @@ -163,7 +164,7 @@ class ID3D11DeviceContext(ID3D11DeviceChild): class ID3D11Device(_IUnknown): CreateBuffer: Callable[[], HRESULT] CreateTexture1D: Callable[[], HRESULT] - CreateTexture2D: Callable[[_Pointer, _Pointer, _Pointer], HRESULT] + CreateTexture2D: Callable[[D3D11_TEXTURE2D_DESC, c_void_p, _CArgObject], HRESULT] CreateTexture3D: Callable[[], HRESULT] CreateShaderResourceView: Callable[[], HRESULT] CreateUnorderedAccessView: Callable[[], HRESULT] @@ -198,10 +199,10 @@ class ID3D11Device(_IUnknown): GetFeatureLevel: Callable[[], c_int32] GetCreationFlags: Callable[[], c_uint] GetDeviceRemovedReason: Callable[[], HRESULT] - GetImmediateContext: Callable[[_Pointer], None] + GetImmediateContext: Callable[[_CArgObject], None] SetExceptionMode: Callable[[], HRESULT] GetExceptionMode: Callable[[], c_uint] -def initialize_d3d_device(dxgi_adapter: _Pointer) -> tuple[_Pointer, _Pointer]: ... -def describe_d3d11_texture_2d(d3d11_texture_2d: _Pointer) -> D3D11_TEXTURE2D_DESC: ... -def prepare_d3d11_texture_2d_for_cpu(d3d11_texture_2d: _Pointer, d3d_device: _Pointer) -> _Pointer: ... +def initialize_d3d_device(dxgi_adapter: IDXGIAdapter) -> tuple[ID3D11Device, ID3D11DeviceContext]: ... +def describe_d3d11_texture_2d(d3d11_texture_2d: ID3D11Texture2D) -> D3D11_TEXTURE2D_DESC: ... +def prepare_d3d11_texture_2d_for_cpu(d3d11_texture_2d: ID3D11Texture2D, d3d_device: ID3D11Device) -> ID3D11Texture2D: ... diff --git a/stubs/D3DShot/d3dshot/dll/dxgi.pyi b/stubs/D3DShot/d3dshot/dll/dxgi.pyi index d6adcc163ea2..c47794f04fb2 100644 --- a/stubs/D3DShot/d3dshot/dll/dxgi.pyi +++ b/stubs/D3DShot/d3dshot/dll/dxgi.pyi @@ -1,7 +1,10 @@ from _typeshed import Incomplete from collections.abc import Callable from ctypes import HRESULT, _CArgObject, _CData, Array, Structure, c_uint, c_ulong, wintypes +from typing import TypedDict from typing_extensions import TypeAlias +from PIL import Image +from d3dshot.dll.d3d import ID3D11Device # TODO: Complete types once we can import non-types dependencies # See: https://github.com/python/typeshed/issues/5768 @@ -10,16 +13,26 @@ from typing_extensions import TypeAlias # import numpy.typing as npt # _IUnknown: TypeAlias = Incomplete _STDMETHOD: TypeAlias = Callable[[Callable[[_CData, int], _CArgObject]], None] -_Frame: TypeAlias = Incomplete +_Frame: TypeAlias = Image.Image | Incomplete # _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | Tensor -# From comtypes.IUnknown -class _IUnknown: - def QueryInterface(self, interface: _Pointer, iid: _Pointer | None = ...) -> HRESULT: ... +class _IUnknown: # From comtypes.IUnknown + def QueryInterface(self, interface: type, iid: _CData | None = ...) -> HRESULT: ... def AddRef(self) -> c_ulong: ... def Release(self) -> c_ulong: ... -_Pointer: TypeAlias = Incomplete +class _DXGIOutputPosition(TypedDict): + left: wintypes.LONG + top: wintypes.LONG + right: wintypes.LONG + bottom: wintypes.LONG + +class _DXGIOutput(TypedDict): + name: str + position: _DXGIOutputPosition + resolution: tuple[tuple[wintypes.LONG, wintypes.LONG], tuple[wintypes.LONG, wintypes.LONG]] + rotation: int + is_attached_to_desktop: bool class LUID(Structure): LowPart: wintypes.DWORD @@ -60,7 +73,7 @@ class DXGI_OUTDUPL_FRAME_INFO(Structure): class DXGI_MAPPED_RECT(Structure): Pitch: wintypes.INT - pBits: _Pointer + pBits: wintypes.PFLOAT class IDXGIObject(_IUnknown): SetPrivateData: Callable[[], HRESULT] @@ -79,12 +92,12 @@ class IDXGIResource(IDXGIDeviceSubObject): class IDXGISurface(IDXGIDeviceSubObject): GetDesc: Callable[[], HRESULT] - Map: Callable[[_Pointer, wintypes.UINT], HRESULT] + Map: Callable[[DXGI_MAPPED_RECT, wintypes.UINT], HRESULT] Unmap: Callable[[], HRESULT] class IDXGIOutputDuplication(IDXGIObject): GetDesc: Callable[[], None] - AcquireNextFrame: Callable[[wintypes.UINT, _Pointer, _Pointer], HRESULT] + AcquireNextFrame: Callable[[wintypes.UINT, DXGI_OUTDUPL_FRAME_INFO, _CArgObject], HRESULT] GetFrameDirtyRects: Callable[[], HRESULT] GetFrameMoveRects: Callable[[], HRESULT] GetFramePointerShape: Callable[[], HRESULT] @@ -93,7 +106,7 @@ class IDXGIOutputDuplication(IDXGIObject): ReleaseFrame: Callable[[], HRESULT] class IDXGIOutput(IDXGIObject): - GetDesc: Callable[[_Pointer], HRESULT] + GetDesc: Callable[[DXGI_OUTPUT_DESC], HRESULT] GetDisplayModeList: Callable[[], HRESULT] FindClosestMatchingMode: Callable[[], HRESULT] WaitForVBlank: Callable[[], HRESULT] @@ -110,15 +123,15 @@ class IDXGIOutput1(IDXGIOutput): GetDisplayModeList1: Callable[[], HRESULT] FindClosestMatchingMode1: Callable[[], HRESULT] GetDisplaySurfaceData1: Callable[[], HRESULT] - DuplicateOutput: Callable[[_Pointer, _Pointer], HRESULT] + DuplicateOutput: Callable[[ID3D11Device, _CArgObject], HRESULT] class IDXGIAdapter(IDXGIObject): - EnumOutputs: Callable[[wintypes.UINT, _Pointer], HRESULT] + EnumOutputs: Callable[[wintypes.UINT, _CArgObject], HRESULT] GetDesc: Callable[[], HRESULT] CheckInterfaceSupport: Callable[[], HRESULT] class IDXGIAdapter1(IDXGIAdapter): - GetDesc1: Callable[[_Pointer], HRESULT] + GetDesc1: Callable[[DXGI_ADAPTER_DESC1], HRESULT] class IDXGIFactory(IDXGIObject): EnumAdapters: Callable[[], HRESULT] @@ -128,19 +141,19 @@ class IDXGIFactory(IDXGIObject): CreateSoftwareAdapter: Callable[[], HRESULT] class IDXGIFactory1(IDXGIFactory): - EnumAdapters1: Callable[[c_uint, _Pointer], HRESULT] + EnumAdapters1: Callable[[c_uint, _CArgObject], HRESULT] IsCurrent: Callable[[], wintypes.BOOL] -def initialize_dxgi_factory() -> _Pointer: ... -def discover_dxgi_adapters(dxgi_factory: _Pointer) -> list[_Pointer]: ... -def describe_dxgi_adapter(dxgi_adapter: _Pointer) -> _Pointer: ... -def discover_dxgi_outputs(dxgi_adapter: _Pointer) -> list[_Pointer]: ... -def describe_dxgi_output(dxgi_output: _Pointer) -> _Pointer: ... -def initialize_dxgi_output_duplication(dxgi_output: _Pointer, d3d_device: _Pointer) -> _Pointer: ... +def initialize_dxgi_factory() -> IDXGIFactory1: ... +def discover_dxgi_adapters(dxgi_factory: IDXGIFactory1) -> list[IDXGIAdapter1]: ... +def describe_dxgi_adapter(dxgi_adapter: IDXGIAdapter1) -> Array[wintypes.WCHAR]: ... +def discover_dxgi_outputs(dxgi_adapter: IDXGIAdapter) -> list[IDXGIOutput1]: ... +def describe_dxgi_output(dxgi_output: IDXGIOutput) -> _DXGIOutput: ... +def initialize_dxgi_output_duplication(dxgi_output: IDXGIOutput1, d3d_device: ID3D11Device) -> IDXGIOutputDuplication: ... def get_dxgi_output_duplication_frame( - dxgi_output_duplication: _Pointer, - d3d_device: _Pointer, - process_func: Callable[[_Pointer, int, int, int, tuple[int, int, int, int], int], _Frame | None] | None = ..., + dxgi_output_duplication: IDXGIOutputDuplication, + d3d_device: ID3D11Device, + process_func: Callable[[wintypes.PFLOAT, int, int, int, tuple[int, int, int, int], int], _Frame | None] | None = ..., width: int = ..., height: int = ..., region: tuple[int, int, int, int] | None = ..., diff --git a/stubs/D3DShot/d3dshot/dll/user32.pyi b/stubs/D3DShot/d3dshot/dll/user32.pyi index 56e109d1e4a5..37bada9d7c5f 100644 --- a/stubs/D3DShot/d3dshot/dll/user32.pyi +++ b/stubs/D3DShot/d3dshot/dll/user32.pyi @@ -1,9 +1,5 @@ import ctypes -from _typeshed import Incomplete from ctypes import wintypes -from typing_extensions import TypeAlias - -_Pointer: TypeAlias = Incomplete class DISPLAY_DEVICE(ctypes.Structure): cb: wintypes.DWORD @@ -14,4 +10,4 @@ class DISPLAY_DEVICE(ctypes.Structure): DeviceKey: wintypes.WCHAR def get_display_device_name_mapping() -> dict[str, tuple[str, bool]]: ... -def get_hmonitor_by_point(x: int, y: int) -> _Pointer: ... # ctypes.windll.user32.MonitorFromPoint(point, 0) +def get_hmonitor_by_point(x: int, y: int) -> wintypes.HMONITOR: ... From 3ba99183a2f7a6708c786b3a75eab6e543179c72 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 4 Sep 2022 23:11:13 +0000 Subject: [PATCH 11/30] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stubs/D3DShot/d3dshot/capture_output.pyi | 2 +- stubs/D3DShot/d3dshot/d3dshot.pyi | 2 +- stubs/D3DShot/d3dshot/display.pyi | 1 + stubs/D3DShot/d3dshot/dll/d3d.pyi | 4 ++-- stubs/D3DShot/d3dshot/dll/dxgi.pyi | 5 +++-- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/stubs/D3DShot/d3dshot/capture_output.pyi b/stubs/D3DShot/d3dshot/capture_output.pyi index c4f7bc129e37..6fd68df722b2 100644 --- a/stubs/D3DShot/d3dshot/capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_output.pyi @@ -1,6 +1,6 @@ -from ctypes import _CVoidConstPLike import enum from _typeshed import Incomplete +from ctypes import _CVoidConstPLike from typing_extensions import TypeAlias from PIL import Image diff --git a/stubs/D3DShot/d3dshot/d3dshot.pyi b/stubs/D3DShot/d3dshot/d3dshot.pyi index 29643c5cc98b..efc2eee4607c 100644 --- a/stubs/D3DShot/d3dshot/d3dshot.pyi +++ b/stubs/D3DShot/d3dshot/d3dshot.pyi @@ -2,10 +2,10 @@ from _typeshed import Incomplete from collections import deque from typing import Any from typing_extensions import TypeAlias -from PIL import Image from d3dshot.capture_output import CaptureOutput as CaptureOutput, CaptureOutputs as CaptureOutputs from d3dshot.display import Display as Display +from PIL import Image _Frame: TypeAlias = Image.Image | Incomplete # _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | _Tensor diff --git a/stubs/D3DShot/d3dshot/display.pyi b/stubs/D3DShot/d3dshot/display.pyi index 89295b3d208c..7fc3d0ebe775 100644 --- a/stubs/D3DShot/d3dshot/display.pyi +++ b/stubs/D3DShot/d3dshot/display.pyi @@ -2,6 +2,7 @@ from _typeshed import Incomplete from collections.abc import Callable from ctypes.wintypes import PFLOAT from typing_extensions import Literal, TypeAlias + from PIL import Image _Frame: TypeAlias = Image.Image | Incomplete diff --git a/stubs/D3DShot/d3dshot/dll/d3d.pyi b/stubs/D3DShot/d3dshot/dll/d3d.pyi index 9204ed109a74..1f8859f67bed 100644 --- a/stubs/D3DShot/d3dshot/dll/d3d.pyi +++ b/stubs/D3DShot/d3dshot/dll/d3d.pyi @@ -1,7 +1,7 @@ from _typeshed import Incomplete -from ctypes import HRESULT, _CArgObject, Structure, c_int32, c_uint, c_void_p, wintypes -from typing_extensions import TypeAlias from collections.abc import Callable +from ctypes import HRESULT, Structure, _CArgObject, c_int32, c_uint, c_void_p, wintypes +from typing_extensions import TypeAlias from d3dshot.dll.dxgi import IDXGIAdapter diff --git a/stubs/D3DShot/d3dshot/dll/dxgi.pyi b/stubs/D3DShot/d3dshot/dll/dxgi.pyi index c47794f04fb2..d151359463aa 100644 --- a/stubs/D3DShot/d3dshot/dll/dxgi.pyi +++ b/stubs/D3DShot/d3dshot/dll/dxgi.pyi @@ -1,10 +1,11 @@ from _typeshed import Incomplete from collections.abc import Callable -from ctypes import HRESULT, _CArgObject, _CData, Array, Structure, c_uint, c_ulong, wintypes +from ctypes import HRESULT, Array, Structure, _CArgObject, _CData, c_uint, c_ulong, wintypes from typing import TypedDict from typing_extensions import TypeAlias -from PIL import Image + from d3dshot.dll.d3d import ID3D11Device +from PIL import Image # TODO: Complete types once we can import non-types dependencies # See: https://github.com/python/typeshed/issues/5768 From c17309ba6d742381d1bcef48cb8fb747b309db9b Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 4 Sep 2022 19:13:25 -0400 Subject: [PATCH 12/30] Unused _STDMETHOD --- stubs/D3DShot/d3dshot/dll/dxgi.pyi | 1 - 1 file changed, 1 deletion(-) diff --git a/stubs/D3DShot/d3dshot/dll/dxgi.pyi b/stubs/D3DShot/d3dshot/dll/dxgi.pyi index c47794f04fb2..34316342e7a0 100644 --- a/stubs/D3DShot/d3dshot/dll/dxgi.pyi +++ b/stubs/D3DShot/d3dshot/dll/dxgi.pyi @@ -12,7 +12,6 @@ from d3dshot.dll.d3d import ID3D11Device # import comtypes # import numpy.typing as npt # _IUnknown: TypeAlias = Incomplete -_STDMETHOD: TypeAlias = Callable[[Callable[[_CData, int], _CArgObject]], None] _Frame: TypeAlias = Image.Image | Incomplete # _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | Tensor From 97934a4f5881457f1ae328a0209893c6d08042dd Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 4 Sep 2022 20:08:10 -0400 Subject: [PATCH 13/30] os.name check --- .flake8 | 4 +- stubs/D3DShot/d3dshot/dll/d3d.pyi | 97 ++++++++++++++----------- stubs/D3DShot/d3dshot/dll/dxgi.pyi | 103 +++++++++++++++------------ stubs/D3DShot/d3dshot/dll/user32.pyi | 2 +- 4 files changed, 114 insertions(+), 92 deletions(-) diff --git a/.flake8 b/.flake8 index ac705d7f8730..014cfadef889 100644 --- a/.flake8 +++ b/.flake8 @@ -35,9 +35,9 @@ per-file-ignores = # Unfortunately, flake8 does not allow to "noqa" just a specific error inside the file itself. # https://github.com/PyCQA/flake8/issues/1079 # F811 redefinition of unused '...' - stdlib/typing.pyi: E301, E302, E305, E501, E701, E741, NQA102, F401, F403, F405, F811, F822, Y037 + stdlib/typing.pyi: E301, E302, E305, E501, E701, E704, E741, NQA102, F401, F403, F405, F811, F822, Y037 # Generated protobuf files include docstrings - *_pb2.pyi: E301, E302, E305, E501, E701, NQA102, Y021, Y026 + *_pb2.pyi: E301, E302, E305, E501, E701, E704, NQA102, Y021, Y026 exclude = .venv*,.git noqa_require_code = true diff --git a/stubs/D3DShot/d3dshot/dll/d3d.pyi b/stubs/D3DShot/d3dshot/dll/d3d.pyi index 1f8859f67bed..69ab558364d9 100644 --- a/stubs/D3DShot/d3dshot/dll/d3d.pyi +++ b/stubs/D3DShot/d3dshot/dll/d3d.pyi @@ -1,10 +1,21 @@ +import sys from _typeshed import Incomplete from collections.abc import Callable -from ctypes import HRESULT, Structure, _CArgObject, c_int32, c_uint, c_void_p, wintypes +from ctypes import Structure, _CArgObject, c_int32, c_uint, c_void_p, wintypes from typing_extensions import TypeAlias from d3dshot.dll.dxgi import IDXGIAdapter +# mypy does not support os.name checks, while pyright does https://github.com/python/mypy/issues/13002 +# import os +# if os.name == "nt": # noqa: Y002 +if sys.platform == "win32": + from ctypes import HRESULT + + _HRESULT: TypeAlias = HRESULT +else: + _HRESULT: TypeAlias = Incomplete + # TODO: Complete types once we can import non-types dependencies # See: https://github.com/python/typeshed/issues/5768 # import comtypes @@ -36,9 +47,9 @@ class D3D11_TEXTURE2D_DESC(Structure): class ID3D11DeviceChild(_IUnknown): GetDevice: Callable[[], None] - GetPrivateData: Callable[[], HRESULT] - SetPrivateData: Callable[[], HRESULT] - SetPrivateDataInterface: Callable[[], HRESULT] + GetPrivateData: Callable[[], _HRESULT] + SetPrivateData: Callable[[], _HRESULT] + SetPrivateDataInterface: Callable[[], _HRESULT] class ID3D11Resource(ID3D11DeviceChild): GetType: Callable[[], None] @@ -56,7 +67,7 @@ class ID3D11DeviceContext(ID3D11DeviceChild): VSSetShader: Callable[[], None] DrawIndexed: Callable[[], None] Draw: Callable[[], None] - Map: Callable[[], HRESULT] + Map: Callable[[], _HRESULT] Unmap: Callable[[], None] PSSetConstantBuffers: Callable[[], None] IASetInputLayout: Callable[[], None] @@ -71,7 +82,7 @@ class ID3D11DeviceContext(ID3D11DeviceChild): VSSetSamplers: Callable[[], None] Begin: Callable[[], None] End: Callable[[], None] - GetData: Callable[[], HRESULT] + GetData: Callable[[], _HRESULT] SetPredication: Callable[[], None] GSSetShaderResources: Callable[[], None] GSSetSamplers: Callable[[], None] @@ -159,48 +170,48 @@ class ID3D11DeviceContext(ID3D11DeviceChild): Flush: Callable[[], None] GetType: Callable[[], None] GetContextFlags: Callable[[], wintypes.UINT] - FinishCommandList: Callable[[], HRESULT] + FinishCommandList: Callable[[], _HRESULT] class ID3D11Device(_IUnknown): - CreateBuffer: Callable[[], HRESULT] - CreateTexture1D: Callable[[], HRESULT] - CreateTexture2D: Callable[[D3D11_TEXTURE2D_DESC, c_void_p, _CArgObject], HRESULT] - CreateTexture3D: Callable[[], HRESULT] - CreateShaderResourceView: Callable[[], HRESULT] - CreateUnorderedAccessView: Callable[[], HRESULT] - CreateRenderTargetView: Callable[[], HRESULT] - CreateDepthStencilView: Callable[[], HRESULT] - CreateInputLayout: Callable[[], HRESULT] - CreateVertexShader: Callable[[], HRESULT] - CreateGeometryShader: Callable[[], HRESULT] - CreateGeometryShaderWithStreamOutput: Callable[[], HRESULT] - CreatePixelShader: Callable[[], HRESULT] - CreateHullShader: Callable[[], HRESULT] - CreateDomainShader: Callable[[], HRESULT] - CreateComputeShader: Callable[[], HRESULT] - CreateClassLinkage: Callable[[], HRESULT] - CreateBlendState: Callable[[], HRESULT] - CreateDepthStencilState: Callable[[], HRESULT] - CreateRasterizerState: Callable[[], HRESULT] - CreateSamplerState: Callable[[], HRESULT] - CreateQuery: Callable[[], HRESULT] - CreatePredicate: Callable[[], HRESULT] - CreateCounter: Callable[[], HRESULT] - CreateDeferredContext: Callable[[], HRESULT] - OpenSharedResource: Callable[[], HRESULT] - CheckFormatSupport: Callable[[], HRESULT] - CheckMultisampleQualityLevels: Callable[[], HRESULT] - CheckCounterInfo: Callable[[], HRESULT] - CheckCounter: Callable[[], HRESULT] - CheckFeatureSupport: Callable[[], HRESULT] - GetPrivateData: Callable[[], HRESULT] - SetPrivateData: Callable[[], HRESULT] - SetPrivateDataInterface: Callable[[], HRESULT] + CreateBuffer: Callable[[], _HRESULT] + CreateTexture1D: Callable[[], _HRESULT] + CreateTexture2D: Callable[[D3D11_TEXTURE2D_DESC, c_void_p, _CArgObject], _HRESULT] + CreateTexture3D: Callable[[], _HRESULT] + CreateShaderResourceView: Callable[[], _HRESULT] + CreateUnorderedAccessView: Callable[[], _HRESULT] + CreateRenderTargetView: Callable[[], _HRESULT] + CreateDepthStencilView: Callable[[], _HRESULT] + CreateInputLayout: Callable[[], _HRESULT] + CreateVertexShader: Callable[[], _HRESULT] + CreateGeometryShader: Callable[[], _HRESULT] + CreateGeometryShaderWithStreamOutput: Callable[[], _HRESULT] + CreatePixelShader: Callable[[], _HRESULT] + CreateHullShader: Callable[[], _HRESULT] + CreateDomainShader: Callable[[], _HRESULT] + CreateComputeShader: Callable[[], _HRESULT] + CreateClassLinkage: Callable[[], _HRESULT] + CreateBlendState: Callable[[], _HRESULT] + CreateDepthStencilState: Callable[[], _HRESULT] + CreateRasterizerState: Callable[[], _HRESULT] + CreateSamplerState: Callable[[], _HRESULT] + CreateQuery: Callable[[], _HRESULT] + CreatePredicate: Callable[[], _HRESULT] + CreateCounter: Callable[[], _HRESULT] + CreateDeferredContext: Callable[[], _HRESULT] + OpenSharedResource: Callable[[], _HRESULT] + CheckFormatSupport: Callable[[], _HRESULT] + CheckMultisampleQualityLevels: Callable[[], _HRESULT] + CheckCounterInfo: Callable[[], _HRESULT] + CheckCounter: Callable[[], _HRESULT] + CheckFeatureSupport: Callable[[], _HRESULT] + GetPrivateData: Callable[[], _HRESULT] + SetPrivateData: Callable[[], _HRESULT] + SetPrivateDataInterface: Callable[[], _HRESULT] GetFeatureLevel: Callable[[], c_int32] GetCreationFlags: Callable[[], c_uint] - GetDeviceRemovedReason: Callable[[], HRESULT] + GetDeviceRemovedReason: Callable[[], _HRESULT] GetImmediateContext: Callable[[_CArgObject], None] - SetExceptionMode: Callable[[], HRESULT] + SetExceptionMode: Callable[[], _HRESULT] GetExceptionMode: Callable[[], c_uint] def initialize_d3d_device(dxgi_adapter: IDXGIAdapter) -> tuple[ID3D11Device, ID3D11DeviceContext]: ... diff --git a/stubs/D3DShot/d3dshot/dll/dxgi.pyi b/stubs/D3DShot/d3dshot/dll/dxgi.pyi index 114ca12aaddf..f78e7913066e 100644 --- a/stubs/D3DShot/d3dshot/dll/dxgi.pyi +++ b/stubs/D3DShot/d3dshot/dll/dxgi.pyi @@ -1,6 +1,7 @@ +import sys from _typeshed import Incomplete from collections.abc import Callable -from ctypes import HRESULT, Array, Structure, _CArgObject, _CData, c_uint, c_ulong, wintypes +from ctypes import Array, Structure, _CArgObject, _CData, c_uint, c_ulong, wintypes from typing import TypedDict from typing_extensions import TypeAlias @@ -16,8 +17,18 @@ from PIL import Image _Frame: TypeAlias = Image.Image | Incomplete # _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | Tensor +# mypy does not support os.name checks, while pyright does https://github.com/python/mypy/issues/13002 +# import os +# if os.name == "nt": # noqa: Y002 +if sys.platform == "win32": + from ctypes import HRESULT + + _HRESULT: TypeAlias = HRESULT +else: + _HRESULT: TypeAlias = Incomplete + class _IUnknown: # From comtypes.IUnknown - def QueryInterface(self, interface: type, iid: _CData | None = ...) -> HRESULT: ... + def QueryInterface(self, interface: type, iid: _CData | None = ...) -> _HRESULT: ... def AddRef(self) -> c_ulong: ... def Release(self) -> c_ulong: ... @@ -76,72 +87,72 @@ class DXGI_MAPPED_RECT(Structure): pBits: wintypes.PFLOAT class IDXGIObject(_IUnknown): - SetPrivateData: Callable[[], HRESULT] - SetPrivateDataInterface: Callable[[], HRESULT] - GetPrivateData: Callable[[], HRESULT] - GetParent: Callable[[], HRESULT] + SetPrivateData: Callable[[], _HRESULT] + SetPrivateDataInterface: Callable[[], _HRESULT] + GetPrivateData: Callable[[], _HRESULT] + GetParent: Callable[[], _HRESULT] class IDXGIDeviceSubObject(IDXGIObject): - GetDevice: Callable[[], HRESULT] + GetDevice: Callable[[], _HRESULT] class IDXGIResource(IDXGIDeviceSubObject): - GetSharedHandle: Callable[[], HRESULT] - GetUsage: Callable[[], HRESULT] - SetEvictionPriority: Callable[[], HRESULT] - GetEvictionPriority: Callable[[], HRESULT] + GetSharedHandle: Callable[[], _HRESULT] + GetUsage: Callable[[], _HRESULT] + SetEvictionPriority: Callable[[], _HRESULT] + GetEvictionPriority: Callable[[], _HRESULT] class IDXGISurface(IDXGIDeviceSubObject): - GetDesc: Callable[[], HRESULT] - Map: Callable[[DXGI_MAPPED_RECT, wintypes.UINT], HRESULT] - Unmap: Callable[[], HRESULT] + GetDesc: Callable[[], _HRESULT] + Map: Callable[[DXGI_MAPPED_RECT, wintypes.UINT], _HRESULT] + Unmap: Callable[[], _HRESULT] class IDXGIOutputDuplication(IDXGIObject): GetDesc: Callable[[], None] - AcquireNextFrame: Callable[[wintypes.UINT, DXGI_OUTDUPL_FRAME_INFO, _CArgObject], HRESULT] - GetFrameDirtyRects: Callable[[], HRESULT] - GetFrameMoveRects: Callable[[], HRESULT] - GetFramePointerShape: Callable[[], HRESULT] - MapDesktopSurface: Callable[[], HRESULT] - UnMapDesktopSurface: Callable[[], HRESULT] - ReleaseFrame: Callable[[], HRESULT] + AcquireNextFrame: Callable[[wintypes.UINT, DXGI_OUTDUPL_FRAME_INFO, _CArgObject], _HRESULT] + GetFrameDirtyRects: Callable[[], _HRESULT] + GetFrameMoveRects: Callable[[], _HRESULT] + GetFramePointerShape: Callable[[], _HRESULT] + MapDesktopSurface: Callable[[], _HRESULT] + UnMapDesktopSurface: Callable[[], _HRESULT] + ReleaseFrame: Callable[[], _HRESULT] class IDXGIOutput(IDXGIObject): - GetDesc: Callable[[DXGI_OUTPUT_DESC], HRESULT] - GetDisplayModeList: Callable[[], HRESULT] - FindClosestMatchingMode: Callable[[], HRESULT] - WaitForVBlank: Callable[[], HRESULT] - TakeOwnership: Callable[[], HRESULT] + GetDesc: Callable[[DXGI_OUTPUT_DESC], _HRESULT] + GetDisplayModeList: Callable[[], _HRESULT] + FindClosestMatchingMode: Callable[[], _HRESULT] + WaitForVBlank: Callable[[], _HRESULT] + TakeOwnership: Callable[[], _HRESULT] ReleaseOwnership: Callable[[], None] - GetGammaControlCapabilities: Callable[[], HRESULT] - SetGammaControl: Callable[[], HRESULT] - GetGammaControl: Callable[[], HRESULT] - SetDisplaySurface: Callable[[], HRESULT] - GetDisplaySurfaceData: Callable[[], HRESULT] - GetFrameStatistics: Callable[[], HRESULT] + GetGammaControlCapabilities: Callable[[], _HRESULT] + SetGammaControl: Callable[[], _HRESULT] + GetGammaControl: Callable[[], _HRESULT] + SetDisplaySurface: Callable[[], _HRESULT] + GetDisplaySurfaceData: Callable[[], _HRESULT] + GetFrameStatistics: Callable[[], _HRESULT] class IDXGIOutput1(IDXGIOutput): - GetDisplayModeList1: Callable[[], HRESULT] - FindClosestMatchingMode1: Callable[[], HRESULT] - GetDisplaySurfaceData1: Callable[[], HRESULT] - DuplicateOutput: Callable[[ID3D11Device, _CArgObject], HRESULT] + GetDisplayModeList1: Callable[[], _HRESULT] + FindClosestMatchingMode1: Callable[[], _HRESULT] + GetDisplaySurfaceData1: Callable[[], _HRESULT] + DuplicateOutput: Callable[[ID3D11Device, _CArgObject], _HRESULT] class IDXGIAdapter(IDXGIObject): - EnumOutputs: Callable[[wintypes.UINT, _CArgObject], HRESULT] - GetDesc: Callable[[], HRESULT] - CheckInterfaceSupport: Callable[[], HRESULT] + EnumOutputs: Callable[[wintypes.UINT, _CArgObject], _HRESULT] + GetDesc: Callable[[], _HRESULT] + CheckInterfaceSupport: Callable[[], _HRESULT] class IDXGIAdapter1(IDXGIAdapter): - GetDesc1: Callable[[DXGI_ADAPTER_DESC1], HRESULT] + GetDesc1: Callable[[DXGI_ADAPTER_DESC1], _HRESULT] class IDXGIFactory(IDXGIObject): - EnumAdapters: Callable[[], HRESULT] - MakeWindowAssociation: Callable[[], HRESULT] - GetWindowAssociation: Callable[[], HRESULT] - CreateSwapChain: Callable[[], HRESULT] - CreateSoftwareAdapter: Callable[[], HRESULT] + EnumAdapters: Callable[[], _HRESULT] + MakeWindowAssociation: Callable[[], _HRESULT] + GetWindowAssociation: Callable[[], _HRESULT] + CreateSwapChain: Callable[[], _HRESULT] + CreateSoftwareAdapter: Callable[[], _HRESULT] class IDXGIFactory1(IDXGIFactory): - EnumAdapters1: Callable[[c_uint, _CArgObject], HRESULT] + EnumAdapters1: Callable[[c_uint, _CArgObject], _HRESULT] IsCurrent: Callable[[], wintypes.BOOL] def initialize_dxgi_factory() -> IDXGIFactory1: ... diff --git a/stubs/D3DShot/d3dshot/dll/user32.pyi b/stubs/D3DShot/d3dshot/dll/user32.pyi index 37bada9d7c5f..a8dfaec82e68 100644 --- a/stubs/D3DShot/d3dshot/dll/user32.pyi +++ b/stubs/D3DShot/d3dshot/dll/user32.pyi @@ -10,4 +10,4 @@ class DISPLAY_DEVICE(ctypes.Structure): DeviceKey: wintypes.WCHAR def get_display_device_name_mapping() -> dict[str, tuple[str, bool]]: ... -def get_hmonitor_by_point(x: int, y: int) -> wintypes.HMONITOR: ... +def get_hmonitor_by_point(x: wintypes.LONG, y: wintypes.LONG) -> wintypes.HMONITOR: ... From 73db85cd52ec9f24680df8f631d244f3b19ae4d0 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 4 Sep 2022 21:38:24 -0400 Subject: [PATCH 14/30] TypedDict from typing_extensions --- stubs/D3DShot/d3dshot/dll/dxgi.pyi | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/stubs/D3DShot/d3dshot/dll/dxgi.pyi b/stubs/D3DShot/d3dshot/dll/dxgi.pyi index f78e7913066e..820f5b60de3a 100644 --- a/stubs/D3DShot/d3dshot/dll/dxgi.pyi +++ b/stubs/D3DShot/d3dshot/dll/dxgi.pyi @@ -2,8 +2,7 @@ import sys from _typeshed import Incomplete from collections.abc import Callable from ctypes import Array, Structure, _CArgObject, _CData, c_uint, c_ulong, wintypes -from typing import TypedDict -from typing_extensions import TypeAlias +from typing_extensions import TypeAlias, TypedDict from d3dshot.dll.d3d import ID3D11Device from PIL import Image From cd79554b0f40f3e4e7f51fef1607c4dcf34efc69 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 4 Sep 2022 21:51:36 -0400 Subject: [PATCH 15/30] Update some types --- stubs/D3DShot/d3dshot/capture_output.pyi | 4 ++-- .../d3dshot/capture_outputs/numpy_capture_output.pyi | 4 ++-- .../D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi | 6 ++++-- .../d3dshot/capture_outputs/pytorch_capture_output.pyi | 4 ++-- stubs/D3DShot/d3dshot/display.pyi | 4 ++-- stubs/D3DShot/d3dshot/dll/shcore.pyi | 4 +++- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/stubs/D3DShot/d3dshot/capture_output.pyi b/stubs/D3DShot/d3dshot/capture_output.pyi index 6fd68df722b2..d0d4b8840a86 100644 --- a/stubs/D3DShot/d3dshot/capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_output.pyi @@ -1,7 +1,7 @@ import enum from _typeshed import Incomplete from ctypes import _CVoidConstPLike -from typing_extensions import TypeAlias +from typing_extensions import Literal, TypeAlias from PIL import Image @@ -33,4 +33,4 @@ class CaptureOutput: rotation: int, ) -> _Frame: ... def to_pil(self, frame: _Frame) -> Image.Image: ... - def stack(self, frames: list[_Frame], stack_dimension) -> _Frame: ... + def stack(self, frames: list[_Frame], stack_dimension: Literal["first", "last"]) -> _Frame: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi index d3f43794c045..ab7ab3ed4996 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi @@ -1,6 +1,6 @@ from _typeshed import Incomplete from ctypes import _CVoidConstPLike -from typing_extensions import TypeAlias +from typing_extensions import TypeAlias, Literal from d3dshot.capture_output import CaptureOutput from PIL import Image @@ -25,4 +25,4 @@ class NumpyCaptureOutput(CaptureOutput): rotation: int, ) -> _NDArray: ... def to_pil(self, frame: _NDArray) -> Image.Image: ... - def stack(self, frames: list[_NDArray] | _NDArray, stack_dimension: int) -> _NDArray: ... + def stack(self, frames: list[_NDArray] | _NDArray, stack_dimension: Literal["first", "last"]) -> _NDArray: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi index 3ee8ea291238..8837161615ab 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi @@ -1,10 +1,12 @@ from ctypes import _CVoidConstPLike -from typing import TypeVar +from typing import Any, TypeVar +from typing_extensions import TypeAlias from d3dshot.capture_output import CaptureOutput from PIL import Image _T = TypeVar("_T") +_Unused: TypeAlias = Any class PILCaptureOutput(CaptureOutput): def __init__(self) -> None: ... @@ -19,4 +21,4 @@ class PILCaptureOutput(CaptureOutput): rotation: int, ) -> Image.Image: ... def to_pil(self, frame: _T) -> _T: ... - def stack(self, frames: list[Image.Image], stack_dimension: int) -> list[Image.Image]: ... + def stack(self, frames: _T, stack_dimension: _Unused) -> _T: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi index 51733009706b..04ce63783f6e 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi @@ -1,6 +1,6 @@ from _typeshed import Incomplete from ctypes import _CVoidConstPLike -from typing_extensions import TypeAlias +from typing_extensions import TypeAlias, Literal from d3dshot.capture_output import CaptureOutput from PIL import Image @@ -23,4 +23,4 @@ class PytorchCaptureOutput(CaptureOutput): rotation: int, ) -> _Tensor: ... def to_pil(self, frame: _Tensor) -> Image.Image: ... - def stack(self, frames: list[_Tensor], stack_dimension: int) -> _Tensor: ... + def stack(self, frames: list[_Tensor], stack_dimension: Literal["first", "last"]) -> _Tensor: ... diff --git a/stubs/D3DShot/d3dshot/display.pyi b/stubs/D3DShot/d3dshot/display.pyi index 7fc3d0ebe775..30394a0d64f5 100644 --- a/stubs/D3DShot/d3dshot/display.pyi +++ b/stubs/D3DShot/d3dshot/display.pyi @@ -14,7 +14,7 @@ class Display: resolution: tuple[int, int] position: dict[Literal["left", "top", "right", "bottom"], int] rotation: int - scale_factor: int + scale_factor: float is_primary: bool hmonitor: int dxgi_output: Incomplete | None @@ -30,7 +30,7 @@ class Display: resolution: tuple[int, int] | None = ..., position: dict[Literal["left", "top", "right", "bottom"], int] | None = ..., rotation: int | None = ..., - scale_factor: int | None = ..., + scale_factor: float | None = ..., is_primary: bool = ..., hmonitor: int | None = ..., dxgi_output: Incomplete | None = ..., diff --git a/stubs/D3DShot/d3dshot/dll/shcore.pyi b/stubs/D3DShot/d3dshot/dll/shcore.pyi index 15a24dba3c4e..3fd5237ef7ba 100644 --- a/stubs/D3DShot/d3dshot/dll/shcore.pyi +++ b/stubs/D3DShot/d3dshot/dll/shcore.pyi @@ -1 +1,3 @@ -def get_scale_factor_for_monitor(hmonitor: int) -> float: ... +from ctypes.wintypes import HMONITOR + +def get_scale_factor_for_monitor(hmonitor: HMONITOR) -> float: ... From e0b7e67221aefe2f155d05562c04f5c3ca20a8fa Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 5 Sep 2022 01:52:54 +0000 Subject: [PATCH 16/30] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi | 2 +- .../D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi index ab7ab3ed4996..fd1e594df656 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi @@ -1,6 +1,6 @@ from _typeshed import Incomplete from ctypes import _CVoidConstPLike -from typing_extensions import TypeAlias, Literal +from typing_extensions import Literal, TypeAlias from d3dshot.capture_output import CaptureOutput from PIL import Image diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi index 04ce63783f6e..f1536dcb0ddf 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi @@ -1,6 +1,6 @@ from _typeshed import Incomplete from ctypes import _CVoidConstPLike -from typing_extensions import TypeAlias, Literal +from typing_extensions import Literal, TypeAlias from d3dshot.capture_output import CaptureOutput from PIL import Image From 66ba404ab9645848ca969d2c3b0f3ee0bbf38e3c Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 4 Sep 2022 21:53:40 -0400 Subject: [PATCH 17/30] skip instead of allowlist --- stubs/D3DShot/@tests/stubtest_allowlist.txt | 16 ---------------- stubs/D3DShot/METADATA.toml | 2 +- 2 files changed, 1 insertion(+), 17 deletions(-) delete mode 100644 stubs/D3DShot/@tests/stubtest_allowlist.txt diff --git a/stubs/D3DShot/@tests/stubtest_allowlist.txt b/stubs/D3DShot/@tests/stubtest_allowlist.txt deleted file mode 100644 index 09a9f30f7bfc..000000000000 --- a/stubs/D3DShot/@tests/stubtest_allowlist.txt +++ /dev/null @@ -1,16 +0,0 @@ -# Cannot import COMError on linux, which the CI runs on -# ImportError: cannot import name 'COMError' from '_ctypes' -d3dshot -d3dshot.capture_output -d3dshot.capture_outputs -d3dshot.capture_outputs.numpy_capture_output -d3dshot.capture_outputs.numpy_float_capture_output -d3dshot.capture_outputs.pil_capture_output -d3dshot.capture_outputs.pytorch_capture_output -d3dshot.capture_outputs.pytorch_float_capture_output -d3dshot.capture_outputs.pytorch_float_gpu_capture_output -d3dshot.capture_outputs.pytorch_gpu_capture_output -d3dshot.d3dshot -d3dshot.display -d3dshot.dll.d3d -d3dshot.dll.dxgi diff --git a/stubs/D3DShot/METADATA.toml b/stubs/D3DShot/METADATA.toml index beb02b01908b..13c4c3be547e 100644 --- a/stubs/D3DShot/METADATA.toml +++ b/stubs/D3DShot/METADATA.toml @@ -2,4 +2,4 @@ version = "0.1.*" requires = ["types-Pillow"] [tool.stubtest] -ignore_missing_stub = false +skip = true From a166c59e6eca20b23c9c533149b3d553d7dab8b8 Mon Sep 17 00:00:00 2001 From: Avasam Date: Mon, 5 Sep 2022 22:49:31 -0400 Subject: [PATCH 18/30] PR review fixes --- .flake8 | 7 +- .../capture_outputs/pil_capture_output.pyi | 4 +- stubs/D3DShot/d3dshot/dll/d3d.pyi | 363 +++++++++--------- stubs/D3DShot/d3dshot/dll/dxgi.pyi | 167 ++++---- 4 files changed, 275 insertions(+), 266 deletions(-) diff --git a/.flake8 b/.flake8 index 014cfadef889..de09afb1411f 100644 --- a/.flake8 +++ b/.flake8 @@ -7,7 +7,6 @@ # Some rules are considered irrelevant to stub files: # E701 multiple statements on one line (colon) -- disallows "..." on the same line -# E704 multiple statements on one line (def) -- disallows "..." on the same line # F401 imported but unused -- does not recognize re-exports # https://github.com/PyCQA/pyflakes/issues/474 # F822 undefined name in __all__ -- flake8 does not recognize 'foo: Any' @@ -30,14 +29,14 @@ [flake8] per-file-ignores = *.py: E203, E301, E302, E305, E501 - *.pyi: E301, E302, E305, E501, E701, E704, E741, NQA102, F401, F403, F405, F822, Y037 + *.pyi: E301, E302, E305, E501, E701, E741, NQA102, F401, F403, F405, F822, Y037 # Since typing.pyi defines "overload" this is not recognized by flake8 as typing.overload. # Unfortunately, flake8 does not allow to "noqa" just a specific error inside the file itself. # https://github.com/PyCQA/flake8/issues/1079 # F811 redefinition of unused '...' - stdlib/typing.pyi: E301, E302, E305, E501, E701, E704, E741, NQA102, F401, F403, F405, F811, F822, Y037 + stdlib/typing.pyi: E301, E302, E305, E501, E701, E741, NQA102, F401, F403, F405, F811, F822, Y037 # Generated protobuf files include docstrings - *_pb2.pyi: E301, E302, E305, E501, E701, E704, NQA102, Y021, Y026 + *_pb2.pyi: E301, E302, E305, E501, E701, NQA102, Y021, Y026 exclude = .venv*,.git noqa_require_code = true diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi index 8837161615ab..86f7a306bd50 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi @@ -1,12 +1,12 @@ from ctypes import _CVoidConstPLike -from typing import Any, TypeVar +from typing import TypeVar from typing_extensions import TypeAlias from d3dshot.capture_output import CaptureOutput from PIL import Image _T = TypeVar("_T") -_Unused: TypeAlias = Any +_Unused: TypeAlias = object class PILCaptureOutput(CaptureOutput): def __init__(self) -> None: ... diff --git a/stubs/D3DShot/d3dshot/dll/d3d.pyi b/stubs/D3DShot/d3dshot/dll/d3d.pyi index 69ab558364d9..3e85e13ed56b 100644 --- a/stubs/D3DShot/d3dshot/dll/d3d.pyi +++ b/stubs/D3DShot/d3dshot/dll/d3d.pyi @@ -1,7 +1,7 @@ import sys from _typeshed import Incomplete -from collections.abc import Callable -from ctypes import Structure, _CArgObject, c_int32, c_uint, c_void_p, wintypes +from ctypes import Structure, _CArgObject, c_int32, c_uint, c_void_p +from ctypes.wintypes import FLOAT, UINT from typing_extensions import TypeAlias from d3dshot.dll.dxgi import IDXGIAdapter @@ -22,197 +22,204 @@ else: _IUnknown: TypeAlias = Incomplete class DXGI_SAMPLE_DESC(Structure): - Count: wintypes.UINT - Quality: wintypes.UINT + Count: UINT + Quality: UINT class D3D11_BOX(Structure): - left: wintypes.UINT - top: wintypes.UINT - front: wintypes.UINT - right: wintypes.UINT - bottom: wintypes.UINT - back: wintypes.UINT + left: UINT + top: UINT + front: UINT + right: UINT + bottom: UINT + back: UINT class D3D11_TEXTURE2D_DESC(Structure): - Width: wintypes.UINT - Height: wintypes.UINT - MipLevels: wintypes.UINT - ArraySize: wintypes.UINT - Format: wintypes.UINT + Width: UINT + Height: UINT + MipLevels: UINT + ArraySize: UINT + Format: UINT SampleDesc: DXGI_SAMPLE_DESC - Usage: wintypes.UINT - BindFlags: wintypes.UINT - CPUAccessFlags: wintypes.UINT - MiscFlags: wintypes.UINT + Usage: UINT + BindFlags: UINT + CPUAccessFlags: UINT + MiscFlags: UINT class ID3D11DeviceChild(_IUnknown): - GetDevice: Callable[[], None] - GetPrivateData: Callable[[], _HRESULT] - SetPrivateData: Callable[[], _HRESULT] - SetPrivateDataInterface: Callable[[], _HRESULT] + def GetDevice(self) -> None: ... + def GetPrivateData(self) -> _HRESULT: ... + def SetPrivateData(self) -> _HRESULT: ... + def SetPrivateDataInterface(self) -> _HRESULT: ... class ID3D11Resource(ID3D11DeviceChild): - GetType: Callable[[], None] - SetEvictionPriority: Callable[[], None] - GetEvictionPriority: Callable[[], wintypes.UINT] + def GetType(self) -> None: ... + def SetEvictionPriority(self) -> None: ... + def GetEvictionPriority(self) -> UINT: ... class ID3D11Texture2D(ID3D11Resource): - GetDesc: Callable[[D3D11_TEXTURE2D_DESC], None] + def GetDesc(self, pDesc: D3D11_TEXTURE2D_DESC) -> None: ... class ID3D11DeviceContext(ID3D11DeviceChild): - VSSetConstantBuffers: Callable[[], None] - PSSetShaderResources: Callable[[], None] - PSSetShader: Callable[[], None] - PSSetSamplers: Callable[[], None] - VSSetShader: Callable[[], None] - DrawIndexed: Callable[[], None] - Draw: Callable[[], None] - Map: Callable[[], _HRESULT] - Unmap: Callable[[], None] - PSSetConstantBuffers: Callable[[], None] - IASetInputLayout: Callable[[], None] - IASetVertexBuffers: Callable[[], None] - IASetIndexBuffer: Callable[[], None] - DrawIndexedInstanced: Callable[[], None] - DrawInstanced: Callable[[], None] - GSSetConstantBuffers: Callable[[], None] - GSSetShader: Callable[[], None] - IASetPrimitiveTopology: Callable[[], None] - VSSetShaderResources: Callable[[], None] - VSSetSamplers: Callable[[], None] - Begin: Callable[[], None] - End: Callable[[], None] - GetData: Callable[[], _HRESULT] - SetPredication: Callable[[], None] - GSSetShaderResources: Callable[[], None] - GSSetSamplers: Callable[[], None] - OMSetRenderTargets: Callable[[], None] - OMSetRenderTargetsAndUnorderedAccessViews: Callable[[], None] - OMSetBlendState: Callable[[], None] - OMSetDepthStencilState: Callable[[], None] - SOSetTargets: Callable[[], None] - DrawAuto: Callable[[], None] - DrawIndexedInstancedIndirect: Callable[[], None] - DrawInstancedIndirect: Callable[[], None] - Dispatch: Callable[[], None] - DispatchIndirect: Callable[[], None] - RSSetState: Callable[[], None] - RSSetViewports: Callable[[], None] - RSSetScissorRects: Callable[[], None] - CopySubresourceRegion: Callable[ - [ID3D11Resource, wintypes.UINT, wintypes.UINT, wintypes.UINT, wintypes.UINT, ID3D11Resource, wintypes.UINT, D3D11_BOX], - None, - ] - CopyResource: Callable[[ID3D11Resource, ID3D11Resource], None] - UpdateSubresource: Callable[[], None] - CopyStructureCount: Callable[[], None] - ClearRenderTargetView: Callable[[], None] - ClearUnorderedAccessViewUint: Callable[[], None] - ClearUnorderedAccessViewFloat: Callable[[], None] - ClearDepthStencilView: Callable[[], None] - GenerateMips: Callable[[], None] - SetResourceMinLOD: Callable[[], None] - GetResourceMinLOD: Callable[[], wintypes.FLOAT] - ResolveSubresource: Callable[[], None] - ExecuteCommandList: Callable[[], None] - HSSetShaderResources: Callable[[], None] - HSSetShader: Callable[[], None] - HSSetSamplers: Callable[[], None] - HSSetConstantBuffers: Callable[[], None] - DSSetShaderResources: Callable[[], None] - DSSetShader: Callable[[], None] - DSSetSamplers: Callable[[], None] - DSSetConstantBuffers: Callable[[], None] - CSSetShaderResources: Callable[[], None] - CSSetUnorderedAccessViews: Callable[[], None] - CSSetShader: Callable[[], None] - CSSetSamplers: Callable[[], None] - CSSetConstantBuffers: Callable[[], None] - VSGetConstantBuffers: Callable[[], None] - PSGetShaderResources: Callable[[], None] - PSGetShader: Callable[[], None] - PSGetSamplers: Callable[[], None] - VSGetShader: Callable[[], None] - PSGetConstantBuffers: Callable[[], None] - IAGetInputLayout: Callable[[], None] - IAGetVertexBuffers: Callable[[], None] - IAGetIndexBuffer: Callable[[], None] - GSGetConstantBuffers: Callable[[], None] - GSGetShader: Callable[[], None] - IAGetPrimitiveTopology: Callable[[], None] - VSGetShaderResources: Callable[[], None] - VSGetSamplers: Callable[[], None] - GetPredication: Callable[[], None] - GSGetShaderResources: Callable[[], None] - GSGetSamplers: Callable[[], None] - OMGetRenderTargets: Callable[[], None] - OMGetRenderTargetsAndUnorderedAccessViews: Callable[[], None] - OMGetBlendState: Callable[[], None] - OMGetDepthStencilState: Callable[[], None] - SOGetTargets: Callable[[], None] - RSGetState: Callable[[], None] - RSGetViewports: Callable[[], None] - RSGetScissorRects: Callable[[], None] - HSGetShaderResources: Callable[[], None] - HSGetShader: Callable[[], None] - HSGetSamplers: Callable[[], None] - HSGetConstantBuffers: Callable[[], None] - DSGetShaderResources: Callable[[], None] - DSGetShader: Callable[[], None] - DSGetSamplers: Callable[[], None] - DSGetConstantBuffers: Callable[[], None] - CSGetShaderResources: Callable[[], None] - CSGetUnorderedAccessViews: Callable[[], None] - CSGetShader: Callable[[], None] - CSGetSamplers: Callable[[], None] - CSGetConstantBuffers: Callable[[], None] - ClearState: Callable[[], None] - Flush: Callable[[], None] - GetType: Callable[[], None] - GetContextFlags: Callable[[], wintypes.UINT] - FinishCommandList: Callable[[], _HRESULT] + def VSSetConstantBuffers(self) -> None: ... + def PSSetShaderResources(self) -> None: ... + def PSSetShader(self) -> None: ... + def PSSetSamplers(self) -> None: ... + def VSSetShader(self) -> None: ... + def DrawIndexed(self) -> None: ... + def Draw(self) -> None: ... + def Map(self) -> _HRESULT: ... + def Unmap(self) -> None: ... + def PSSetConstantBuffers(self) -> None: ... + def IASetInputLayout(self) -> None: ... + def IASetVertexBuffers(self) -> None: ... + def IASetIndexBuffer(self) -> None: ... + def DrawIndexedInstanced(self) -> None: ... + def DrawInstanced(self) -> None: ... + def GSSetConstantBuffers(self) -> None: ... + def GSSetShader(self) -> None: ... + def IASetPrimitiveTopology(self) -> None: ... + def VSSetShaderResources(self) -> None: ... + def VSSetSamplers(self) -> None: ... + def Begin(self) -> None: ... + def End(self) -> None: ... + def GetData(self) -> _HRESULT: ... + def SetPredication(self) -> None: ... + def GSSetShaderResources(self) -> None: ... + def GSSetSamplers(self) -> None: ... + def OMSetRenderTargets(self) -> None: ... + def OMSetRenderTargetsAndUnorderedAccessViews(self) -> None: ... + def OMSetBlendState(self) -> None: ... + def OMSetDepthStencilState(self) -> None: ... + def SOSetTargets(self) -> None: ... + def DrawAuto(self) -> None: ... + def DrawIndexedInstancedIndirect(self) -> None: ... + def DrawInstancedIndirect(self) -> None: ... + def Dispatch(self) -> None: ... + def DispatchIndirect(self) -> None: ... + def RSSetState(self) -> None: ... + def RSSetViewports(self) -> None: ... + def RSSetScissorRects(self) -> None: ... + def CopySubresourceRegion( + self, + pDstResource: ID3D11Resource, + DstSubresource: UINT, + DstX: UINT, + DstY: UINT, + DstZ: UINT, + pSrcResource: ID3D11Resource, + SrcSubresource: UINT, + pSrcBox: D3D11_BOX, + ) -> None: ... + def CopyResource(pDstResource: ID3D11Resource, pSrcResource: ID3D11Resource) -> None: ... + def UpdateSubresource(self) -> None: ... + def CopyStructureCount(self) -> None: ... + def ClearRenderTargetView(self) -> None: ... + def ClearUnorderedAccessViewUint(self) -> None: ... + def ClearUnorderedAccessViewFloat(self) -> None: ... + def ClearDepthStencilView(self) -> None: ... + def GenerateMips(self) -> None: ... + def SetResourceMinLOD(self) -> None: ... + def GetResourceMinLOD(self) -> FLOAT: ... + def ResolveSubresource(self) -> None: ... + def ExecuteCommandList(self) -> None: ... + def HSSetShaderResources(self) -> None: ... + def HSSetShader(self) -> None: ... + def HSSetSamplers(self) -> None: ... + def HSSetConstantBuffers(self) -> None: ... + def DSSetShaderResources(self) -> None: ... + def DSSetShader(self) -> None: ... + def DSSetSamplers(self) -> None: ... + def DSSetConstantBuffers(self) -> None: ... + def CSSetShaderResources(self) -> None: ... + def CSSetUnorderedAccessViews(self) -> None: ... + def CSSetShader(self) -> None: ... + def CSSetSamplers(self) -> None: ... + def CSSetConstantBuffers(self) -> None: ... + def VSGetConstantBuffers(self) -> None: ... + def PSGetShaderResources(self) -> None: ... + def PSGetShader(self) -> None: ... + def PSGetSamplers(self) -> None: ... + def VSGetShader(self) -> None: ... + def PSGetConstantBuffers(self) -> None: ... + def IAGetInputLayout(self) -> None: ... + def IAGetVertexBuffers(self) -> None: ... + def IAGetIndexBuffer(self) -> None: ... + def GSGetConstantBuffers(self) -> None: ... + def GSGetShader(self) -> None: ... + def IAGetPrimitiveTopology(self) -> None: ... + def VSGetShaderResources(self) -> None: ... + def VSGetSamplers(self) -> None: ... + def GetPredication(self) -> None: ... + def GSGetShaderResources(self) -> None: ... + def GSGetSamplers(self) -> None: ... + def OMGetRenderTargets(self) -> None: ... + def OMGetRenderTargetsAndUnorderedAccessViews(self) -> None: ... + def OMGetBlendState(self) -> None: ... + def OMGetDepthStencilState(self) -> None: ... + def SOGetTargets(self) -> None: ... + def RSGetState(self) -> None: ... + def RSGetViewports(self) -> None: ... + def RSGetScissorRects(self) -> None: ... + def HSGetShaderResources(self) -> None: ... + def HSGetShader(self) -> None: ... + def HSGetSamplers(self) -> None: ... + def HSGetConstantBuffers(self) -> None: ... + def DSGetShaderResources(self) -> None: ... + def DSGetShader(self) -> None: ... + def DSGetSamplers(self) -> None: ... + def DSGetConstantBuffers(self) -> None: ... + def CSGetShaderResources(self) -> None: ... + def CSGetUnorderedAccessViews(self) -> None: ... + def CSGetShader(self) -> None: ... + def CSGetSamplers(self) -> None: ... + def CSGetConstantBuffers(self) -> None: ... + def ClearState(self) -> None: ... + def Flush(self) -> None: ... + def GetType(self) -> None: ... + def GetContextFlags(self) -> UINT: ... + def FinishCommandList(self) -> _HRESULT: ... class ID3D11Device(_IUnknown): - CreateBuffer: Callable[[], _HRESULT] - CreateTexture1D: Callable[[], _HRESULT] - CreateTexture2D: Callable[[D3D11_TEXTURE2D_DESC, c_void_p, _CArgObject], _HRESULT] - CreateTexture3D: Callable[[], _HRESULT] - CreateShaderResourceView: Callable[[], _HRESULT] - CreateUnorderedAccessView: Callable[[], _HRESULT] - CreateRenderTargetView: Callable[[], _HRESULT] - CreateDepthStencilView: Callable[[], _HRESULT] - CreateInputLayout: Callable[[], _HRESULT] - CreateVertexShader: Callable[[], _HRESULT] - CreateGeometryShader: Callable[[], _HRESULT] - CreateGeometryShaderWithStreamOutput: Callable[[], _HRESULT] - CreatePixelShader: Callable[[], _HRESULT] - CreateHullShader: Callable[[], _HRESULT] - CreateDomainShader: Callable[[], _HRESULT] - CreateComputeShader: Callable[[], _HRESULT] - CreateClassLinkage: Callable[[], _HRESULT] - CreateBlendState: Callable[[], _HRESULT] - CreateDepthStencilState: Callable[[], _HRESULT] - CreateRasterizerState: Callable[[], _HRESULT] - CreateSamplerState: Callable[[], _HRESULT] - CreateQuery: Callable[[], _HRESULT] - CreatePredicate: Callable[[], _HRESULT] - CreateCounter: Callable[[], _HRESULT] - CreateDeferredContext: Callable[[], _HRESULT] - OpenSharedResource: Callable[[], _HRESULT] - CheckFormatSupport: Callable[[], _HRESULT] - CheckMultisampleQualityLevels: Callable[[], _HRESULT] - CheckCounterInfo: Callable[[], _HRESULT] - CheckCounter: Callable[[], _HRESULT] - CheckFeatureSupport: Callable[[], _HRESULT] - GetPrivateData: Callable[[], _HRESULT] - SetPrivateData: Callable[[], _HRESULT] - SetPrivateDataInterface: Callable[[], _HRESULT] - GetFeatureLevel: Callable[[], c_int32] - GetCreationFlags: Callable[[], c_uint] - GetDeviceRemovedReason: Callable[[], _HRESULT] - GetImmediateContext: Callable[[_CArgObject], None] - SetExceptionMode: Callable[[], _HRESULT] - GetExceptionMode: Callable[[], c_uint] + def CreateBuffer(self) -> _HRESULT: ... + def CreateTexture1D(self) -> _HRESULT: ... + def CreateTexture2D(self, pDesc: D3D11_TEXTURE2D_DESC, pInitialData: c_void_p, ppTexture2D: _CArgObject) -> _HRESULT: ... + def CreateTexture3D(self) -> _HRESULT: ... + def CreateShaderResourceView(self) -> _HRESULT: ... + def CreateUnorderedAccessView(self) -> _HRESULT: ... + def CreateRenderTargetView(self) -> _HRESULT: ... + def CreateDepthStencilView(self) -> _HRESULT: ... + def CreateInputLayout(self) -> _HRESULT: ... + def CreateVertexShader(self) -> _HRESULT: ... + def CreateGeometryShader(self) -> _HRESULT: ... + def CreateGeometryShaderWithStreamOutput(self) -> _HRESULT: ... + def CreatePixelShader(self) -> _HRESULT: ... + def CreateHullShader(self) -> _HRESULT: ... + def CreateDomainShader(self) -> _HRESULT: ... + def CreateComputeShader(self) -> _HRESULT: ... + def CreateClassLinkage(self) -> _HRESULT: ... + def CreateBlendState(self) -> _HRESULT: ... + def CreateDepthStencilState(self) -> _HRESULT: ... + def CreateRasterizerState(self) -> _HRESULT: ... + def CreateSamplerState(self) -> _HRESULT: ... + def CreateQuery(self) -> _HRESULT: ... + def CreatePredicate(self) -> _HRESULT: ... + def CreateCounter(self) -> _HRESULT: ... + def CreateDeferredContext(self) -> _HRESULT: ... + def OpenSharedResource(self) -> _HRESULT: ... + def CheckFormatSupport(self) -> _HRESULT: ... + def CheckMultisampleQualityLevels(self) -> _HRESULT: ... + def CheckCounterInfo(self) -> _HRESULT: ... + def CheckCounter(self) -> _HRESULT: ... + def CheckFeatureSupport(self) -> _HRESULT: ... + def GetPrivateData(self) -> _HRESULT: ... + def SetPrivateData(self) -> _HRESULT: ... + def SetPrivateDataInterface(self) -> _HRESULT: ... + def GetFeatureLevel(self) -> c_int32: ... + def GetCreationFlags(self) -> c_uint: ... + def GetDeviceRemovedReason(self) -> _HRESULT: ... + def GetImmediateContext(self, ppImmediateContext: _CArgObject) -> None: ... + def SetExceptionMode(self) -> _HRESULT: ... + def GetExceptionMode(self) -> c_uint: ... def initialize_d3d_device(dxgi_adapter: IDXGIAdapter) -> tuple[ID3D11Device, ID3D11DeviceContext]: ... def describe_d3d11_texture_2d(d3d11_texture_2d: ID3D11Texture2D) -> D3D11_TEXTURE2D_DESC: ... diff --git a/stubs/D3DShot/d3dshot/dll/dxgi.pyi b/stubs/D3DShot/d3dshot/dll/dxgi.pyi index 820f5b60de3a..9e4c1ad92d4f 100644 --- a/stubs/D3DShot/d3dshot/dll/dxgi.pyi +++ b/stubs/D3DShot/d3dshot/dll/dxgi.pyi @@ -1,7 +1,8 @@ import sys from _typeshed import Incomplete from collections.abc import Callable -from ctypes import Array, Structure, _CArgObject, _CData, c_uint, c_ulong, wintypes +from ctypes import Array, Structure, _CArgObject, _CData, c_uint, c_ulong +from ctypes.wintypes import BOOL, DWORD, HMONITOR, INT, LARGE_INTEGER, LONG, PFLOAT, POINT, RECT, UINT, ULARGE_INTEGER, WCHAR from typing_extensions import TypeAlias, TypedDict from d3dshot.dll.d3d import ID3D11Device @@ -32,138 +33,140 @@ class _IUnknown: # From comtypes.IUnknown def Release(self) -> c_ulong: ... class _DXGIOutputPosition(TypedDict): - left: wintypes.LONG - top: wintypes.LONG - right: wintypes.LONG - bottom: wintypes.LONG + left: LONG + top: LONG + right: LONG + bottom: LONG class _DXGIOutput(TypedDict): name: str position: _DXGIOutputPosition - resolution: tuple[tuple[wintypes.LONG, wintypes.LONG], tuple[wintypes.LONG, wintypes.LONG]] + resolution: tuple[tuple[LONG, LONG], tuple[LONG, LONG]] rotation: int is_attached_to_desktop: bool class LUID(Structure): - LowPart: wintypes.DWORD - HighPart: wintypes.LONG + LowPart: DWORD + HighPart: LONG class DXGI_ADAPTER_DESC1(Structure): - Description: Array[wintypes.WCHAR] - VendorId: wintypes.UINT - DeviceId: wintypes.UINT - SubSysId: wintypes.UINT - Revision: wintypes.UINT - DedicatedVideoMemory: wintypes.ULARGE_INTEGER - DedicatedSystemMemory: wintypes.ULARGE_INTEGER - SharedSystemMemory: wintypes.ULARGE_INTEGER + Description: Array[WCHAR] + VendorId: UINT + DeviceId: UINT + SubSysId: UINT + Revision: UINT + DedicatedVideoMemory: ULARGE_INTEGER + DedicatedSystemMemory: ULARGE_INTEGER + SharedSystemMemory: ULARGE_INTEGER AdapterLuid: LUID - Flags: wintypes.UINT + Flags: UINT class DXGI_OUTPUT_DESC(Structure): - DeviceName: Array[wintypes.WCHAR] - DesktopCoordinates: wintypes.RECT - AttachedToDesktop: wintypes.BOOL - Rotation: wintypes.UINT - Monitor: wintypes.HMONITOR + DeviceName: Array[WCHAR] + DesktopCoordinates: RECT + AttachedToDesktop: BOOL + Rotation: UINT + Monitor: HMONITOR class DXGI_OUTDUPL_POINTER_POSITION(Structure): - Position: wintypes.POINT - Visible: wintypes.BOOL + Position: POINT + Visible: BOOL class DXGI_OUTDUPL_FRAME_INFO(Structure): - LastPresentTime: wintypes.LARGE_INTEGER - LastMouseUpdateTime: wintypes.LARGE_INTEGER - AccumulatedFrames: wintypes.UINT - RectsCoalesced: wintypes.BOOL - ProtectedContentMaskedOut: wintypes.BOOL + LastPresentTime: LARGE_INTEGER + LastMouseUpdateTime: LARGE_INTEGER + AccumulatedFrames: UINT + RectsCoalesced: BOOL + ProtectedContentMaskedOut: BOOL PointerPosition: DXGI_OUTDUPL_POINTER_POSITION - TotalMetadataBufferSize: wintypes.UINT - PointerShapeBufferSize: wintypes.UINT + TotalMetadataBufferSize: UINT + PointerShapeBufferSize: UINT class DXGI_MAPPED_RECT(Structure): - Pitch: wintypes.INT - pBits: wintypes.PFLOAT + Pitch: INT + pBits: PFLOAT class IDXGIObject(_IUnknown): - SetPrivateData: Callable[[], _HRESULT] - SetPrivateDataInterface: Callable[[], _HRESULT] - GetPrivateData: Callable[[], _HRESULT] - GetParent: Callable[[], _HRESULT] + def SetPrivateData(self) -> _HRESULT: ... + def SetPrivateDataInterface(self) -> _HRESULT: ... + def GetPrivateData(self) -> _HRESULT: ... + def GetParent(self) -> _HRESULT: ... class IDXGIDeviceSubObject(IDXGIObject): - GetDevice: Callable[[], _HRESULT] + def GetDevice(self) -> _HRESULT: ... class IDXGIResource(IDXGIDeviceSubObject): - GetSharedHandle: Callable[[], _HRESULT] - GetUsage: Callable[[], _HRESULT] - SetEvictionPriority: Callable[[], _HRESULT] - GetEvictionPriority: Callable[[], _HRESULT] + def GetSharedHandle(self) -> _HRESULT: ... + def GetUsage(self) -> _HRESULT: ... + def SetEvictionPriority(self) -> _HRESULT: ... + def GetEvictionPriority(self) -> _HRESULT: ... class IDXGISurface(IDXGIDeviceSubObject): - GetDesc: Callable[[], _HRESULT] - Map: Callable[[DXGI_MAPPED_RECT, wintypes.UINT], _HRESULT] - Unmap: Callable[[], _HRESULT] + def GetDesc(self) -> _HRESULT: ... + def Map(self, pLockedRect: DXGI_MAPPED_RECT, MapFlags: UINT) -> _HRESULT: ... + def Unmap(self) -> _HRESULT: ... class IDXGIOutputDuplication(IDXGIObject): - GetDesc: Callable[[], None] - AcquireNextFrame: Callable[[wintypes.UINT, DXGI_OUTDUPL_FRAME_INFO, _CArgObject], _HRESULT] - GetFrameDirtyRects: Callable[[], _HRESULT] - GetFrameMoveRects: Callable[[], _HRESULT] - GetFramePointerShape: Callable[[], _HRESULT] - MapDesktopSurface: Callable[[], _HRESULT] - UnMapDesktopSurface: Callable[[], _HRESULT] - ReleaseFrame: Callable[[], _HRESULT] + def GetDesc(self) -> None: ... + def AcquireNextFrame( + self, TimeoutInMilliseconds: UINT, pFrameInfo: DXGI_OUTDUPL_FRAME_INFO, ppDesktopResource: _CArgObject + ) -> _HRESULT: ... + def GetFrameDirtyRects(self) -> _HRESULT: ... + def GetFrameMoveRects(self) -> _HRESULT: ... + def GetFramePointerShape(self) -> _HRESULT: ... + def MapDesktopSurface(self) -> _HRESULT: ... + def UnMapDesktopSurface(self) -> _HRESULT: ... + def ReleaseFrame(self) -> _HRESULT: ... class IDXGIOutput(IDXGIObject): - GetDesc: Callable[[DXGI_OUTPUT_DESC], _HRESULT] - GetDisplayModeList: Callable[[], _HRESULT] - FindClosestMatchingMode: Callable[[], _HRESULT] - WaitForVBlank: Callable[[], _HRESULT] - TakeOwnership: Callable[[], _HRESULT] - ReleaseOwnership: Callable[[], None] - GetGammaControlCapabilities: Callable[[], _HRESULT] - SetGammaControl: Callable[[], _HRESULT] - GetGammaControl: Callable[[], _HRESULT] - SetDisplaySurface: Callable[[], _HRESULT] - GetDisplaySurfaceData: Callable[[], _HRESULT] - GetFrameStatistics: Callable[[], _HRESULT] + def GetDesc(self, pDesc: DXGI_OUTPUT_DESC) -> _HRESULT: ... + def GetDisplayModeList(self) -> _HRESULT: ... + def FindClosestMatchingMode(self) -> _HRESULT: ... + def WaitForVBlank(self) -> _HRESULT: ... + def TakeOwnership(self) -> _HRESULT: ... + def ReleaseOwnership(self) -> None: ... + def GetGammaControlCapabilities(self) -> _HRESULT: ... + def SetGammaControl(self) -> _HRESULT: ... + def GetGammaControl(self) -> _HRESULT: ... + def SetDisplaySurface(self) -> _HRESULT: ... + def GetDisplaySurfaceData(self) -> _HRESULT: ... + def GetFrameStatistics(self) -> _HRESULT: ... class IDXGIOutput1(IDXGIOutput): - GetDisplayModeList1: Callable[[], _HRESULT] - FindClosestMatchingMode1: Callable[[], _HRESULT] - GetDisplaySurfaceData1: Callable[[], _HRESULT] - DuplicateOutput: Callable[[ID3D11Device, _CArgObject], _HRESULT] + def GetDisplayModeList1(self) -> _HRESULT: ... + def FindClosestMatchingMode1(self) -> _HRESULT: ... + def GetDisplaySurfaceData1(self) -> _HRESULT: ... + def DuplicateOutput(self, pDevice: ID3D11Device, ppOutputDuplication: _CArgObject) -> _HRESULT: ... class IDXGIAdapter(IDXGIObject): - EnumOutputs: Callable[[wintypes.UINT, _CArgObject], _HRESULT] - GetDesc: Callable[[], _HRESULT] - CheckInterfaceSupport: Callable[[], _HRESULT] + def EnumOutputs(self, Output: UINT, ppOutput: _CArgObject) -> _HRESULT: ... + def GetDesc(self) -> _HRESULT: ... + def CheckInterfaceSupport(self) -> _HRESULT: ... class IDXGIAdapter1(IDXGIAdapter): - GetDesc1: Callable[[DXGI_ADAPTER_DESC1], _HRESULT] + def GetDesc1(self, pDesc: DXGI_ADAPTER_DESC1) -> _HRESULT: ... class IDXGIFactory(IDXGIObject): - EnumAdapters: Callable[[], _HRESULT] - MakeWindowAssociation: Callable[[], _HRESULT] - GetWindowAssociation: Callable[[], _HRESULT] - CreateSwapChain: Callable[[], _HRESULT] - CreateSoftwareAdapter: Callable[[], _HRESULT] + def EnumAdapters(self) -> _HRESULT: ... + def MakeWindowAssociation(self) -> _HRESULT: ... + def GetWindowAssociation(self) -> _HRESULT: ... + def CreateSwapChain(self) -> _HRESULT: ... + def CreateSoftwareAdapter(self) -> _HRESULT: ... class IDXGIFactory1(IDXGIFactory): - EnumAdapters1: Callable[[c_uint, _CArgObject], _HRESULT] - IsCurrent: Callable[[], wintypes.BOOL] + def EnumAdapters1(self, Adapter: c_uint, ppAdapter: _CArgObject) -> _HRESULT: ... + def IsCurrent(self) -> BOOL: ... def initialize_dxgi_factory() -> IDXGIFactory1: ... def discover_dxgi_adapters(dxgi_factory: IDXGIFactory1) -> list[IDXGIAdapter1]: ... -def describe_dxgi_adapter(dxgi_adapter: IDXGIAdapter1) -> Array[wintypes.WCHAR]: ... +def describe_dxgi_adapter(dxgi_adapter: IDXGIAdapter1) -> Array[WCHAR]: ... def discover_dxgi_outputs(dxgi_adapter: IDXGIAdapter) -> list[IDXGIOutput1]: ... def describe_dxgi_output(dxgi_output: IDXGIOutput) -> _DXGIOutput: ... def initialize_dxgi_output_duplication(dxgi_output: IDXGIOutput1, d3d_device: ID3D11Device) -> IDXGIOutputDuplication: ... def get_dxgi_output_duplication_frame( dxgi_output_duplication: IDXGIOutputDuplication, d3d_device: ID3D11Device, - process_func: Callable[[wintypes.PFLOAT, int, int, int, tuple[int, int, int, int], int], _Frame | None] | None = ..., + process_func: Callable[[PFLOAT, int, int, int, tuple[int, int, int, int], int], _Frame | None] | None = ..., width: int = ..., height: int = ..., region: tuple[int, int, int, int] | None = ..., From 1d7734cd58039a5105a981c3372186f037f7bbb1 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 10 Sep 2022 22:55:51 -0400 Subject: [PATCH 19/30] Some PR comments, about comments --- pyrightconfig.stricter.json | 4 ++-- stubs/D3DShot/METADATA.toml | 2 ++ stubs/D3DShot/d3dshot/capture_output.pyi | 1 + stubs/D3DShot/d3dshot/d3dshot.pyi | 1 + stubs/D3DShot/d3dshot/display.pyi | 1 + stubs/D3DShot/d3dshot/dll/d3d.pyi | 9 ++++++--- stubs/D3DShot/d3dshot/dll/dxgi.pyi | 14 ++++++-------- 7 files changed, 19 insertions(+), 13 deletions(-) diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index b09b7c1162cf..473806edca98 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -38,6 +38,7 @@ "stubs/caldav", "stubs/commonmark", "stubs/cryptography", + "stubs/D3DShot", "stubs/dateparser", "stubs/dj-database-url", "stubs/docutils", @@ -90,8 +91,7 @@ "stubs/tzlocal/tzlocal/utils.pyi", "stubs/ttkthemes", "stubs/urllib3", - "stubs/vobject", - "stubs/D3DShot" + "stubs/vobject" ], "typeCheckingMode": "basic", "strictListInference": true, diff --git a/stubs/D3DShot/METADATA.toml b/stubs/D3DShot/METADATA.toml index 13c4c3be547e..d6bdd1ba0ba9 100644 --- a/stubs/D3DShot/METADATA.toml +++ b/stubs/D3DShot/METADATA.toml @@ -2,4 +2,6 @@ version = "0.1.*" requires = ["types-Pillow"] [tool.stubtest] +# The library only works on Windows; we currently only run stubtest on Ubuntu for third-party stubs in CI. +# See #8660 skip = true diff --git a/stubs/D3DShot/d3dshot/capture_output.pyi b/stubs/D3DShot/d3dshot/capture_output.pyi index d0d4b8840a86..10e1a0dd323d 100644 --- a/stubs/D3DShot/d3dshot/capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_output.pyi @@ -6,6 +6,7 @@ from typing_extensions import Literal, TypeAlias from PIL import Image _Frame: TypeAlias = Image.Image | Incomplete +# FIXME: When #5768 is resolved: # _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | _Tensor class CaptureOutputs(enum.Enum): diff --git a/stubs/D3DShot/d3dshot/d3dshot.pyi b/stubs/D3DShot/d3dshot/d3dshot.pyi index efc2eee4607c..d27d7c12d4a0 100644 --- a/stubs/D3DShot/d3dshot/d3dshot.pyi +++ b/stubs/D3DShot/d3dshot/d3dshot.pyi @@ -8,6 +8,7 @@ from d3dshot.display import Display as Display from PIL import Image _Frame: TypeAlias = Image.Image | Incomplete +# FIXME: When #5768 is resolved: # _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | _Tensor class Singleton(type): diff --git a/stubs/D3DShot/d3dshot/display.pyi b/stubs/D3DShot/d3dshot/display.pyi index 30394a0d64f5..4181f4ae0e76 100644 --- a/stubs/D3DShot/d3dshot/display.pyi +++ b/stubs/D3DShot/d3dshot/display.pyi @@ -6,6 +6,7 @@ from typing_extensions import Literal, TypeAlias from PIL import Image _Frame: TypeAlias = Image.Image | Incomplete +# FIXME: When #5768 is resolved: # _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | _Tensor class Display: diff --git a/stubs/D3DShot/d3dshot/dll/d3d.pyi b/stubs/D3DShot/d3dshot/dll/d3d.pyi index 3e85e13ed56b..be3737dad1a1 100644 --- a/stubs/D3DShot/d3dshot/dll/d3d.pyi +++ b/stubs/D3DShot/d3dshot/dll/d3d.pyi @@ -1,6 +1,6 @@ import sys from _typeshed import Incomplete -from ctypes import Structure, _CArgObject, c_int32, c_uint, c_void_p +from ctypes import Structure, _CArgObject, _CData, c_int32, c_uint, c_ulong, c_void_p from ctypes.wintypes import FLOAT, UINT from typing_extensions import TypeAlias @@ -18,8 +18,11 @@ else: # TODO: Complete types once we can import non-types dependencies # See: https://github.com/python/typeshed/issues/5768 -# import comtypes -_IUnknown: TypeAlias = Incomplete +# from comtypes import IUnknown +class _IUnknown: # From comtypes.IUnknown + def QueryInterface(self, interface: type, iid: _CData | None = ...) -> _HRESULT: ... + def AddRef(self) -> c_ulong: ... + def Release(self) -> c_ulong: ... class DXGI_SAMPLE_DESC(Structure): Count: UINT diff --git a/stubs/D3DShot/d3dshot/dll/dxgi.pyi b/stubs/D3DShot/d3dshot/dll/dxgi.pyi index 9e4c1ad92d4f..299a4b43040b 100644 --- a/stubs/D3DShot/d3dshot/dll/dxgi.pyi +++ b/stubs/D3DShot/d3dshot/dll/dxgi.pyi @@ -9,13 +9,16 @@ from d3dshot.dll.d3d import ID3D11Device from PIL import Image # TODO: Complete types once we can import non-types dependencies -# See: https://github.com/python/typeshed/issues/5768 +# See: #5768 # from torch import Tensor -# import comtypes +# from comtypes import IUnknown # import numpy.typing as npt -# _IUnknown: TypeAlias = Incomplete _Frame: TypeAlias = Image.Image | Incomplete # _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | Tensor +class _IUnknown: # From comtypes.IUnknown + def QueryInterface(self, interface: type, iid: _CData | None = ...) -> _HRESULT: ... + def AddRef(self) -> c_ulong: ... + def Release(self) -> c_ulong: ... # mypy does not support os.name checks, while pyright does https://github.com/python/mypy/issues/13002 # import os @@ -27,11 +30,6 @@ if sys.platform == "win32": else: _HRESULT: TypeAlias = Incomplete -class _IUnknown: # From comtypes.IUnknown - def QueryInterface(self, interface: type, iid: _CData | None = ...) -> _HRESULT: ... - def AddRef(self) -> c_ulong: ... - def Release(self) -> c_ulong: ... - class _DXGIOutputPosition(TypedDict): left: LONG top: LONG From 041c2f3f46084bf85f68a630eed8771616e527b2 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 11 Sep 2022 00:19:16 -0400 Subject: [PATCH 20/30] Missed self arg --- stubs/D3DShot/d3dshot/dll/d3d.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/D3DShot/d3dshot/dll/d3d.pyi b/stubs/D3DShot/d3dshot/dll/d3d.pyi index be3737dad1a1..006481c8a6e9 100644 --- a/stubs/D3DShot/d3dshot/dll/d3d.pyi +++ b/stubs/D3DShot/d3dshot/dll/d3d.pyi @@ -113,7 +113,7 @@ class ID3D11DeviceContext(ID3D11DeviceChild): SrcSubresource: UINT, pSrcBox: D3D11_BOX, ) -> None: ... - def CopyResource(pDstResource: ID3D11Resource, pSrcResource: ID3D11Resource) -> None: ... + def CopyResource(self, pDstResource: ID3D11Resource, pSrcResource: ID3D11Resource) -> None: ... def UpdateSubresource(self) -> None: ... def CopyStructureCount(self) -> None: ... def ClearRenderTargetView(self) -> None: ... From ba1510137d5e6c54dc9190323168f0e28243a1bc Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 11 Sep 2022 01:08:09 -0400 Subject: [PATCH 21/30] _Pointer --- stubs/D3DShot/d3dshot/dll/d3d.pyi | 22 ++++++++------- stubs/D3DShot/d3dshot/dll/dxgi.pyi | 43 +++++++++++++++++++----------- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/stubs/D3DShot/d3dshot/dll/d3d.pyi b/stubs/D3DShot/d3dshot/dll/d3d.pyi index 006481c8a6e9..67521f476159 100644 --- a/stubs/D3DShot/d3dshot/dll/d3d.pyi +++ b/stubs/D3DShot/d3dshot/dll/d3d.pyi @@ -1,6 +1,6 @@ import sys from _typeshed import Incomplete -from ctypes import Structure, _CArgObject, _CData, c_int32, c_uint, c_ulong, c_void_p +from ctypes import Structure, _CData, _Pointer, c_int32, c_uint, c_ulong, c_void_p from ctypes.wintypes import FLOAT, UINT from typing_extensions import TypeAlias @@ -19,7 +19,7 @@ else: # TODO: Complete types once we can import non-types dependencies # See: https://github.com/python/typeshed/issues/5768 # from comtypes import IUnknown -class _IUnknown: # From comtypes.IUnknown +class _IUnknown(_CData): # From comtypes.IUnknown def QueryInterface(self, interface: type, iid: _CData | None = ...) -> _HRESULT: ... def AddRef(self) -> c_ulong: ... def Release(self) -> c_ulong: ... @@ -60,7 +60,7 @@ class ID3D11Resource(ID3D11DeviceChild): def GetEvictionPriority(self) -> UINT: ... class ID3D11Texture2D(ID3D11Resource): - def GetDesc(self, pDesc: D3D11_TEXTURE2D_DESC) -> None: ... + def GetDesc(self, pDesc: _Pointer[D3D11_TEXTURE2D_DESC]) -> None: ... class ID3D11DeviceContext(ID3D11DeviceChild): def VSSetConstantBuffers(self) -> None: ... @@ -104,16 +104,16 @@ class ID3D11DeviceContext(ID3D11DeviceChild): def RSSetScissorRects(self) -> None: ... def CopySubresourceRegion( self, - pDstResource: ID3D11Resource, + pDstResource: _Pointer[ID3D11Resource], DstSubresource: UINT, DstX: UINT, DstY: UINT, DstZ: UINT, - pSrcResource: ID3D11Resource, + pSrcResource: _Pointer[ID3D11Resource], SrcSubresource: UINT, - pSrcBox: D3D11_BOX, + pSrcBox: _Pointer[D3D11_BOX], ) -> None: ... - def CopyResource(self, pDstResource: ID3D11Resource, pSrcResource: ID3D11Resource) -> None: ... + def CopyResource(self, pDstResource: _Pointer[ID3D11Resource], pSrcResource: _Pointer[ID3D11Resource]) -> None: ... def UpdateSubresource(self) -> None: ... def CopyStructureCount(self) -> None: ... def ClearRenderTargetView(self) -> None: ... @@ -185,7 +185,9 @@ class ID3D11DeviceContext(ID3D11DeviceChild): class ID3D11Device(_IUnknown): def CreateBuffer(self) -> _HRESULT: ... def CreateTexture1D(self) -> _HRESULT: ... - def CreateTexture2D(self, pDesc: D3D11_TEXTURE2D_DESC, pInitialData: c_void_p, ppTexture2D: _CArgObject) -> _HRESULT: ... + def CreateTexture2D( + self, pDesc: _Pointer[D3D11_TEXTURE2D_DESC], pInitialData: c_void_p, ppTexture2D: _Pointer[_Pointer[ID3D11Texture2D]] + ) -> _HRESULT: ... def CreateTexture3D(self) -> _HRESULT: ... def CreateShaderResourceView(self) -> _HRESULT: ... def CreateUnorderedAccessView(self) -> _HRESULT: ... @@ -220,10 +222,10 @@ class ID3D11Device(_IUnknown): def GetFeatureLevel(self) -> c_int32: ... def GetCreationFlags(self) -> c_uint: ... def GetDeviceRemovedReason(self) -> _HRESULT: ... - def GetImmediateContext(self, ppImmediateContext: _CArgObject) -> None: ... + def GetImmediateContext(self, ppImmediateContext: _Pointer[_Pointer[ID3D11DeviceContext]]) -> None: ... def SetExceptionMode(self) -> _HRESULT: ... def GetExceptionMode(self) -> c_uint: ... -def initialize_d3d_device(dxgi_adapter: IDXGIAdapter) -> tuple[ID3D11Device, ID3D11DeviceContext]: ... +def initialize_d3d_device(dxgi_adapter: _Pointer[IDXGIAdapter]) -> tuple[ID3D11Device, ID3D11DeviceContext]: ... def describe_d3d11_texture_2d(d3d11_texture_2d: ID3D11Texture2D) -> D3D11_TEXTURE2D_DESC: ... def prepare_d3d11_texture_2d_for_cpu(d3d11_texture_2d: ID3D11Texture2D, d3d_device: ID3D11Device) -> ID3D11Texture2D: ... diff --git a/stubs/D3DShot/d3dshot/dll/dxgi.pyi b/stubs/D3DShot/d3dshot/dll/dxgi.pyi index 299a4b43040b..481b4938d617 100644 --- a/stubs/D3DShot/d3dshot/dll/dxgi.pyi +++ b/stubs/D3DShot/d3dshot/dll/dxgi.pyi @@ -1,8 +1,9 @@ import sys from _typeshed import Incomplete from collections.abc import Callable -from ctypes import Array, Structure, _CArgObject, _CData, c_uint, c_ulong +from ctypes import Array, Structure, _CData, _Pointer, c_uint, c_ulong from ctypes.wintypes import BOOL, DWORD, HMONITOR, INT, LARGE_INTEGER, LONG, PFLOAT, POINT, RECT, UINT, ULARGE_INTEGER, WCHAR +from typing import TypeVar from typing_extensions import TypeAlias, TypedDict from d3dshot.dll.d3d import ID3D11Device @@ -15,7 +16,7 @@ from PIL import Image # import numpy.typing as npt _Frame: TypeAlias = Image.Image | Incomplete # _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | Tensor -class _IUnknown: # From comtypes.IUnknown +class _IUnknown(_CData): # From comtypes.IUnknown def QueryInterface(self, interface: type, iid: _CData | None = ...) -> _HRESULT: ... def AddRef(self) -> c_ulong: ... def Release(self) -> c_ulong: ... @@ -43,6 +44,9 @@ class _DXGIOutput(TypedDict): rotation: int is_attached_to_desktop: bool +_ProcessFuncRegionArg = TypeVar("_ProcessFuncRegionArg", tuple[int, int, int, int], None) +_ProcessFuncReturn = TypeVar("_ProcessFuncReturn", _Frame, None) + class LUID(Structure): LowPart: DWORD HighPart: LONG @@ -101,13 +105,16 @@ class IDXGIResource(IDXGIDeviceSubObject): class IDXGISurface(IDXGIDeviceSubObject): def GetDesc(self) -> _HRESULT: ... - def Map(self, pLockedRect: DXGI_MAPPED_RECT, MapFlags: UINT) -> _HRESULT: ... + def Map(self, pLockedRect: _Pointer[DXGI_MAPPED_RECT], MapFlags: UINT) -> _HRESULT: ... def Unmap(self) -> _HRESULT: ... class IDXGIOutputDuplication(IDXGIObject): def GetDesc(self) -> None: ... def AcquireNextFrame( - self, TimeoutInMilliseconds: UINT, pFrameInfo: DXGI_OUTDUPL_FRAME_INFO, ppDesktopResource: _CArgObject + self, + TimeoutInMilliseconds: UINT, + pFrameInfo: _Pointer[DXGI_OUTDUPL_FRAME_INFO], + ppDesktopResource: _Pointer[_Pointer[IDXGIResource]], ) -> _HRESULT: ... def GetFrameDirtyRects(self) -> _HRESULT: ... def GetFrameMoveRects(self) -> _HRESULT: ... @@ -117,7 +124,7 @@ class IDXGIOutputDuplication(IDXGIObject): def ReleaseFrame(self) -> _HRESULT: ... class IDXGIOutput(IDXGIObject): - def GetDesc(self, pDesc: DXGI_OUTPUT_DESC) -> _HRESULT: ... + def GetDesc(self, pDesc: _Pointer[DXGI_OUTPUT_DESC]) -> _HRESULT: ... def GetDisplayModeList(self) -> _HRESULT: ... def FindClosestMatchingMode(self) -> _HRESULT: ... def WaitForVBlank(self) -> _HRESULT: ... @@ -134,15 +141,17 @@ class IDXGIOutput1(IDXGIOutput): def GetDisplayModeList1(self) -> _HRESULT: ... def FindClosestMatchingMode1(self) -> _HRESULT: ... def GetDisplaySurfaceData1(self) -> _HRESULT: ... - def DuplicateOutput(self, pDevice: ID3D11Device, ppOutputDuplication: _CArgObject) -> _HRESULT: ... + def DuplicateOutput( + self, pDevice: _Pointer[ID3D11Device], ppOutputDuplication: _Pointer[_Pointer[IDXGIOutputDuplication]] + ) -> _HRESULT: ... class IDXGIAdapter(IDXGIObject): - def EnumOutputs(self, Output: UINT, ppOutput: _CArgObject) -> _HRESULT: ... + def EnumOutputs(self, Output: UINT, ppOutput: _Pointer[_Pointer[IDXGIOutput]]) -> _HRESULT: ... def GetDesc(self) -> _HRESULT: ... def CheckInterfaceSupport(self) -> _HRESULT: ... class IDXGIAdapter1(IDXGIAdapter): - def GetDesc1(self, pDesc: DXGI_ADAPTER_DESC1) -> _HRESULT: ... + def GetDesc1(self, pDesc: _Pointer[DXGI_ADAPTER_DESC1]) -> _HRESULT: ... class IDXGIFactory(IDXGIObject): def EnumAdapters(self) -> _HRESULT: ... @@ -152,21 +161,23 @@ class IDXGIFactory(IDXGIObject): def CreateSoftwareAdapter(self) -> _HRESULT: ... class IDXGIFactory1(IDXGIFactory): - def EnumAdapters1(self, Adapter: c_uint, ppAdapter: _CArgObject) -> _HRESULT: ... + def EnumAdapters1(self, Adapter: c_uint, ppAdapter: _Pointer[_Pointer[IDXGIAdapter1]]) -> _HRESULT: ... def IsCurrent(self) -> BOOL: ... -def initialize_dxgi_factory() -> IDXGIFactory1: ... -def discover_dxgi_adapters(dxgi_factory: IDXGIFactory1) -> list[IDXGIAdapter1]: ... +def initialize_dxgi_factory() -> _Pointer[IDXGIFactory1]: ... +def discover_dxgi_adapters(dxgi_factory: IDXGIFactory1) -> list[_Pointer[IDXGIAdapter1]]: ... def describe_dxgi_adapter(dxgi_adapter: IDXGIAdapter1) -> Array[WCHAR]: ... -def discover_dxgi_outputs(dxgi_adapter: IDXGIAdapter) -> list[IDXGIOutput1]: ... +def discover_dxgi_outputs(dxgi_adapter: IDXGIAdapter) -> list[_Pointer[IDXGIOutput1]]: ... def describe_dxgi_output(dxgi_output: IDXGIOutput) -> _DXGIOutput: ... -def initialize_dxgi_output_duplication(dxgi_output: IDXGIOutput1, d3d_device: ID3D11Device) -> IDXGIOutputDuplication: ... +def initialize_dxgi_output_duplication( + dxgi_output: IDXGIOutput1, d3d_device: _Pointer[ID3D11Device] +) -> _Pointer[IDXGIOutputDuplication]: ... def get_dxgi_output_duplication_frame( dxgi_output_duplication: IDXGIOutputDuplication, d3d_device: ID3D11Device, - process_func: Callable[[PFLOAT, int, int, int, tuple[int, int, int, int], int], _Frame | None] | None = ..., + process_func: Callable[[PFLOAT, int, int, int, _ProcessFuncRegionArg, int], _ProcessFuncReturn] | None = ..., width: int = ..., height: int = ..., - region: tuple[int, int, int, int] | None = ..., + region: _ProcessFuncRegionArg = ..., rotation: int = ..., -) -> _Frame: ... +) -> _ProcessFuncReturn | None: ... From df2ec927b59431e5a58cae517c2c335b90c0652d Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 11 Sep 2022 13:58:39 -0400 Subject: [PATCH 22/30] Remove nt check comment --- stubs/D3DShot/d3dshot/dll/d3d.pyi | 3 --- stubs/D3DShot/d3dshot/dll/dxgi.pyi | 3 --- 2 files changed, 6 deletions(-) diff --git a/stubs/D3DShot/d3dshot/dll/d3d.pyi b/stubs/D3DShot/d3dshot/dll/d3d.pyi index 67521f476159..211114b36eda 100644 --- a/stubs/D3DShot/d3dshot/dll/d3d.pyi +++ b/stubs/D3DShot/d3dshot/dll/d3d.pyi @@ -6,9 +6,6 @@ from typing_extensions import TypeAlias from d3dshot.dll.dxgi import IDXGIAdapter -# mypy does not support os.name checks, while pyright does https://github.com/python/mypy/issues/13002 -# import os -# if os.name == "nt": # noqa: Y002 if sys.platform == "win32": from ctypes import HRESULT diff --git a/stubs/D3DShot/d3dshot/dll/dxgi.pyi b/stubs/D3DShot/d3dshot/dll/dxgi.pyi index 481b4938d617..374a244aa0c9 100644 --- a/stubs/D3DShot/d3dshot/dll/dxgi.pyi +++ b/stubs/D3DShot/d3dshot/dll/dxgi.pyi @@ -21,9 +21,6 @@ class _IUnknown(_CData): # From comtypes.IUnknown def AddRef(self) -> c_ulong: ... def Release(self) -> c_ulong: ... -# mypy does not support os.name checks, while pyright does https://github.com/python/mypy/issues/13002 -# import os -# if os.name == "nt": # noqa: Y002 if sys.platform == "win32": from ctypes import HRESULT From b16a70f8163e9fad6dcdf6c33986e19839c72621 Mon Sep 17 00:00:00 2001 From: Avasam Date: Mon, 12 Sep 2022 01:04:09 -0400 Subject: [PATCH 23/30] More PR comments and a few more completions --- pyrightconfig.stricter.json | 1 - stubs/D3DShot/d3dshot/capture_output.pyi | 13 ++++-- .../capture_outputs/numpy_capture_output.pyi | 5 ++- .../numpy_float_capture_output.pyi | 2 + .../capture_outputs/pil_capture_output.pyi | 6 +-- .../pytorch_capture_output.pyi | 3 +- stubs/D3DShot/d3dshot/d3dshot.pyi | 15 ++----- stubs/D3DShot/d3dshot/display.pyi | 42 +++++++++---------- stubs/D3DShot/d3dshot/dll/__init__.pyi | 10 +++++ stubs/D3DShot/d3dshot/dll/dxgi.pyi | 19 ++------- 10 files changed, 58 insertions(+), 58 deletions(-) diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index 473806edca98..668861ee5540 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -38,7 +38,6 @@ "stubs/caldav", "stubs/commonmark", "stubs/cryptography", - "stubs/D3DShot", "stubs/dateparser", "stubs/dj-database-url", "stubs/docutils", diff --git a/stubs/D3DShot/d3dshot/capture_output.pyi b/stubs/D3DShot/d3dshot/capture_output.pyi index 10e1a0dd323d..ea0bc4b40ec0 100644 --- a/stubs/D3DShot/d3dshot/capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_output.pyi @@ -1,13 +1,20 @@ import enum from _typeshed import Incomplete +from collections.abc import Sequence from ctypes import _CVoidConstPLike from typing_extensions import Literal, TypeAlias from PIL import Image _Frame: TypeAlias = Image.Image | Incomplete -# FIXME: When #5768 is resolved: -# _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | _Tensor +_Frames: TypeAlias = Image.Image | Sequence[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 +# _Frames: TypeAlias = Image.Image | Sequence[npt.NDArray[np.int32]] | Sequence[npt.NDArray[np.float32]] | Sequence[_Tensor] class CaptureOutputs(enum.Enum): PIL: int @@ -34,4 +41,4 @@ class CaptureOutput: rotation: int, ) -> _Frame: ... def to_pil(self, frame: _Frame) -> Image.Image: ... - def stack(self, frames: list[_Frame], stack_dimension: Literal["first", "last"]) -> _Frame: ... + def stack(self, frames: _Frames, stack_dimension: Literal["first", "last"]) -> _Frame: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi index fd1e594df656..083eeb798560 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi @@ -1,4 +1,5 @@ from _typeshed import Incomplete +from collections.abc import Sequence from ctypes import _CVoidConstPLike from typing_extensions import Literal, TypeAlias @@ -6,7 +7,7 @@ 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 +# See: #5768 # import numpy as np # import numpy.typing as npt # _NDArray: TypeAlias = npt.NDArray[np.int32] @@ -25,4 +26,4 @@ class NumpyCaptureOutput(CaptureOutput): rotation: int, ) -> _NDArray: ... def to_pil(self, frame: _NDArray) -> Image.Image: ... - def stack(self, frames: list[_NDArray] | _NDArray, stack_dimension: Literal["first", "last"]) -> _NDArray: ... + def stack(self, frames: Sequence[_NDArray] | _NDArray, stack_dimension: Literal["first", "last"]) -> _NDArray: ... 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 677785053e16..49d4e5d7ea75 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/numpy_float_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/numpy_float_capture_output.pyi @@ -1,3 +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 class NumpyFloatCaptureOutput(NumpyCaptureOutput): ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi index 86f7a306bd50..9397a6316c16 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi @@ -5,8 +5,8 @@ from typing_extensions import TypeAlias from d3dshot.capture_output import CaptureOutput from PIL import Image -_T = TypeVar("_T") _Unused: TypeAlias = object +_ImageT = TypeVar("_ImageT", bound=Image.Image) class PILCaptureOutput(CaptureOutput): def __init__(self) -> None: ... @@ -20,5 +20,5 @@ class PILCaptureOutput(CaptureOutput): region: tuple[int, int, int, int], rotation: int, ) -> Image.Image: ... - def to_pil(self, frame: _T) -> _T: ... - def stack(self, frames: _T, stack_dimension: _Unused) -> _T: ... + def to_pil(self, frame: _ImageT) -> _ImageT: ... + def stack(self, frames: _ImageT, stack_dimension: _Unused) -> _ImageT: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi index f1536dcb0ddf..4498bd52f01a 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi @@ -1,4 +1,5 @@ from _typeshed import Incomplete +from collections.abc import Sequence from ctypes import _CVoidConstPLike from typing_extensions import Literal, TypeAlias @@ -23,4 +24,4 @@ class PytorchCaptureOutput(CaptureOutput): rotation: int, ) -> _Tensor: ... def to_pil(self, frame: _Tensor) -> Image.Image: ... - def stack(self, frames: list[_Tensor], stack_dimension: Literal["first", "last"]) -> _Tensor: ... + def stack(self, frames: Sequence[_Tensor], stack_dimension: Literal["first", "last"]) -> _Tensor: ... diff --git a/stubs/D3DShot/d3dshot/d3dshot.pyi b/stubs/D3DShot/d3dshot/d3dshot.pyi index d27d7c12d4a0..4b7ae3f34e8e 100644 --- a/stubs/D3DShot/d3dshot/d3dshot.pyi +++ b/stubs/D3DShot/d3dshot/d3dshot.pyi @@ -1,20 +1,11 @@ -from _typeshed import Incomplete from collections import deque -from typing import Any -from typing_extensions import TypeAlias -from d3dshot.capture_output import CaptureOutput as CaptureOutput, CaptureOutputs as CaptureOutputs +from d3dshot.capture_output import CaptureOutput as CaptureOutput, CaptureOutputs as CaptureOutputs, _Frame from d3dshot.display import Display as Display -from PIL import Image -_Frame: TypeAlias = Image.Image | Incomplete -# FIXME: When #5768 is resolved: -# _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | _Tensor +class Singleton(type): ... -class Singleton(type): - def __call__(cls, *args: Any, **kwargs: Any) -> Any: ... - -class D3DShot: +class D3DShot(metaclass=Singleton): displays: list[Display] display: Display capture_output: CaptureOutput diff --git a/stubs/D3DShot/d3dshot/display.pyi b/stubs/D3DShot/d3dshot/display.pyi index 4181f4ae0e76..a4b4d8b66d25 100644 --- a/stubs/D3DShot/d3dshot/display.pyi +++ b/stubs/D3DShot/d3dshot/display.pyi @@ -1,46 +1,46 @@ -from _typeshed import Incomplete -from collections.abc import Callable -from ctypes.wintypes import PFLOAT -from typing_extensions import Literal, TypeAlias +from ctypes import _Pointer +from typing_extensions import TypedDict -from PIL import Image +from d3dshot.dll import _ProcessFunc, _ProcessFuncRegionArg, _ProcessFuncReturn +from d3dshot.dll.d3d import ID3D11Device, ID3D11DeviceContext +from d3dshot.dll.dxgi import IDXGIAdapter, IDXGIOutput1, IDXGIOutputDuplication -_Frame: TypeAlias = Image.Image | Incomplete -# FIXME: When #5768 is resolved: -# _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | _Tensor +class _PositionDict(TypedDict): + left: int + top: int + right: int + bottom: int class Display: name: str adapter_name: str resolution: tuple[int, int] - position: dict[Literal["left", "top", "right", "bottom"], int] + position: _PositionDict rotation: int scale_factor: float is_primary: bool hmonitor: int - dxgi_output: Incomplete | None - dxgi_adapter: Incomplete | None - d3d_device: Incomplete - d3d_device_context: Incomplete - dxgi_output_duplication: Incomplete + dxgi_output: IDXGIOutput1 | None + dxgi_adapter: _Pointer[IDXGIAdapter] | None + d3d_device: ID3D11Device + d3d_device_context: ID3D11DeviceContext + dxgi_output_duplication: _Pointer[IDXGIOutputDuplication] def __init__( self, name: str | None = ..., adapter_name: str | None = ..., resolution: tuple[int, int] | None = ..., - position: dict[Literal["left", "top", "right", "bottom"], int] | None = ..., + position: _PositionDict | None = ..., rotation: int | None = ..., scale_factor: float | None = ..., is_primary: bool = ..., hmonitor: int | None = ..., - dxgi_output: Incomplete | None = ..., - dxgi_adapter: Incomplete | None = ..., + dxgi_output: IDXGIOutput1 | None = ..., + dxgi_adapter: _Pointer[IDXGIAdapter] | None = ..., ) -> None: ... def capture( - self, - process_func: Callable[[PFLOAT, int, int, int, tuple[int, int, int, int], int], _Frame | None] | None, - region: tuple[int, int, int, int] | None = ..., - ) -> _Frame: ... + self, process_func: _ProcessFunc[_ProcessFuncRegionArg, _ProcessFuncReturn] | None, region: _ProcessFuncRegionArg = ... + ) -> _ProcessFuncReturn: ... @classmethod def discover_displays(cls) -> list[Display]: ... diff --git a/stubs/D3DShot/d3dshot/dll/__init__.pyi b/stubs/D3DShot/d3dshot/dll/__init__.pyi index e69de29bb2d1..7a9d279173de 100644 --- a/stubs/D3DShot/d3dshot/dll/__init__.pyi +++ b/stubs/D3DShot/d3dshot/dll/__init__.pyi @@ -0,0 +1,10 @@ +from collections.abc import Callable +from ctypes.wintypes import PFLOAT +from typing import TypeVar +from typing_extensions import TypeAlias + +from d3dshot.capture_output import _Frame + +_ProcessFuncRegionArg = TypeVar("_ProcessFuncRegionArg", tuple[int, int, int, int], None) +_ProcessFuncReturn = TypeVar("_ProcessFuncReturn", _Frame, None) +_ProcessFunc: TypeAlias = Callable[[PFLOAT, int, int, int, int, _ProcessFuncRegionArg, int], _ProcessFuncReturn] # noqa: Y047 diff --git a/stubs/D3DShot/d3dshot/dll/dxgi.pyi b/stubs/D3DShot/d3dshot/dll/dxgi.pyi index 374a244aa0c9..bf3c991578e6 100644 --- a/stubs/D3DShot/d3dshot/dll/dxgi.pyi +++ b/stubs/D3DShot/d3dshot/dll/dxgi.pyi @@ -1,21 +1,13 @@ import sys from _typeshed import Incomplete -from collections.abc import Callable from ctypes import Array, Structure, _CData, _Pointer, c_uint, c_ulong from ctypes.wintypes import BOOL, DWORD, HMONITOR, INT, LARGE_INTEGER, LONG, PFLOAT, POINT, RECT, UINT, ULARGE_INTEGER, WCHAR -from typing import TypeVar from typing_extensions import TypeAlias, TypedDict +from d3dshot.dll import _ProcessFunc, _ProcessFuncRegionArg, _ProcessFuncReturn from d3dshot.dll.d3d import ID3D11Device -from PIL import Image - -# 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 | Incomplete -# _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | Tensor + + class _IUnknown(_CData): # From comtypes.IUnknown def QueryInterface(self, interface: type, iid: _CData | None = ...) -> _HRESULT: ... def AddRef(self) -> c_ulong: ... @@ -41,9 +33,6 @@ class _DXGIOutput(TypedDict): rotation: int is_attached_to_desktop: bool -_ProcessFuncRegionArg = TypeVar("_ProcessFuncRegionArg", tuple[int, int, int, int], None) -_ProcessFuncReturn = TypeVar("_ProcessFuncReturn", _Frame, None) - class LUID(Structure): LowPart: DWORD HighPart: LONG @@ -172,7 +161,7 @@ def initialize_dxgi_output_duplication( def get_dxgi_output_duplication_frame( dxgi_output_duplication: IDXGIOutputDuplication, d3d_device: ID3D11Device, - process_func: Callable[[PFLOAT, int, int, int, _ProcessFuncRegionArg, int], _ProcessFuncReturn] | None = ..., + process_func: _ProcessFunc[_ProcessFuncRegionArg, _ProcessFuncReturn] | None = ..., width: int = ..., height: int = ..., region: _ProcessFuncRegionArg = ..., From 628a00e5ddd80ba9685ce60dcea0e5ab27e3043c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 12 Sep 2022 05:10:02 +0000 Subject: [PATCH 24/30] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stubs/D3DShot/d3dshot/dll/dxgi.pyi | 1 - 1 file changed, 1 deletion(-) diff --git a/stubs/D3DShot/d3dshot/dll/dxgi.pyi b/stubs/D3DShot/d3dshot/dll/dxgi.pyi index bf3c991578e6..ac065fb4a47f 100644 --- a/stubs/D3DShot/d3dshot/dll/dxgi.pyi +++ b/stubs/D3DShot/d3dshot/dll/dxgi.pyi @@ -7,7 +7,6 @@ from typing_extensions import TypeAlias, TypedDict from d3dshot.dll import _ProcessFunc, _ProcessFuncRegionArg, _ProcessFuncReturn from d3dshot.dll.d3d import ID3D11Device - class _IUnknown(_CData): # From comtypes.IUnknown def QueryInterface(self, interface: type, iid: _CData | None = ...) -> _HRESULT: ... def AddRef(self) -> c_ulong: ... From e444cc13d1a7170eaeea66d433d0bab824c8e452 Mon Sep 17 00:00:00 2001 From: Avasam Date: Mon, 12 Sep 2022 01:14:10 -0400 Subject: [PATCH 25/30] Liskov substitution principle --- stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi | 2 +- .../D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi index 9397a6316c16..d32bfbcf2ceb 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi @@ -21,4 +21,4 @@ class PILCaptureOutput(CaptureOutput): rotation: int, ) -> Image.Image: ... def to_pil(self, frame: _ImageT) -> _ImageT: ... - def stack(self, frames: _ImageT, stack_dimension: _Unused) -> _ImageT: ... + def stack(self, frames: _ImageT, stack_dimension: _Unused) -> _ImageT: ... # type: ignore[override] diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi index 4498bd52f01a..d83219b8814d 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi @@ -24,4 +24,4 @@ class PytorchCaptureOutput(CaptureOutput): rotation: int, ) -> _Tensor: ... def to_pil(self, frame: _Tensor) -> Image.Image: ... - def stack(self, frames: Sequence[_Tensor], stack_dimension: Literal["first", "last"]) -> _Tensor: ... + def stack(self, frames: Sequence[_Tensor], stack_dimension: Literal["first", "last"]) -> _Tensor: ... # type: ignore[override] From 24dea6941aa9642d707f9d7df9b8bdc392c52fb9 Mon Sep 17 00:00:00 2001 From: Avasam Date: Mon, 12 Sep 2022 11:43:26 -0400 Subject: [PATCH 26/30] PR comments and __ --- stubs/D3DShot/d3dshot/capture_output.pyi | 4 +- .../capture_outputs/pil_capture_output.pyi | 3 +- .../pytorch_capture_output.pyi | 2 +- stubs/D3DShot/d3dshot/dll/__init__.pyi | 18 +++++++ stubs/D3DShot/d3dshot/dll/d3d.pyi | 48 +++++++------------ stubs/D3DShot/d3dshot/dll/dxgi.pyi | 38 +++++---------- 6 files changed, 51 insertions(+), 62 deletions(-) diff --git a/stubs/D3DShot/d3dshot/capture_output.pyi b/stubs/D3DShot/d3dshot/capture_output.pyi index ea0bc4b40ec0..429c4758d62e 100644 --- a/stubs/D3DShot/d3dshot/capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_output.pyi @@ -7,14 +7,12 @@ from typing_extensions import Literal, TypeAlias from PIL import Image _Frame: TypeAlias = Image.Image | Incomplete -_Frames: TypeAlias = Image.Image | Sequence[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 -# _Frames: TypeAlias = Image.Image | Sequence[npt.NDArray[np.int32]] | Sequence[npt.NDArray[np.float32]] | Sequence[_Tensor] class CaptureOutputs(enum.Enum): PIL: int @@ -41,4 +39,4 @@ class CaptureOutput: rotation: int, ) -> _Frame: ... def to_pil(self, frame: _Frame) -> Image.Image: ... - def stack(self, frames: _Frames, stack_dimension: Literal["first", "last"]) -> _Frame: ... + def stack(self, frames: Sequence[_Frame], stack_dimension: Literal["first", "last"]) -> _Frame: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi index d32bfbcf2ceb..0a593d73357d 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi @@ -1,3 +1,4 @@ +from collections.abc import Sequence from ctypes import _CVoidConstPLike from typing import TypeVar from typing_extensions import TypeAlias @@ -21,4 +22,4 @@ class PILCaptureOutput(CaptureOutput): rotation: int, ) -> Image.Image: ... def to_pil(self, frame: _ImageT) -> _ImageT: ... - def stack(self, frames: _ImageT, stack_dimension: _Unused) -> _ImageT: ... # type: ignore[override] + def stack(self, frames: Sequence[_ImageT], stack_dimension: _Unused) -> Sequence[_ImageT]: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi index d83219b8814d..4498bd52f01a 100644 --- a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi @@ -24,4 +24,4 @@ class PytorchCaptureOutput(CaptureOutput): rotation: int, ) -> _Tensor: ... def to_pil(self, frame: _Tensor) -> Image.Image: ... - def stack(self, frames: Sequence[_Tensor], stack_dimension: Literal["first", "last"]) -> _Tensor: ... # type: ignore[override] + def stack(self, frames: Sequence[_Tensor], stack_dimension: Literal["first", "last"]) -> _Tensor: ... diff --git a/stubs/D3DShot/d3dshot/dll/__init__.pyi b/stubs/D3DShot/d3dshot/dll/__init__.pyi index 7a9d279173de..56e0e35b58ae 100644 --- a/stubs/D3DShot/d3dshot/dll/__init__.pyi +++ b/stubs/D3DShot/d3dshot/dll/__init__.pyi @@ -1,4 +1,7 @@ +import sys +from _typeshed import Incomplete from collections.abc import Callable +from ctypes import _CData, c_ulong from ctypes.wintypes import PFLOAT from typing import TypeVar from typing_extensions import TypeAlias @@ -7,4 +10,19 @@ from d3dshot.capture_output import _Frame _ProcessFuncRegionArg = TypeVar("_ProcessFuncRegionArg", tuple[int, int, int, int], None) _ProcessFuncReturn = TypeVar("_ProcessFuncReturn", _Frame, None) +# The _ProcessFunc alias is used in multiple submodules _ProcessFunc: TypeAlias = Callable[[PFLOAT, int, int, int, int, _ProcessFuncRegionArg, int], _ProcessFuncReturn] # noqa: Y047 + +if sys.platform == "win32": + from ctypes import HRESULT + + _HRESULT: TypeAlias = HRESULT +else: + _HRESULT: TypeAlias = Incomplete + +# TODO: Use comtypes.IUnknown once we can import non-types dependencies +# See: #5768 +class _IUnknown(_CData): + def QueryInterface(self, interface: type, iid: _CData | None = ...) -> _HRESULT: ... + def AddRef(self) -> c_ulong: ... + def Release(self) -> c_ulong: ... diff --git a/stubs/D3DShot/d3dshot/dll/d3d.pyi b/stubs/D3DShot/d3dshot/dll/d3d.pyi index 211114b36eda..e412c2dbbeca 100644 --- a/stubs/D3DShot/d3dshot/dll/d3d.pyi +++ b/stubs/D3DShot/d3dshot/dll/d3d.pyi @@ -1,26 +1,9 @@ -import sys -from _typeshed import Incomplete -from ctypes import Structure, _CData, _Pointer, c_int32, c_uint, c_ulong, c_void_p +from ctypes import Structure, _Pointer, c_int32, c_uint, c_void_p from ctypes.wintypes import FLOAT, UINT -from typing_extensions import TypeAlias +from d3dshot.dll import _HRESULT, _IUnknown from d3dshot.dll.dxgi import IDXGIAdapter -if sys.platform == "win32": - from ctypes import HRESULT - - _HRESULT: TypeAlias = HRESULT -else: - _HRESULT: TypeAlias = Incomplete - -# TODO: Complete types once we can import non-types dependencies -# See: https://github.com/python/typeshed/issues/5768 -# from comtypes import IUnknown -class _IUnknown(_CData): # From comtypes.IUnknown - def QueryInterface(self, interface: type, iid: _CData | None = ...) -> _HRESULT: ... - def AddRef(self) -> c_ulong: ... - def Release(self) -> c_ulong: ... - class DXGI_SAMPLE_DESC(Structure): Count: UINT Quality: UINT @@ -57,7 +40,7 @@ class ID3D11Resource(ID3D11DeviceChild): def GetEvictionPriority(self) -> UINT: ... class ID3D11Texture2D(ID3D11Resource): - def GetDesc(self, pDesc: _Pointer[D3D11_TEXTURE2D_DESC]) -> None: ... + def GetDesc(self, __pDesc: _Pointer[D3D11_TEXTURE2D_DESC]) -> None: ... class ID3D11DeviceContext(ID3D11DeviceChild): def VSSetConstantBuffers(self) -> None: ... @@ -101,16 +84,16 @@ class ID3D11DeviceContext(ID3D11DeviceChild): def RSSetScissorRects(self) -> None: ... def CopySubresourceRegion( self, - pDstResource: _Pointer[ID3D11Resource], - DstSubresource: UINT, - DstX: UINT, - DstY: UINT, - DstZ: UINT, - pSrcResource: _Pointer[ID3D11Resource], - SrcSubresource: UINT, - pSrcBox: _Pointer[D3D11_BOX], + __pDstResource: _Pointer[ID3D11Resource], + __DstSubresource: UINT, + __DstX: UINT, + __DstY: UINT, + __DstZ: UINT, + __pSrcResource: _Pointer[ID3D11Resource], + __SrcSubresource: UINT, + __pSrcBox: _Pointer[D3D11_BOX], ) -> None: ... - def CopyResource(self, pDstResource: _Pointer[ID3D11Resource], pSrcResource: _Pointer[ID3D11Resource]) -> None: ... + def CopyResource(self, __pDstResource: _Pointer[ID3D11Resource], __pSrcResource: _Pointer[ID3D11Resource]) -> None: ... def UpdateSubresource(self) -> None: ... def CopyStructureCount(self) -> None: ... def ClearRenderTargetView(self) -> None: ... @@ -183,7 +166,10 @@ class ID3D11Device(_IUnknown): def CreateBuffer(self) -> _HRESULT: ... def CreateTexture1D(self) -> _HRESULT: ... def CreateTexture2D( - self, pDesc: _Pointer[D3D11_TEXTURE2D_DESC], pInitialData: c_void_p, ppTexture2D: _Pointer[_Pointer[ID3D11Texture2D]] + self, + __pDesc: _Pointer[D3D11_TEXTURE2D_DESC], + __pInitialData: c_void_p, + __ppTexture2D: _Pointer[_Pointer[ID3D11Texture2D]], ) -> _HRESULT: ... def CreateTexture3D(self) -> _HRESULT: ... def CreateShaderResourceView(self) -> _HRESULT: ... @@ -219,7 +205,7 @@ class ID3D11Device(_IUnknown): def GetFeatureLevel(self) -> c_int32: ... def GetCreationFlags(self) -> c_uint: ... def GetDeviceRemovedReason(self) -> _HRESULT: ... - def GetImmediateContext(self, ppImmediateContext: _Pointer[_Pointer[ID3D11DeviceContext]]) -> None: ... + def GetImmediateContext(self, __ppImmediateContext: _Pointer[_Pointer[ID3D11DeviceContext]]) -> None: ... def SetExceptionMode(self) -> _HRESULT: ... def GetExceptionMode(self) -> c_uint: ... diff --git a/stubs/D3DShot/d3dshot/dll/dxgi.pyi b/stubs/D3DShot/d3dshot/dll/dxgi.pyi index ac065fb4a47f..d26d46867c5e 100644 --- a/stubs/D3DShot/d3dshot/dll/dxgi.pyi +++ b/stubs/D3DShot/d3dshot/dll/dxgi.pyi @@ -1,24 +1,10 @@ -import sys -from _typeshed import Incomplete -from ctypes import Array, Structure, _CData, _Pointer, c_uint, c_ulong +from ctypes import Array, Structure, _Pointer, c_uint from ctypes.wintypes import BOOL, DWORD, HMONITOR, INT, LARGE_INTEGER, LONG, PFLOAT, POINT, RECT, UINT, ULARGE_INTEGER, WCHAR -from typing_extensions import TypeAlias, TypedDict +from typing_extensions import TypedDict -from d3dshot.dll import _ProcessFunc, _ProcessFuncRegionArg, _ProcessFuncReturn +from d3dshot.dll import _HRESULT, _IUnknown, _ProcessFunc, _ProcessFuncRegionArg, _ProcessFuncReturn from d3dshot.dll.d3d import ID3D11Device -class _IUnknown(_CData): # From comtypes.IUnknown - def QueryInterface(self, interface: type, iid: _CData | None = ...) -> _HRESULT: ... - def AddRef(self) -> c_ulong: ... - def Release(self) -> c_ulong: ... - -if sys.platform == "win32": - from ctypes import HRESULT - - _HRESULT: TypeAlias = HRESULT -else: - _HRESULT: TypeAlias = Incomplete - class _DXGIOutputPosition(TypedDict): left: LONG top: LONG @@ -90,16 +76,16 @@ class IDXGIResource(IDXGIDeviceSubObject): class IDXGISurface(IDXGIDeviceSubObject): def GetDesc(self) -> _HRESULT: ... - def Map(self, pLockedRect: _Pointer[DXGI_MAPPED_RECT], MapFlags: UINT) -> _HRESULT: ... + def Map(self, __pLockedRect: _Pointer[DXGI_MAPPED_RECT], __MapFlags: UINT) -> _HRESULT: ... def Unmap(self) -> _HRESULT: ... class IDXGIOutputDuplication(IDXGIObject): def GetDesc(self) -> None: ... def AcquireNextFrame( self, - TimeoutInMilliseconds: UINT, - pFrameInfo: _Pointer[DXGI_OUTDUPL_FRAME_INFO], - ppDesktopResource: _Pointer[_Pointer[IDXGIResource]], + __TimeoutInMilliseconds: UINT, + __pFrameInfo: _Pointer[DXGI_OUTDUPL_FRAME_INFO], + __ppDesktopResource: _Pointer[_Pointer[IDXGIResource]], ) -> _HRESULT: ... def GetFrameDirtyRects(self) -> _HRESULT: ... def GetFrameMoveRects(self) -> _HRESULT: ... @@ -109,7 +95,7 @@ class IDXGIOutputDuplication(IDXGIObject): def ReleaseFrame(self) -> _HRESULT: ... class IDXGIOutput(IDXGIObject): - def GetDesc(self, pDesc: _Pointer[DXGI_OUTPUT_DESC]) -> _HRESULT: ... + def GetDesc(self, __pDesc: _Pointer[DXGI_OUTPUT_DESC]) -> _HRESULT: ... def GetDisplayModeList(self) -> _HRESULT: ... def FindClosestMatchingMode(self) -> _HRESULT: ... def WaitForVBlank(self) -> _HRESULT: ... @@ -127,16 +113,16 @@ class IDXGIOutput1(IDXGIOutput): def FindClosestMatchingMode1(self) -> _HRESULT: ... def GetDisplaySurfaceData1(self) -> _HRESULT: ... def DuplicateOutput( - self, pDevice: _Pointer[ID3D11Device], ppOutputDuplication: _Pointer[_Pointer[IDXGIOutputDuplication]] + self, __pDevice: _Pointer[ID3D11Device], __ppOutputDuplication: _Pointer[_Pointer[IDXGIOutputDuplication]] ) -> _HRESULT: ... class IDXGIAdapter(IDXGIObject): - def EnumOutputs(self, Output: UINT, ppOutput: _Pointer[_Pointer[IDXGIOutput]]) -> _HRESULT: ... + def EnumOutputs(self, __Output: UINT, __ppOutput: _Pointer[_Pointer[IDXGIOutput]]) -> _HRESULT: ... def GetDesc(self) -> _HRESULT: ... def CheckInterfaceSupport(self) -> _HRESULT: ... class IDXGIAdapter1(IDXGIAdapter): - def GetDesc1(self, pDesc: _Pointer[DXGI_ADAPTER_DESC1]) -> _HRESULT: ... + def GetDesc1(self, __pDesc: _Pointer[DXGI_ADAPTER_DESC1]) -> _HRESULT: ... class IDXGIFactory(IDXGIObject): def EnumAdapters(self) -> _HRESULT: ... @@ -146,7 +132,7 @@ class IDXGIFactory(IDXGIObject): def CreateSoftwareAdapter(self) -> _HRESULT: ... class IDXGIFactory1(IDXGIFactory): - def EnumAdapters1(self, Adapter: c_uint, ppAdapter: _Pointer[_Pointer[IDXGIAdapter1]]) -> _HRESULT: ... + def EnumAdapters1(self, __Adapter: c_uint, __ppAdapter: _Pointer[_Pointer[IDXGIAdapter1]]) -> _HRESULT: ... def IsCurrent(self) -> BOOL: ... def initialize_dxgi_factory() -> _Pointer[IDXGIFactory1]: ... From dbd298b27fa802075e4dc7674f269753b4344047 Mon Sep 17 00:00:00 2001 From: Avasam Date: Mon, 12 Sep 2022 11:50:55 -0400 Subject: [PATCH 27/30] Added comment for display init --- stubs/D3DShot/d3dshot/display.pyi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stubs/D3DShot/d3dshot/display.pyi b/stubs/D3DShot/d3dshot/display.pyi index a4b4d8b66d25..59600e2a49cf 100644 --- a/stubs/D3DShot/d3dshot/display.pyi +++ b/stubs/D3DShot/d3dshot/display.pyi @@ -11,6 +11,9 @@ class _PositionDict(TypedDict): right: int bottom: int +# Note that Display.d3d_device and Display.d3d_device_context can never be None. +# Despite initially being set to None in __init__, +# they're always immediatly set in _initialize_dxgi_output_duplication() class Display: name: str adapter_name: str From 1488687132fbe04a4d598f7e74c5a4ac61ba8a2d Mon Sep 17 00:00:00 2001 From: Avasam Date: Mon, 12 Sep 2022 13:24:09 -0400 Subject: [PATCH 28/30] Comments and Iterable --- stubs/D3DShot/d3dshot/capture_output.pyi | 2 ++ stubs/D3DShot/d3dshot/d3dshot.pyi | 5 +++-- stubs/D3DShot/d3dshot/display.pyi | 6 +++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/stubs/D3DShot/d3dshot/capture_output.pyi b/stubs/D3DShot/d3dshot/capture_output.pyi index 429c4758d62e..aa68b092eb20 100644 --- a/stubs/D3DShot/d3dshot/capture_output.pyi +++ b/stubs/D3DShot/d3dshot/capture_output.pyi @@ -25,7 +25,9 @@ class CaptureOutputs(enum.Enum): class CaptureOutputError(BaseException): ... +# All CaptureOutput methods just reference the backend. Making this both a base class and a wrapper. class CaptureOutput: + # `backend` is a subclass of CaptureOutput based on the CaptureOutputs enum passed to __init__ backend: CaptureOutput def __init__(self, backend: CaptureOutputs = ...) -> None: ... def process( diff --git a/stubs/D3DShot/d3dshot/d3dshot.pyi b/stubs/D3DShot/d3dshot/d3dshot.pyi index 4b7ae3f34e8e..5424517ee80c 100644 --- a/stubs/D3DShot/d3dshot/d3dshot.pyi +++ b/stubs/D3DShot/d3dshot/d3dshot.pyi @@ -1,4 +1,5 @@ from collections import deque +from collections.abc import Iterable from d3dshot.capture_output import CaptureOutput as CaptureOutput, CaptureOutputs as CaptureOutputs, _Frame from d3dshot.display import Display as Display @@ -27,8 +28,8 @@ class D3DShot(metaclass=Singleton): def is_capturing(self) -> bool: ... def get_latest_frame(self) -> _Frame | None: ... def get_frame(self, frame_index: int) -> _Frame | None: ... - def get_frames(self, frame_indices: list[int]) -> list[_Frame]: ... - def get_frame_stack(self, frame_indices: list[int], stack_dimension: str | None = ...) -> _Frame: ... + def get_frames(self, frame_indices: Iterable[int]) -> list[_Frame]: ... + def get_frame_stack(self, frame_indices: Iterable[int], stack_dimension: str | None = ...) -> _Frame: ... def screenshot(self, region: tuple[int, int, int, int] | None = ...) -> _Frame | None: ... def screenshot_to_disk( self, directory: str | None = ..., file_name: str | None = ..., region: tuple[int, int, int, int] | None = ... diff --git a/stubs/D3DShot/d3dshot/display.pyi b/stubs/D3DShot/d3dshot/display.pyi index 59600e2a49cf..367a0c635848 100644 --- a/stubs/D3DShot/d3dshot/display.pyi +++ b/stubs/D3DShot/d3dshot/display.pyi @@ -11,9 +11,6 @@ class _PositionDict(TypedDict): right: int bottom: int -# Note that Display.d3d_device and Display.d3d_device_context can never be None. -# Despite initially being set to None in __init__, -# they're always immediatly set in _initialize_dxgi_output_duplication() class Display: name: str adapter_name: str @@ -25,6 +22,9 @@ class Display: hmonitor: int dxgi_output: IDXGIOutput1 | None dxgi_adapter: _Pointer[IDXGIAdapter] | None + # Note that Display.d3d_device and Display.d3d_device_context can never be None. + # Despite initially being set to None in __init__, + # they're always immediatley set in _initialize_dxgi_output_duplication() d3d_device: ID3D11Device d3d_device_context: ID3D11DeviceContext dxgi_output_duplication: _Pointer[IDXGIOutputDuplication] From 42b5119f20e7f938de987cd6c3f6d2401d5799d0 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 12 Sep 2022 18:26:51 +0100 Subject: [PATCH 29/30] `immediatley` -> `immediately` --- stubs/D3DShot/d3dshot/display.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/D3DShot/d3dshot/display.pyi b/stubs/D3DShot/d3dshot/display.pyi index 367a0c635848..fb30dd2b50c8 100644 --- a/stubs/D3DShot/d3dshot/display.pyi +++ b/stubs/D3DShot/d3dshot/display.pyi @@ -24,7 +24,7 @@ class Display: dxgi_adapter: _Pointer[IDXGIAdapter] | None # Note that Display.d3d_device and Display.d3d_device_context can never be None. # Despite initially being set to None in __init__, - # they're always immediatley set in _initialize_dxgi_output_duplication() + # they're always immediately set in _initialize_dxgi_output_duplication() d3d_device: ID3D11Device d3d_device_context: ID3D11DeviceContext dxgi_output_duplication: _Pointer[IDXGIOutputDuplication] From c99d4c8b603c1a73a3044afd1fc470c43e290314 Mon Sep 17 00:00:00 2001 From: Avasam Date: Mon, 12 Sep 2022 13:28:16 -0400 Subject: [PATCH 30/30] oops typo --- stubs/D3DShot/d3dshot/display.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/D3DShot/d3dshot/display.pyi b/stubs/D3DShot/d3dshot/display.pyi index 367a0c635848..fb30dd2b50c8 100644 --- a/stubs/D3DShot/d3dshot/display.pyi +++ b/stubs/D3DShot/d3dshot/display.pyi @@ -24,7 +24,7 @@ class Display: dxgi_adapter: _Pointer[IDXGIAdapter] | None # Note that Display.d3d_device and Display.d3d_device_context can never be None. # Despite initially being set to None in __init__, - # they're always immediatley set in _initialize_dxgi_output_duplication() + # they're always immediately set in _initialize_dxgi_output_duplication() d3d_device: ID3D11Device d3d_device_context: ID3D11DeviceContext dxgi_output_duplication: _Pointer[IDXGIOutputDuplication]