From 7ded8d10a945a1b772616b0d3038a569486fdada Mon Sep 17 00:00:00 2001 From: Matt Land Date: Mon, 24 Apr 2023 09:41:53 -0600 Subject: [PATCH 1/2] work for #59 to remove changing types of objects when reassigning rename, remove type overrides more implicit types, and non-matching return types mypy caught errors --- .pre-commit-config.yaml | 14 +++++++++++ adafruit_imageload/__init__.py | 7 +++++- adafruit_imageload/bmp/__init__.py | 8 +++---- adafruit_imageload/bmp/indexed.py | 30 +++++++++++++---------- adafruit_imageload/gif.py | 6 +++-- adafruit_imageload/png.py | 32 ++++++++++++++++--------- adafruit_imageload/pnm/__init__.py | 25 +++++++++++-------- adafruit_imageload/pnm/pbm_ascii.py | 4 ++-- adafruit_imageload/pnm/pbm_binary.py | 4 ++-- adafruit_imageload/pnm/pgm/__init__.py | 6 ++--- adafruit_imageload/pnm/pgm/ascii.py | 17 ++++++------- adafruit_imageload/pnm/pgm/binary.py | 19 ++++++++------- adafruit_imageload/pnm/ppm_ascii.py | 21 ++++++++-------- adafruit_imageload/pnm/ppm_binary.py | 26 +++++++++++--------- adafruit_imageload/tilegrid_inflator.py | 10 ++++---- mypy.ini | 8 ++++++- 16 files changed, 145 insertions(+), 92 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0e5fccc..11aa787 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,5 @@ # SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# SPDX-FileCopyrightText: 2023 Matt Land # # SPDX-License-Identifier: Unlicense @@ -40,3 +41,16 @@ repos: files: "^tests/" args: - --disable=missing-docstring,consider-using-f-string,duplicate-code + - repo: local + hooks: + - id: mypy + name: mypy (library code) + entry: "mypy ." + language: python + additional_dependencies: ["mypy==1.2.0"] + types: [python] + exclude: "^(docs/|examples/|tests/|setup.py$)" + # use require_serial so that script + # is only called once per commit + require_serial: true + pass_filenames: false diff --git a/adafruit_imageload/__init__.py b/adafruit_imageload/__init__.py index a8965d1..bd8cd98 100644 --- a/adafruit_imageload/__init__.py +++ b/adafruit_imageload/__init__.py @@ -1,5 +1,5 @@ # SPDX-FileCopyrightText: 2018 Scott Shawcroft for Adafruit Industries -# SPDX-FileCopyrightText: 2022 Matt Land +# SPDX-FileCopyrightText: 2022-2023 Matt Land # # SPDX-License-Identifier: MIT @@ -77,10 +77,15 @@ def load( return pnm.load(file, header, bitmap=bitmap, palette=palette) if header.startswith(b"GIF"): + if not bitmap: + raise RuntimeError("bitmap argument required") + from . import gif return gif.load(file, bitmap=bitmap, palette=palette) if header.startswith(b"\x89PN"): + if not bitmap: + raise RuntimeError("bitmap argument required") from . import png return png.load(file, bitmap=bitmap, palette=palette) diff --git a/adafruit_imageload/bmp/__init__.py b/adafruit_imageload/bmp/__init__.py index ff422e8..736188f 100644 --- a/adafruit_imageload/bmp/__init__.py +++ b/adafruit_imageload/bmp/__init__.py @@ -1,5 +1,5 @@ # SPDX-FileCopyrightText: 2018 Scott Shawcroft for Adafruit Industries -# SPDX-FileCopyrightText: 2022 Matt Land +# SPDX-FileCopyrightText: 2022-2023 Matt Land # # SPDX-License-Identifier: MIT @@ -29,9 +29,9 @@ def load( file: BufferedReader, *, - bitmap: BitmapConstructor = None, - palette: PaletteConstructor = None -) -> Tuple[Bitmap, Optional[Palette]]: + bitmap: Optional[BitmapConstructor] = None, + palette: Optional[PaletteConstructor] = None +) -> Tuple[Optional[Bitmap], Optional[Palette]]: """Loads a bmp image from the open ``file``. Returns tuple of bitmap object and palette object. diff --git a/adafruit_imageload/bmp/indexed.py b/adafruit_imageload/bmp/indexed.py index 1855a34..134b9b3 100755 --- a/adafruit_imageload/bmp/indexed.py +++ b/adafruit_imageload/bmp/indexed.py @@ -1,5 +1,5 @@ # SPDX-FileCopyrightText: 2018 Scott Shawcroft for Adafruit Industries -# SPDX-FileCopyrightText: 2022 Matt Land +# SPDX-FileCopyrightText: 2022-2023 Matt Land # # SPDX-License-Identifier: MIT @@ -43,9 +43,9 @@ def load( color_depth: int, compression: int, *, - bitmap: BitmapConstructor = None, - palette: PaletteConstructor = None, -) -> Tuple[Bitmap, Optional[Palette]]: + bitmap: Optional[BitmapConstructor] = None, + palette: Optional[PaletteConstructor] = None, +) -> Tuple[Optional[Bitmap], Optional[Palette]]: """Loads indexed bitmap data into bitmap and palette objects. :param file file: The open bmp file @@ -54,19 +54,24 @@ def load( :param int data_start: Byte location where the data starts (after headers) :param int colors: Number of distinct colors in the image :param int color_depth: Number of bits used to store a value - :param int compression: 0 - none, 1 - 8bit RLE, 2 - 4bit RLE""" + :param int compression: 0 - none, 1 - 8bit RLE, 2 - 4bit RLE + :param BitmapConstructor bitmap: a function that returns a displayio.Bitmap + :param PaletteConstructor palette: a function that returns a displayio.Palette + """ # pylint: disable=too-many-arguments,too-many-locals,too-many-branches + palette_obj = None if palette: - palette = palette(colors) # type: Palette + palette_obj = palette(colors) file.seek(data_start - colors * 4) for value in range(colors): c_bytes = file.read(4) # Need to swap red & blue bytes (bytes 0 and 2) - palette[value] = bytes( + palette_obj[value] = bytes( b"".join([c_bytes[2:3], c_bytes[1:2], c_bytes[0:1], c_bytes[3:1]]) ) + bitmap_obj = None if bitmap: minimum_color_depth = 1 while colors > 2**minimum_color_depth: @@ -78,7 +83,7 @@ def load( # convert unsigned int to signed int when height is negative height = negative_height_check(height) - bitmap = bitmap(width, abs(height), colors) # type: Bitmap + bitmap_obj = bitmap(width, abs(height), colors) file.seek(data_start) line_size = width // (8 // color_depth) if width % (8 // color_depth) != 0: @@ -97,10 +102,9 @@ def load( range3 = 1 if compression == 0: - if _bitmap_readinto: _bitmap_readinto( - bitmap, + bitmap_obj, file, bits_per_pixel=color_depth, element_size=4, @@ -120,17 +124,17 @@ def load( pixel = ( chunk[i] >> (8 - color_depth * (x % pixels_per_byte + 1)) ) & mask - bitmap[offset + x] = pixel + bitmap_obj[offset + x] = pixel elif compression in (1, 2): decode_rle( - bitmap=bitmap, + bitmap=bitmap_obj, file=file, compression=compression, y_range=(range1, range2, range3), width=width, ) - return bitmap, palette + return bitmap_obj, palette_obj def decode_rle( diff --git a/adafruit_imageload/gif.py b/adafruit_imageload/gif.py index d1ecd8c..3cf3a52 100644 --- a/adafruit_imageload/gif.py +++ b/adafruit_imageload/gif.py @@ -1,5 +1,5 @@ # SPDX-FileCopyrightText: 2019 Radomir Dopieralski for Adafruit Industries -# SPDX-FileCopyrightText: 2022 Matt Land +# SPDX-FileCopyrightText: 2022-2023 Matt Land # # SPDX-License-Identifier: MIT @@ -32,7 +32,7 @@ def load( file: BufferedReader, *, bitmap: BitmapConstructor, - palette: PaletteConstructor = None + palette: Optional[PaletteConstructor] = None ) -> Tuple[Bitmap, Optional[Palette]]: """Loads a GIF image from the open ``file``. @@ -50,6 +50,8 @@ def load( " Tuple[Bitmap, Optional[Palette]]: + """ + Loads a PNG image from the open ``file``. Returns tuple of bitmap object and palette object. @@ -38,7 +44,9 @@ def load( :param object bitmap: Type to store bitmap data. Must have API similar to `displayio.Bitmap`. :param object palette: Type to store the palette. Must have API similar to - `displayio.Palette`. Will be skipped if None""" + `displayio.Palette`. Will be skipped if None + """ + # pylint: disable=too-many-locals,too-many-branches header = file.read(8) if header != b"\x89PNG\r\n\x1a\n": raise ValueError("Not a PNG file") @@ -46,7 +54,9 @@ def load( data = bytearray() pal = None mode = None - depth = None + depth = 0 + width = 0 + height = 0 while True: size, chunk = struct.unpack(">I4s", file.read(8)) if chunk == b"IHDR": @@ -81,16 +91,16 @@ def load( else: file.seek(size, 1) # skip unknown chunks file.seek(4, 1) # skip CRC - data = zlib.decompress(data) + data_bytes = zlib.decompress(data) bmp = bitmap(width, height, 1 << depth) scanline = (width * depth + 7) // 8 mem = memoryview(bmp) for y in range(height): dst = y * scanline src = y * (scanline + 1) + 1 - filter_ = data[src - 1] + filter_ = data_bytes[src - 1] if filter_ == 0: - mem[dst : dst + scanline] = data[src : src + scanline] + mem[dst : dst + scanline] = data_bytes[src : src + scanline] else: raise NotImplementedError("Filters not supported") return bmp, pal diff --git a/adafruit_imageload/pnm/__init__.py b/adafruit_imageload/pnm/__init__.py index 36b51c2..66b731d 100644 --- a/adafruit_imageload/pnm/__init__.py +++ b/adafruit_imageload/pnm/__init__.py @@ -1,5 +1,5 @@ # SPDX-FileCopyrightText: 2018 Scott Shawcroft for Adafruit Industries -# SPDX-FileCopyrightText: 2022 Matt Land +# SPDX-FileCopyrightText: 2022-2023 Matt Land # SPDX-FileCopyrightText: Brooke Storm # SPDX-FileCopyrightText: Sam McGahan # @@ -40,8 +40,8 @@ def load( file: BufferedReader, header: bytes, *, - bitmap: BitmapConstructor = None, - palette: PaletteConstructor = None + bitmap: Optional[BitmapConstructor] = None, + palette: Optional[PaletteConstructor] = None ) -> Tuple[Optional[Bitmap], Optional[Palette]]: """ Scan for netpbm format info, skip over comments, and delegate to a submodule @@ -92,10 +92,15 @@ def load( ) if len(pnm_header) == 2 and magic_number in [b"P1", b"P4"]: - bitmap = bitmap(pnm_header[0], pnm_header[1], 1) # type: Bitmap + if not bitmap: + raise RuntimeError( + "A bitmap constructor is required for this type of pnm format file" + ) + bitmap_obj = bitmap(pnm_header[0], pnm_header[1], 1) + palette_obj = None if palette: - palette = palette(1) # type: Palette - palette[0] = b"\xFF\xFF\xFF" + palette_obj = palette(1) + palette_obj[0] = b"\xFF\xFF\xFF" if magic_number.startswith(b"P1"): from . import pbm_ascii @@ -103,8 +108,8 @@ def load( file, pnm_header[0], pnm_header[1], - bitmap=bitmap, - palette=palette, + bitmap=bitmap_obj, + palette=palette_obj, ) from . import pbm_binary @@ -113,8 +118,8 @@ def load( file, pnm_header[0], pnm_header[1], - bitmap=bitmap, - palette=palette, + bitmap=bitmap_obj, + palette=palette_obj, ) next_byte = file.read(1) diff --git a/adafruit_imageload/pnm/pbm_ascii.py b/adafruit_imageload/pnm/pbm_ascii.py index 150f749..0122132 100644 --- a/adafruit_imageload/pnm/pbm_ascii.py +++ b/adafruit_imageload/pnm/pbm_ascii.py @@ -1,5 +1,5 @@ # SPDX-FileCopyrightText: 2018 Scott Shawcroft for Adafruit Industries -# SPDX-FileCopyrightText: 2022 Matt Land +# SPDX-FileCopyrightText: 2022-2023 Matt Land # SPDX-FileCopyrightText: Brooke Storm # SPDX-FileCopyrightText: Sam McGahan # @@ -32,7 +32,7 @@ def load( width: int, height: int, bitmap: Bitmap, - palette: Palette = None, + palette: Optional[Palette] = None, ) -> Tuple[Bitmap, Optional[Palette]]: """ Load a P1 'PBM' ascii image into the displayio.Bitmap diff --git a/adafruit_imageload/pnm/pbm_binary.py b/adafruit_imageload/pnm/pbm_binary.py index 9b6b9ad..263cb2c 100644 --- a/adafruit_imageload/pnm/pbm_binary.py +++ b/adafruit_imageload/pnm/pbm_binary.py @@ -1,5 +1,5 @@ # SPDX-FileCopyrightText: 2018 Scott Shawcroft for Adafruit Industries -# SPDX-FileCopyrightText: 2022 Matt Land +# SPDX-FileCopyrightText: 2022-2023 Matt Land # SPDX-FileCopyrightText: Brooke Storm # SPDX-FileCopyrightText: Sam McGahan # @@ -31,7 +31,7 @@ def load( width: int, height: int, bitmap: Bitmap, - palette: Palette = None, + palette: Optional[Palette] = None, ) -> Tuple[Bitmap, Optional[Palette]]: """ Load a P4 'PBM' binary image into the Bitmap diff --git a/adafruit_imageload/pnm/pgm/__init__.py b/adafruit_imageload/pnm/pgm/__init__.py index 9cb941d..3ed43f7 100644 --- a/adafruit_imageload/pnm/pgm/__init__.py +++ b/adafruit_imageload/pnm/pgm/__init__.py @@ -1,5 +1,5 @@ # SPDX-FileCopyrightText: 2018 Scott Shawcroft for Adafruit Industries -# SPDX-FileCopyrightText: 2022 Matt Land +# SPDX-FileCopyrightText: 2022-2023 Matt Land # SPDX-FileCopyrightText: Brooke Storm # SPDX-FileCopyrightText: Sam McGahan # @@ -29,8 +29,8 @@ def load( magic_number: bytes, header: List[int], *, - bitmap: BitmapConstructor = None, - palette: PaletteConstructor = None + bitmap: Optional[BitmapConstructor] = None, + palette: Optional[PaletteConstructor] = None ) -> Tuple[Optional[Bitmap], Optional[Palette]]: """ Perform the load of Netpbm greyscale images (P2, P5) diff --git a/adafruit_imageload/pnm/pgm/ascii.py b/adafruit_imageload/pnm/pgm/ascii.py index 300d1eb..097665f 100644 --- a/adafruit_imageload/pnm/pgm/ascii.py +++ b/adafruit_imageload/pnm/pgm/ascii.py @@ -1,5 +1,5 @@ # SPDX-FileCopyrightText: 2018 Scott Shawcroft for Adafruit Industries -# SPDX-FileCopyrightText: 2022 Matt Land +# SPDX-FileCopyrightText: 2022-2023 Matt Land # SPDX-FileCopyrightText: Brooke Storm # SPDX-FileCopyrightText: Sam McGahan # @@ -27,8 +27,8 @@ def load( file: BufferedReader, width: int, height: int, - bitmap: BitmapConstructor = None, - palette: PaletteConstructor = None, + bitmap: Optional[BitmapConstructor] = None, + palette: Optional[PaletteConstructor] = None, ) -> Tuple[Optional[Bitmap], Optional[Palette]]: """ Load a PGM ascii file (P2) @@ -46,11 +46,12 @@ def load( _palette_colors.add(int_pixel) pixel = bytearray() pixel += byte + palette_obj = None if palette: - palette = build_palette(palette, _palette_colors) # type: Palette + palette_obj = build_palette(palette, _palette_colors) + bitmap_obj = None if bitmap: - bitmap = bitmap(width, height, len(_palette_colors)) # type: Bitmap - _palette_colors = list(_palette_colors) + bitmap_obj = bitmap(width, height, len(_palette_colors)) file.seek(data_start) for y in range(height): for x in range(width): @@ -61,8 +62,8 @@ def load( break pixel += byte int_pixel = int("".join(["%c" % char for char in pixel])) - bitmap[x, y] = _palette_colors.index(int_pixel) - return bitmap, palette + bitmap_obj[x, y] = list(_palette_colors).index(int_pixel) + return bitmap_obj, palette_obj def build_palette( diff --git a/adafruit_imageload/pnm/pgm/binary.py b/adafruit_imageload/pnm/pgm/binary.py index 4dd8bff..7e8c56b 100644 --- a/adafruit_imageload/pnm/pgm/binary.py +++ b/adafruit_imageload/pnm/pgm/binary.py @@ -1,5 +1,5 @@ # SPDX-FileCopyrightText: 2018 Scott Shawcroft for Adafruit Industries -# SPDX-FileCopyrightText: 2022 Matt Land +# SPDX-FileCopyrightText: 2022-2023 Matt Land # SPDX-FileCopyrightText: Brooke Storm # SPDX-FileCopyrightText: Sam McGahan # @@ -15,7 +15,7 @@ """ try: - from typing import Tuple, Optional, Set, List + from typing import Tuple, Optional, Set from io import BufferedReader from displayio import Palette, Bitmap from ...displayio_types import PaletteConstructor, BitmapConstructor @@ -27,8 +27,8 @@ def load( file: BufferedReader, width: int, height: int, - bitmap: BitmapConstructor = None, - palette: PaletteConstructor = None, + bitmap: Optional[BitmapConstructor] = None, + palette: Optional[PaletteConstructor] = None, ) -> Tuple[Optional[Bitmap], Optional[Palette]]: """ Load a P5 format file (binary), handle PGM (greyscale) @@ -40,17 +40,18 @@ def load( for pixel in data_line: palette_colors.add(pixel) + palette_obj = None if palette: - palette = build_palette(palette, palette_colors) # type: Palette + palette_obj = build_palette(palette, palette_colors) + bitmap_obj = None if bitmap: - bitmap = bitmap(width, height, len(palette_colors)) # type: Bitmap - palette_colors = list(palette_colors) # type: List[int] + bitmap_obj = bitmap(width, height, len(palette_colors)) file.seek(data_start) for y in range(height): data_line = iter(bytes(file.read(width))) for x, pixel in enumerate(data_line): - bitmap[x, y] = palette_colors.index(pixel) - return bitmap, palette + bitmap_obj[x, y] = list(palette_colors).index(pixel) + return bitmap_obj, palette_obj def build_palette( diff --git a/adafruit_imageload/pnm/ppm_ascii.py b/adafruit_imageload/pnm/ppm_ascii.py index 8aa6b39..f6bb88b 100644 --- a/adafruit_imageload/pnm/ppm_ascii.py +++ b/adafruit_imageload/pnm/ppm_ascii.py @@ -1,5 +1,5 @@ # SPDX-FileCopyrightText: 2018 Scott Shawcroft for Adafruit Industries -# SPDX-FileCopyrightText: 2022 Matt Land +# SPDX-FileCopyrightText: 2022-2023 Matt Land # SPDX-FileCopyrightText: Brooke Storm # SPDX-FileCopyrightText: Sam McGahan # @@ -38,8 +38,8 @@ def load( file: BufferedReader, width: int, height: int, - bitmap: BitmapConstructor = None, - palette: PaletteConstructor = None, + bitmap: Optional[BitmapConstructor] = None, + palette: Optional[PaletteConstructor] = None, ) -> Tuple[Optional[Bitmap], Optional[Palette]]: """ :param stream file: infile with the position set at start of data @@ -55,27 +55,28 @@ def load( for triplet in read_three_colors(file): palette_colors.add(triplet) + palette_obj = None if palette: - palette = palette(len(palette_colors)) # type: Palette + palette_obj = palette(len(palette_colors)) for counter, color in enumerate(palette_colors): - palette[counter] = color + palette_obj[counter] = color + bitmap_obj = None if bitmap: file.seek(data_start) - bitmap = bitmap(width, height, len(palette_colors)) # type: Bitmap - palette_colors = list(palette_colors) # type: List[bytes] + bitmap_obj = bitmap(width, height, len(palette_colors)) for y in range(height): for x in range(width): for color in read_three_colors(file): - bitmap[x, y] = palette_colors.index(color) + bitmap_obj[x, y] = list(palette_colors).index(color) break # exit the inner generator - return bitmap, palette + return bitmap_obj, palette_obj def read_three_colors(file: BufferedReader) -> Iterator[bytes]: """ Generator to read integer values from file, in groups of three. Each value can be len 1-3, for values 0 - 255, space padded. - :return tuple[int]: + :return Iterator[bytes]: """ triplet = [] # type: List[int] color = bytearray() diff --git a/adafruit_imageload/pnm/ppm_binary.py b/adafruit_imageload/pnm/ppm_binary.py index cf32fb9..c828654 100644 --- a/adafruit_imageload/pnm/ppm_binary.py +++ b/adafruit_imageload/pnm/ppm_binary.py @@ -1,5 +1,5 @@ # SPDX-FileCopyrightText: 2018 Scott Shawcroft for Adafruit Industries -# SPDX-FileCopyrightText: 2022 Matt Land +# SPDX-FileCopyrightText: 2022-2023 Matt Land # SPDX-FileCopyrightText: Brooke Storm # SPDX-FileCopyrightText: Sam McGahan # @@ -31,11 +31,14 @@ def load( file: BufferedReader, width: int, height: int, - bitmap: BitmapConstructor = None, - palette: PaletteConstructor = None, + bitmap: Optional[BitmapConstructor] = None, + palette: Optional[PaletteConstructor] = None, ) -> Tuple[Optional[Bitmap], Optional[Palette]]: - """Load pixel values (indices or colors) into a bitmap and for a binary - ppm, return None for pallet.""" + """ + Load pixel values (indices or colors) into a bitmap and for a binary + ppm, return None for pallet. + """ + # pylint: disable=too-many-locals data_start = file.tell() palette_colors = set() # type: Set[Tuple[int, int, int]] @@ -47,22 +50,23 @@ def load( # red, green, blue palette_colors.add((red, next(data_line), next(data_line))) + palette_obj = None if palette: - palette = palette(len(palette_colors)) # type: Palette + palette_obj = palette(len(palette_colors)) for counter, color in enumerate(palette_colors): - palette[counter] = bytes(color) + palette_obj[counter] = bytes(color) + bitmap_obj = None if bitmap: - bitmap = bitmap(width, height, len(palette_colors)) # type: Bitmap + bitmap_obj = bitmap(width, height, len(palette_colors)) file.seek(data_start) - palette_colors = list(palette_colors) # type: List[Tuple[int, int, int]] for y in range(height): x = 0 data_line = iter(bytes(file.read(line_size))) for red in data_line: # red, green, blue - bitmap[x, y] = palette_colors.index( + bitmap_obj[x, y] = list(palette_colors).index( (red, next(data_line), next(data_line)) ) x += 1 - return bitmap, palette + return bitmap_obj, palette_obj diff --git a/adafruit_imageload/tilegrid_inflator.py b/adafruit_imageload/tilegrid_inflator.py index 0f40f6b..db6c65f 100644 --- a/adafruit_imageload/tilegrid_inflator.py +++ b/adafruit_imageload/tilegrid_inflator.py @@ -1,5 +1,5 @@ # SPDX-FileCopyrightText: 2022 Tim Cocks for Adafruit Industries -# SPDX-FileCopyrightText: 2022 Matt Land +# SPDX-FileCopyrightText: 2022-2023 Matt Land # # SPDX-License-Identifier: MIT @@ -27,9 +27,9 @@ def inflate_tilegrid( - bmp_path: str = None, + bmp_path: Optional[str] = None, target_size: Tuple[int, int] = (3, 3), - tile_size: List[int] = None, + tile_size: Optional[List[int]] = None, transparent_index: Optional[Union[tuple, int]] = None, bmp_obj: Optional[OnDiskBitmap] = None, bmp_palette: Optional[Palette] = None, @@ -39,8 +39,8 @@ def inflate_tilegrid( the center rows and columns. :param Optional[str] bmp_path: filepath to the 3x3 spritesheet bitmap file - :param Optional[tuple] target_size: desired size in tiles (target_width, target_height) - :param Optional[tuple] tile_size: size of the tiles in the 3x3 spritesheet. If + :param tuple[int, int] target_size: desired size in tiles (target_width, target_height) + :param Optional[List[int]] tile_size: size of the tiles in the 3x3 spritesheet. If None is used it will equally divide the width and height of the Bitmap by 3. :param Optional[Union[tuple, int]] transparent_index: a single index within the palette to make transparent, or a tuple of multiple indexes to make transparent diff --git a/mypy.ini b/mypy.ini index 5e6c3a5..a24b0e4 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022 Matt Land +# SPDX-FileCopyrightText: 2022-2023 Matt Land # # SPDX-License-Identifier: Unlicense [mypy] @@ -6,3 +6,9 @@ python_version = 3.7 disallow_untyped_defs = True disable_error_code = no-redef exclude = (examples|tests|setup.py|docs) + +[mypy-displayio] +ignore_missing_imports = True + +[mypy-bitmaptools] +ignore_missing_imports = True From ae65dc37e828eaeef915bf981f043dc8e30b643c Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 25 Apr 2023 18:13:21 -0500 Subject: [PATCH 2/2] revert pre-commit mypy task change for now. --- .pre-commit-config.yaml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 11aa787..0e5fccc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,4 @@ # SPDX-FileCopyrightText: 2020 Diego Elio Pettenò -# SPDX-FileCopyrightText: 2023 Matt Land # # SPDX-License-Identifier: Unlicense @@ -41,16 +40,3 @@ repos: files: "^tests/" args: - --disable=missing-docstring,consider-using-f-string,duplicate-code - - repo: local - hooks: - - id: mypy - name: mypy (library code) - entry: "mypy ." - language: python - additional_dependencies: ["mypy==1.2.0"] - types: [python] - exclude: "^(docs/|examples/|tests/|setup.py$)" - # use require_serial so that script - # is only called once per commit - require_serial: true - pass_filenames: false