Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type stubs for zune-python #233

Closed
kiyoon opened this issue Sep 19, 2024 · 2 comments · Fixed by #235
Closed

Type stubs for zune-python #233

kiyoon opened this issue Sep 19, 2024 · 2 comments · Fixed by #235

Comments

@kiyoon
Copy link
Contributor

kiyoon commented Sep 19, 2024

zune-python currently doesn't have type hint stubs, which makes the type checkers like pyright struggle.

I've made a template version of the stub and this could be polished and added to the repository:

import enum
from typing import Literal, overload

class ImageFormat(enum.Enum):
    FarbFeld = ...
    JPEG = ...
    PNG = ...
    PSD = ...
    Unknown = ...
    BMP = ...
    HDR = ...
    JPEG_XL = ...
    PPM = ...
    Qoi = ...

class ResizeMethod(enum.Enum):
    Bilinear = ...
    Bicubic = ...

class Image:
    @staticmethod
    def open(file: str) -> Image: ...
    def save(self, file: str, *, format: ImageFormat) -> None: ...
    def dimensions(self) -> tuple[int, int]: ...
    def width(self) -> int: ...
    def height(self) -> int: ...
    @overload
    def auto_orient(self, *, in_place: Literal[False]) -> Image: ...
    @overload
    def auto_orient(self, *, in_place: Literal[True]) -> None: ...
    def auto_orient(self, *, in_place: bool) -> Image | None: ...
    @overload
    def resize(
        self,
        new_width: int,
        new_height: int,
        method: ResizeMethod,
        *,
        in_place: Literal[False],
    ) -> Image: ...
    @overload
    def resize(
        self,
        new_width: int,
        new_height: int,
        method: ResizeMethod,
        *,
        in_place: Literal[True],
    ) -> None: ...
    def resize(
        self, new_width: int, new_height: int, method: ResizeMethod, *, in_place: bool
    ) -> Image | None: ...
    @overload
    def crop(
        self, width: int, height: int, x: int, y: int, *, in_place: Literal[False]
    ) -> Image: ...
    @overload
    def crop(
        self, width: int, height: int, x: int, y: int, *, in_place: Literal[True]
    ) -> None: ...
    def crop(
        self, width: int, height: int, x: int, y: int, *, in_place: bool
    ) -> Image | None: ...
@etemesi254
Copy link
Owner

Is this an issue with. how marutin does things or it's an issue with zune -python?

I think maybe marutin should generate type hints or maybe I'm wrong

@kiyoon
Copy link
Contributor Author

kiyoon commented Sep 21, 2024

In my experience with maturin, it doesn't really generate stubs. You have to manually add this.

See PyO3/pyo3#2454

https://www.maturin.rs/project_layout This page also says you need to put a separate .pyi files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants