Updated type hints

This commit is contained in:
Andrew Murray 2024-06-08 18:01:26 +10:00
parent d2603b779a
commit 45cdc53bbb
7 changed files with 21 additions and 15 deletions

View File

@ -124,8 +124,8 @@ def test_fastpath_translate() -> None:
def test_center() -> None: def test_center() -> None:
im = hopper() im = hopper()
rotate(im, im.mode, 45, center=(0, 0)) rotate(im, im.mode, 45, center=(0, 0))
rotate(im, im.mode, 45, translate=(im.size[0] / 2, 0)) rotate(im, im.mode, 45, translate=(im.size[0] // 2, 0))
rotate(im, im.mode, 45, center=(0, 0), translate=(im.size[0] / 2, 0)) rotate(im, im.mode, 45, center=(0, 0), translate=(im.size[0] // 2, 0))
def test_rotate_no_fill() -> None: def test_rotate_no_fill() -> None:

View File

@ -144,10 +144,12 @@ pixel, the Python Imaging Library provides different resampling *filters*.
.. py:currentmodule:: PIL.Image .. py:currentmodule:: PIL.Image
.. data:: Resampling.NEAREST .. data:: Resampling.NEAREST
:noindex:
Pick one nearest pixel from the input image. Ignore all other input pixels. Pick one nearest pixel from the input image. Ignore all other input pixels.
.. data:: Resampling.BOX .. data:: Resampling.BOX
:noindex:
Each pixel of source image contributes to one pixel of the Each pixel of source image contributes to one pixel of the
destination image with identical weights. destination image with identical weights.
@ -158,6 +160,7 @@ pixel, the Python Imaging Library provides different resampling *filters*.
.. versionadded:: 3.4.0 .. versionadded:: 3.4.0
.. data:: Resampling.BILINEAR .. data:: Resampling.BILINEAR
:noindex:
For resize calculate the output pixel value using linear interpolation For resize calculate the output pixel value using linear interpolation
on all pixels that may contribute to the output value. on all pixels that may contribute to the output value.
@ -165,6 +168,7 @@ pixel, the Python Imaging Library provides different resampling *filters*.
in the input image is used. in the input image is used.
.. data:: Resampling.HAMMING .. data:: Resampling.HAMMING
:noindex:
Produces a sharper image than :data:`Resampling.BILINEAR`, doesn't have Produces a sharper image than :data:`Resampling.BILINEAR`, doesn't have
dislocations on local level like with :data:`Resampling.BOX`. dislocations on local level like with :data:`Resampling.BOX`.
@ -174,6 +178,7 @@ pixel, the Python Imaging Library provides different resampling *filters*.
.. versionadded:: 3.4.0 .. versionadded:: 3.4.0
.. data:: Resampling.BICUBIC .. data:: Resampling.BICUBIC
:noindex:
For resize calculate the output pixel value using cubic interpolation For resize calculate the output pixel value using cubic interpolation
on all pixels that may contribute to the output value. on all pixels that may contribute to the output value.
@ -181,6 +186,7 @@ pixel, the Python Imaging Library provides different resampling *filters*.
in the input image is used. in the input image is used.
.. data:: Resampling.LANCZOS .. data:: Resampling.LANCZOS
:noindex:
Calculate the output pixel value using a high-quality Lanczos filter (a Calculate the output pixel value using a high-quality Lanczos filter (a
truncated sinc) on all pixels that may contribute to the output value. truncated sinc) on all pixels that may contribute to the output value.

View File

@ -424,7 +424,6 @@ See :ref:`concept-filters` for details.
.. autoclass:: Resampling .. autoclass:: Resampling
:members: :members:
:undoc-members: :undoc-members:
:noindex:
Dither modes Dither modes
^^^^^^^^^^^^ ^^^^^^^^^^^^

View File

@ -2303,8 +2303,8 @@ class Image:
def rotate( def rotate(
self, self,
angle: float, angle: float,
resample: int = Resampling.NEAREST, resample: Resampling = Resampling.NEAREST,
expand: bool = False, expand: int | bool = False,
center: tuple[int, int] | None = None, center: tuple[int, int] | None = None,
translate: tuple[int, int] | None = None, translate: tuple[int, int] | None = None,
fillcolor: float | tuple[float, ...] | str | None = None, fillcolor: float | tuple[float, ...] | str | None = None,
@ -2617,8 +2617,8 @@ class Image:
def thumbnail( def thumbnail(
self, self,
size: tuple[int, int], size: tuple[float, float],
resample: int = Resampling.BICUBIC, resample: Resampling = Resampling.BICUBIC,
reducing_gap: float = 2.0, reducing_gap: float = 2.0,
) -> None: ) -> None:
""" """
@ -2953,7 +2953,7 @@ class ImageTransformHandler:
self, self,
size: tuple[int, int], size: tuple[int, int],
image: Image, image: Image,
**options: str | int | tuple[int, ...] | list[int], **options: Any,
) -> Image: ) -> Image:
pass pass

View File

@ -95,7 +95,9 @@ class ImageDraw:
if TYPE_CHECKING: if TYPE_CHECKING:
from . import ImageFont from . import ImageFont
def getfont(self) -> ImageFont.FreeTypeFont | ImageFont.ImageFont: def getfont(
self,
) -> ImageFont.ImageFont | ImageFont.FreeTypeFont | ImageFont.TransposedFont:
""" """
Get the current default font. Get the current default font.
@ -122,14 +124,13 @@ class ImageDraw:
def _getfont( def _getfont(
self, font_size: float | None self, font_size: float | None
) -> ImageFont.FreeTypeFont | ImageFont.ImageFont: ) -> ImageFont.ImageFont | ImageFont.FreeTypeFont | ImageFont.TransposedFont:
if font_size is not None: if font_size is not None:
from . import ImageFont from . import ImageFont
font = ImageFont.load_default(font_size) return ImageFont.load_default(font_size)
else: else:
font = self.getfont() return self.getfont()
return font
def _getink(self, ink, fill=None) -> tuple[int | None, int | None]: def _getink(self, ink, fill=None) -> tuple[int | None, int | None]:
if ink is None and fill is None: if ink is None and fill is None:

View File

@ -361,7 +361,7 @@ class FreeTypeFont:
text: str, text: str,
mode: str = "", mode: str = "",
direction: str | None = None, direction: str | None = None,
features: str | None = None, features: list[str] | None = None,
language: str | None = None, language: str | None = None,
stroke_width: float = 0, stroke_width: float = 0,
anchor: str | None = None, anchor: str | None = None,

View File

@ -6,7 +6,7 @@ class _Axis(TypedDict):
minimum: int | None minimum: int | None
default: int | None default: int | None
maximum: int | None maximum: int | None
name: str | None name: bytes | None
class Font: class Font:
@property @property