From d3ba8a38587ceb8c54dfa9fed32c1028aa80595e Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 13 Jun 2021 14:15:51 +0200 Subject: [PATCH] Pillow: fix errors found by stubtest (#5629) * Update Pillow stubtest allowlist * Update cryptography allowlist --- stubs/Pillow/@tests/stubtest_allowlist.txt | 19 ++++----------- stubs/Pillow/PIL/Image.pyi | 12 ++++++---- stubs/Pillow/PIL/ImageDraw.pyi | 24 +++++++++---------- stubs/Pillow/PIL/ImageFont.pyi | 23 +++++++++++------- stubs/Pillow/PIL/PyAccess.pyi | 4 ++-- stubs/Pillow/PIL/TiffImagePlugin.pyi | 2 -- .../@tests/stubtest_allowlist.txt | 7 +++--- 7 files changed, 42 insertions(+), 49 deletions(-) diff --git a/stubs/Pillow/@tests/stubtest_allowlist.txt b/stubs/Pillow/@tests/stubtest_allowlist.txt index 18a3de965..b0cdde03a 100644 --- a/stubs/Pillow/@tests/stubtest_allowlist.txt +++ b/stubs/Pillow/@tests/stubtest_allowlist.txt @@ -1,15 +1,4 @@ -PIL.Image.Image.category -PIL.Image.Image.resize -PIL.Image.fromarray -PIL.Image.open -PIL.ImageDraw.ImageDraw.multiline_text -PIL.ImageDraw.ImageDraw.multiline_textbbox -PIL.ImageDraw.ImageDraw.textbbox -PIL.ImageFile.ImageFile.__getattr__ -PIL.ImageFile.ImageFile.__init__ -PIL.ImageFont.FreeTypeFont.getlength -PIL.ImageFont.FreeTypeFont.getmask -PIL.ImageFont.FreeTypeFont.getmask2 -PIL.ImageFont.FreeTypeFont.getsize -PIL.ImageFont.FreeTypeFont.getsize_multiline -PIL.__getattr__ +PIL.FpxImagePlugin +PIL.ImageQt.ImageQt +PIL.MicImagePlugin +PIL.WmfImagePlugin.WmfHandler diff --git a/stubs/Pillow/PIL/Image.pyi b/stubs/Pillow/PIL/Image.pyi index bb9e72816..aff63603e 100644 --- a/stubs/Pillow/PIL/Image.pyi +++ b/stubs/Pillow/PIL/Image.pyi @@ -107,8 +107,6 @@ class Image: readonly: int pyaccess: Any @property - def category(self) -> int: ... # obsolete - @property def width(self) -> int: ... @property def height(self) -> int: ... @@ -171,7 +169,11 @@ class Image: def putpixel(self, xy, value): ... def remap_palette(self, dest_map, source_palette=...): ... def resize( - self, size: tuple[int, int], resample: _Resample = ..., box: tuple[float, float, float, float] | None = ... + self, + size: tuple[int, int], + resample: _Resample = ..., + box: tuple[float, float, float, float] | None = ..., + reducing_gap: float | None = ..., ) -> Image: ... def reduce(self, factor, box=...): ... def rotate( @@ -204,10 +206,10 @@ class ImageTransformHandler: ... def new(mode: _Mode, size: tuple[int, int], color: float | Tuple[float, ...] = ...) -> Image: ... def frombytes(mode: _Mode, size: tuple[int, int], data, decoder_name: str = ..., *args) -> Image: ... def frombuffer(mode: _Mode, size: tuple[int, int], data, decoder_name: str = ..., *args) -> Image: ... -def fromarray(obj, mode: _Mode = ...) -> Image: ... +def fromarray(obj, mode: _Mode | None = ...) -> Image: ... def fromqimage(im) -> Image: ... def fromqpixmap(im) -> Image: ... -def open(fp: str | bytes | Path | SupportsRead[bytes], mode: _Mode = ..., formats=...) -> Image: ... +def open(fp: str | bytes | Path | SupportsRead[bytes], mode: Literal["r"] = ..., formats=...) -> Image: ... def alpha_composite(im1: Image, im2: Image) -> Image: ... def blend(im1: Image, im2: Image, alpha) -> Image: ... def composite(image1: Image, image2: Image, mask) -> Image: ... diff --git a/stubs/Pillow/PIL/ImageDraw.pyi b/stubs/Pillow/PIL/ImageDraw.pyi index 374c509c6..c7d284fb5 100644 --- a/stubs/Pillow/PIL/ImageDraw.pyi +++ b/stubs/Pillow/PIL/ImageDraw.pyi @@ -69,12 +69,12 @@ class ImageDraw: text: str | bytes, fill: _Ink | None = ..., font: _Font | None = ..., - anchor=..., + anchor: Any | None = ..., spacing: float = ..., align: Literal["left", "center", "right"] = ..., - direction: Literal["rtl", "ltr", "ttb"] = ..., - features=..., - language: str = ..., + direction: Literal["rtl", "ltr", "ttb"] | None = ..., + features: Any | None = ..., + language: str | None = ..., stroke_width: float = ..., stroke_fill: _Ink | None = ..., embedded_color: bool = ..., @@ -110,28 +110,28 @@ class ImageDraw: ) -> int: ... def textbbox( self, - xy, + xy: tuple[float, float], text: str | bytes, font: _Font | None = ..., - anchor=..., + anchor: Any | None = ..., spacing: float = ..., align: Literal["left", "center", "right"] = ..., - direction: Literal["rtl", "ltr", "ttb"] = ..., - features=..., + direction: Literal["rtl", "ltr", "ttb"] | None = ..., + features: Any | None = ..., language: str | None = ..., stroke_width: float = ..., embedded_color: bool = ..., ) -> tuple[int, int, int, int]: ... def multiline_textbbox( self, - xy, + xy: tuple[float, float], text: str | bytes, font: _Font | None = ..., - anchor=..., + anchor: Any | None = ..., spacing: float = ..., align: Literal["left", "center", "right"] = ..., - direction: Literal["rtl", "ltr", "ttb"] = ..., - features=..., + direction: Literal["rtl", "ltr", "ttb"] | None = ..., + features: Any | None = ..., language: str | None = ..., stroke_width: float = ..., embedded_color: bool = ..., diff --git a/stubs/Pillow/PIL/ImageFont.pyi b/stubs/Pillow/PIL/ImageFont.pyi index 820f813f3..e63bf2d5a 100644 --- a/stubs/Pillow/PIL/ImageFont.pyi +++ b/stubs/Pillow/PIL/ImageFont.pyi @@ -29,7 +29,12 @@ class FreeTypeFont: def getname(self) -> tuple[str, str]: ... def getmetrics(self): ... def getlength( - self, text, mode=..., direction: Literal["ltr", "rtl", "ttb"] = ..., features=..., language: str | None = ... + self, + text, + mode=..., + direction: Literal["ltr", "rtl", "ttb"] | None = ..., + features: Any | None = ..., + language: str | None = ..., ) -> int: ... def getbbox( self, text, mode: str = ..., direction=..., features=..., language: str | None = ..., stroke_width: int = ..., anchor=... @@ -37,17 +42,17 @@ class FreeTypeFont: def getsize( self, text, - direction: Literal["ltr", "rtl", "ttb"] = ..., - features=..., + direction: Literal["ltr", "rtl", "ttb"] | None = ..., + features: Any | None = ..., language: str | None = ..., stroke_width: int = ..., ) -> tuple[int, int]: ... def getsize_multiline( self, text, - direction: Literal["ltr", "rtl", "ttb"] = ..., + direction: Literal["ltr", "rtl", "ttb"] | None = ..., spacing: float = ..., - features=..., + features: Any | None = ..., language: str | None = ..., stroke_width: float = ..., ): ... @@ -56,8 +61,8 @@ class FreeTypeFont: self, text: str, mode: str = ..., - direction: Literal["ltr", "rtl", "ttb"] = ..., - features=..., + direction: Literal["ltr", "rtl", "ttb"] | None = ..., + features: Any | None = ..., language: str | None = ..., stroke_width: float = ..., anchor=..., @@ -68,8 +73,8 @@ class FreeTypeFont: text, mode: str = ..., fill=..., - direction: Literal["ltr", "rtl", "ttb"] = ..., - features=..., + direction: Literal["ltr", "rtl", "ttb"] | None = ..., + features: Any | None = ..., language: str | None = ..., stroke_width: float = ..., anchor=..., diff --git a/stubs/Pillow/PIL/PyAccess.pyi b/stubs/Pillow/PIL/PyAccess.pyi index 51fe7dc2f..2d87adf90 100644 --- a/stubs/Pillow/PIL/PyAccess.pyi +++ b/stubs/Pillow/PIL/PyAccess.pyi @@ -1,8 +1,8 @@ +from logging import Logger from typing import Any -defs: str ffi: Any -logger: Any +logger: Logger class PyAccess: readonly: Any diff --git a/stubs/Pillow/PIL/TiffImagePlugin.pyi b/stubs/Pillow/PIL/TiffImagePlugin.pyi index 0af01687b..3b9aea231 100644 --- a/stubs/Pillow/PIL/TiffImagePlugin.pyi +++ b/stubs/Pillow/PIL/TiffImagePlugin.pyi @@ -116,8 +116,6 @@ class ImageFileDirectory_v2(MutableMapping[int, Any]): def tobytes(self, offset: int = ...): ... def save(self, fp): ... -name: Any - class ImageFileDirectory_v1(ImageFileDirectory_v2): def __init__(self, *args, **kwargs) -> None: ... tags: Any diff --git a/stubs/cryptography/@tests/stubtest_allowlist.txt b/stubs/cryptography/@tests/stubtest_allowlist.txt index 96ec224aa..9eb68be6c 100644 --- a/stubs/cryptography/@tests/stubtest_allowlist.txt +++ b/stubs/cryptography/@tests/stubtest_allowlist.txt @@ -8,6 +8,9 @@ cryptography.hazmat.backends.interfaces.DHBackend.dh_parameters_supported cryptography.hazmat.backends.interfaces.HMACBackend.cmac_algorithm_supported cryptography.hazmat.bindings.openssl.binding.Binding.init_static_locks cryptography.hazmat.primitives.asymmetric.dh.DHParameterNumbers.__init__ +cryptography.hazmat.primitives.asymmetric.dsa.AsymmetricVerificationContext +cryptography.hazmat.primitives.asymmetric.ec.AsymmetricVerificationContext +cryptography.hazmat.primitives.asymmetric.rsa.AsymmetricVerificationContext cryptography.hazmat.primitives.ciphers.aead.AESCCM.__init__ cryptography.hazmat.primitives.ciphers.modes.GCM.__init__ cryptography.hazmat.primitives.cmac.CMAC.__init__ @@ -18,22 +21,18 @@ cryptography.hazmat.primitives.hmac.HMAC.__init__ cryptography.hazmat.primitives.hmac.HMAC.update cryptography.hazmat.primitives.serialization.pkcs12.serialize_key_and_certificates cryptography.hazmat.primitives.serialization.pkcs7.PKCS7SignatureBuilder.__init__ -cryptography.x509.CertificateBuilder.add_extension cryptography.x509.CertificateBuilder.public_key cryptography.x509.CertificateBuilder.serial_number cryptography.x509.CertificateRevocationListBuilder.__init__ -cryptography.x509.CertificateRevocationListBuilder.add_extension cryptography.x509.CertificateRevocationListBuilder.issuer_name cryptography.x509.CertificateRevocationListBuilder.last_update cryptography.x509.CertificateRevocationListBuilder.next_update cryptography.x509.CertificateSigningRequestBuilder.__init__ -cryptography.x509.CertificateSigningRequestBuilder.add_extension cryptography.x509.Extension.__init__ cryptography.x509.Extensions.__init__ cryptography.x509.NameAttribute.__init__ cryptography.x509.OCSPExtensionOID cryptography.x509.RevokedCertificateBuilder.__init__ -cryptography.x509.RevokedCertificateBuilder.add_extension cryptography.x509.RevokedCertificateBuilder.serial_number cryptography.x509.extensions.AccessDescription.__init__ cryptography.x509.extensions.AuthorityInformationAccess.__init__