diff --git a/stubs/Pillow/@tests/stubtest_allowlist.txt b/stubs/Pillow/@tests/stubtest_allowlist.txt index f64ebfffa..8ac755738 100644 --- a/stubs/Pillow/@tests/stubtest_allowlist.txt +++ b/stubs/Pillow/@tests/stubtest_allowlist.txt @@ -24,3 +24,6 @@ PIL.ImImagePlugin.i PIL.XVThumbImagePlugin.b PIL.XVThumbImagePlugin.g PIL.XVThumbImagePlugin.r + +# Forwarded arguments +PIL\.TiffImagePlugin\.IFDRational\.__[a-z]+__ diff --git a/stubs/Pillow/PIL/TiffImagePlugin.pyi b/stubs/Pillow/PIL/TiffImagePlugin.pyi index d39a2769d..a092e11b6 100644 --- a/stubs/Pillow/PIL/TiffImagePlugin.pyi +++ b/stubs/Pillow/PIL/TiffImagePlugin.pyi @@ -1,13 +1,17 @@ +import sys from _typeshed import Incomplete -from collections.abc import MutableMapping +from collections.abc import Callable, MutableMapping +from fractions import Fraction, _ComparableNum from numbers import Rational from types import TracebackType -from typing import Any, ClassVar -from typing_extensions import Final, Literal +from typing import ClassVar, overload +from typing_extensions import Final, Literal, SupportsIndex, TypeAlias from ._imaging import _PixelAccessor from .ImageFile import ImageFile +_OpenInfo: TypeAlias = tuple[Literal[b"II", b"MM"], int, tuple[int, ...], int, tuple[int, ...], tuple[int, ...]] + # These are meant to be overridable READ_LIBTIFF: bool WRITE_LIBTIFF: bool @@ -56,11 +60,11 @@ XMP: Final = 700 JPEGQUALITY: Final = 65537 IMAGEJ_META_DATA_BYTE_COUNTS: Final = 50838 IMAGEJ_META_DATA: Final = 50839 -COMPRESSION_INFO: Any -COMPRESSION_INFO_REV: Any -OPEN_INFO: Any +COMPRESSION_INFO: Final[dict[int, str]] +COMPRESSION_INFO_REV: Final[dict[str, int]] +OPEN_INFO: Final[dict[_OpenInfo, tuple[str, str]]] MAX_SAMPLESPERPIXEL: Final = 6 -PREFIXES: Any +PREFIXES: Final[list[bytes]] class IFDRational(Rational): def __init__(self, value, denominator: int = 1) -> None: ... @@ -71,34 +75,100 @@ class IFDRational(Rational): def limit_rational(self, max_denominator): ... def __hash__(self) -> int: ... def __eq__(self, other): ... - __add__: Any - __radd__: Any - __sub__: Any - __rsub__: Any - __mul__: Any - __rmul__: Any - __truediv__: Any - __rtruediv__: Any - __floordiv__: Any - __rfloordiv__: Any - __mod__: Any - __rmod__: Any - __pow__: Any - __rpow__: Any - __pos__: Any - __neg__: Any - __abs__: Any - __trunc__: Any - __lt__: Any - __gt__: Any - __le__: Any - __ge__: Any - __bool__: Any - __ceil__: Any - __floor__: Any - __round__: Any + # The following methods are aliased from fractions.Fraction: + @overload + def __add__(a, b: int | Fraction) -> Fraction: ... + @overload + def __add__(a, b: float) -> float: ... + @overload + def __add__(a, b: complex) -> complex: ... + @overload + def __radd__(b, a: int | Fraction) -> Fraction: ... + @overload + def __radd__(b, a: float) -> float: ... + @overload + def __radd__(b, a: complex) -> complex: ... + @overload + def __sub__(a, b: int | Fraction) -> Fraction: ... + @overload + def __sub__(a, b: float) -> float: ... + @overload + def __sub__(a, b: complex) -> complex: ... + @overload + def __rsub__(b, a: int | Fraction) -> Fraction: ... + @overload + def __rsub__(b, a: float) -> float: ... + @overload + def __rsub__(b, a: complex) -> complex: ... + @overload + def __mul__(a, b: int | Fraction) -> Fraction: ... + @overload + def __mul__(a, b: float) -> float: ... + @overload + def __mul__(a, b: complex) -> complex: ... + @overload + def __rmul__(b, a: int | Fraction) -> Fraction: ... + @overload + def __rmul__(b, a: float) -> float: ... + @overload + def __rmul__(b, a: complex) -> complex: ... + @overload + def __truediv__(a, b: int | Fraction) -> Fraction: ... + @overload + def __truediv__(a, b: float) -> float: ... + @overload + def __truediv__(a, b: complex) -> complex: ... + @overload + def __rtruediv__(b, a: int | Fraction) -> Fraction: ... + @overload + def __rtruediv__(b, a: float) -> float: ... + @overload + def __rtruediv__(b, a: complex) -> complex: ... + @overload + def __floordiv__(a, b: int | Fraction) -> int: ... + @overload + def __floordiv__(a, b: float) -> float: ... + @overload + def __rfloordiv__(b, a: int | Fraction) -> int: ... + @overload + def __rfloordiv__(b, a: float) -> float: ... + @overload + def __mod__(a, b: int | Fraction) -> Fraction: ... + @overload + def __mod__(a, b: float) -> float: ... + @overload + def __rmod__(b, a: int | Fraction) -> Fraction: ... + @overload + def __rmod__(b, a: float) -> float: ... + @overload + def __pow__(a, b: int) -> Fraction: ... + @overload + def __pow__(a, b: float | Fraction) -> float: ... + @overload + def __pow__(a, b: complex) -> complex: ... + @overload + def __rpow__(b, a: float | Fraction) -> float: ... + @overload + def __rpow__(b, a: complex) -> complex: ... + def __pos__(a) -> Fraction: ... + def __neg__(a) -> Fraction: ... + def __abs__(a) -> Fraction: ... + def __trunc__(a) -> int: ... + def __lt__(a, b: _ComparableNum) -> bool: ... + def __gt__(a, b: _ComparableNum) -> bool: ... + def __le__(a, b: _ComparableNum) -> bool: ... + def __ge__(a, b: _ComparableNum) -> bool: ... + def __bool__(a) -> bool: ... + def __ceil__(a) -> int: ... + def __floor__(a) -> int: ... + @overload + def __round__(self, ndigits: None = None) -> int: ... + @overload + def __round__(self, ndigits: int) -> Fraction: ... + if sys.version_info >= (3, 11): + def __int__(a, _index: Callable[[SupportsIndex], int] = ...) -> int: ... -class ImageFileDirectory_v2(MutableMapping[int, Any]): +class ImageFileDirectory_v2(MutableMapping[int, Incomplete]): group: int | None tagtype: dict[int, int] def __init__( @@ -169,12 +239,12 @@ ImageFileDirectory = ImageFileDirectory_v1 class TiffImageFile(ImageFile): format: ClassVar[Literal["TIFF", "MIC"]] format_description: ClassVar[str] - tag_v2: Any - tag: Any + tag_v2: Incomplete + tag: Incomplete def __init__(self, fp: Incomplete | None = None, filename: Incomplete | None = None) -> None: ... @property def n_frames(self): ... - im: Any + im: Incomplete def seek(self, frame) -> None: ... def tell(self): ... def getxmp(self): ... @@ -182,19 +252,19 @@ class TiffImageFile(ImageFile): def load(self) -> _PixelAccessor: ... def load_end(self) -> None: ... -SAVE_INFO: Any +SAVE_INFO: Incomplete class AppendingTiffWriter: - fieldSizes: Any - Tags: Any - f: Any + fieldSizes: Incomplete + Tags: Incomplete + f: Incomplete close_fp: bool - name: Any - beginning: Any + name: Incomplete + beginning: Incomplete def __init__(self, fn, new: bool = False) -> None: ... - whereToWriteNewIFDOffset: Any + whereToWriteNewIFDOffset: Incomplete offsetOfNewPage: int - IIMM: Any + IIMM: Incomplete isFirst: bool def setup(self) -> None: ... def finalize(self) -> None: ... @@ -206,10 +276,10 @@ class AppendingTiffWriter: def tell(self): ... def seek(self, offset, whence=0): ... def goToEnd(self) -> None: ... - endian: Any - longFmt: Any - shortFmt: Any - tagFormat: Any + endian: Incomplete + longFmt: Incomplete + shortFmt: Incomplete + tagFormat: Incomplete def setEndian(self, endian) -> None: ... def skipIFDs(self) -> None: ... def write(self, data): ...