Skip to content

Commit 47fcbd3

Browse files
committed
adafruit#56 more linting
1 parent 3481819 commit 47fcbd3

18 files changed

+76
-48
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,8 @@ _build
4545
.idea
4646
.vscode
4747
*~
48+
49+
# virtualenv
50+
Pipfile
51+
Pipfile.lock
52+
Makefile

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ repos:
2525
types: [python]
2626
args:
2727
- --disable=consider-using-f-string
28+
- --min-similarity-lines=14
2829
exclude: "^(docs/|examples/|tests/|setup.py$)"
2930
- id: pylint
3031
name: pylint (example code)

.pylintrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,7 @@ ignore-docstrings=yes
252252
ignore-imports=yes
253253

254254
# Minimum lines number of a similarity.
255-
min-similarity-lines=4
256-
255+
min-similarity-lines=14
257256

258257
[BASIC]
259258

adafruit_imageload/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
Iterable,
2424
Union,
2525
)
26-
from io import BufferedReader, FileIO
26+
from io import BufferedReader
2727
from displayio import Palette, Bitmap
2828
from .displayio_types import Palette_Constructor, Bitmap_Constructor
2929
except ImportError:
@@ -75,9 +75,7 @@ def load(
7575
if header.startswith(b"P"):
7676
from . import pnm
7777

78-
return pnm.load(
79-
file, header, bitmap_constructor=bitmap, palette_constructor=palette
80-
)
78+
return pnm.load(file, header, bitmap=bitmap, palette=palette)
8179
if header.startswith(b"GIF"):
8280
from . import gif
8381

adafruit_imageload/bmp/indexed.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
import sys
1818

1919
try:
20-
from typing import Tuple, Optional, Set, List
20+
from typing import Tuple, Optional, List
2121
from displayio import Palette, Bitmap
22-
from io import FileIO
22+
from io import BufferedReader
2323
from ..displayio_types import Palette_Constructor, Bitmap_Constructor
2424
except ImportError:
2525
pass
@@ -35,7 +35,7 @@
3535

3636

3737
def load(
38-
file: FileIO,
38+
file: BufferedReader,
3939
width: int,
4040
height: int,
4141
data_start: int,
@@ -135,7 +135,7 @@ def load(
135135

136136
def decode_rle(
137137
bitmap: Bitmap,
138-
file: FileIO,
138+
file: BufferedReader,
139139
compression: int,
140140
y_range: Tuple[int, int, int],
141141
width: int,

adafruit_imageload/displayio_types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
1313
"""
1414
try:
15-
from typing import Callable, Optional
16-
from displayio import Palette, Bitmap, OnDiskBitmap
15+
from typing import Callable
16+
from displayio import Palette, Bitmap
1717

1818
Palette_Constructor = Callable[[int], Palette]
1919
Bitmap_Constructor = Callable[[int, int, int], Bitmap]

adafruit_imageload/gif.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
import struct
1818

1919
try:
20-
from typing import Tuple, Iterator, Optional, List, Iterable, Union, BinaryIO
20+
from typing import Tuple, Iterator, Optional, List
2121
from displayio import Palette, Bitmap
2222
from .displayio_types import Palette_Constructor, Bitmap_Constructor
23+
from io import BufferedReader
2324
except ImportError:
2425
pass
2526

@@ -28,7 +29,10 @@
2829

2930

3031
def load(
31-
file: BinaryIO, *, bitmap: Bitmap_Constructor, palette: Palette_Constructor = None
32+
file: BufferedReader,
33+
*,
34+
bitmap: Bitmap_Constructor,
35+
palette: Palette_Constructor = None
3236
) -> Tuple[Bitmap, Optional[Palette]]:
3337
"""Loads a GIF image from the open ``file``.
3438
@@ -42,7 +46,11 @@ def load(
4246
header = file.read(6)
4347
if header not in {b"GIF87a", b"GIF89a"}:
4448
raise ValueError("Not a GIF file")
45-
width, height, flags, _, _ = struct.unpack("<HHBBB", file.read(7))
49+
50+
width, height, flags, _, _ = struct.unpack( # pylint: disable=no-member
51+
"<HHBBB", file.read(7)
52+
)
53+
4654
if (flags & 0x80) != 0:
4755
palette_size = 1 << ((flags & 0x07) + 1)
4856
palette_obj = palette(palette_size)
@@ -67,9 +75,11 @@ def load(
6775
return bitmap_obj, palette_obj
6876

6977

70-
def _read_frame(file: FileIO, bitmap: Bitmap) -> None:
78+
def _read_frame(file: BufferedReader, bitmap: Bitmap) -> None:
7179
"""Read a single frame and apply it to the bitmap."""
72-
ddx, ddy, width, _, flags = struct.unpack("<HHHHB", file.read(9))
80+
ddx, ddy, width, _, flags = struct.unpack( # pylint: disable=no-member
81+
"<HHHHB", file.read(9)
82+
)
7383
if (flags & 0x40) != 0:
7484
raise NotImplementedError("Interlacing not supported")
7585
if (flags & 0x80) != 0:
@@ -88,7 +98,7 @@ def _read_frame(file: FileIO, bitmap: Bitmap) -> None:
8898
y += 1
8999

90100

91-
def _read_blockstream(file: FileIO) -> Iterator[int]:
101+
def _read_blockstream(file: BufferedReader) -> Iterator[int]:
92102
"""Read a block from a file."""
93103
while True:
94104
size = file.read(1)[0]

adafruit_imageload/pnm/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
Iterable,
2626
Union,
2727
Callable,
28-
BinaryIO,
2928
)
3029
from displayio import Palette, Bitmap
3130
from ..displayio_types import Palette_Constructor, Bitmap_Constructor
31+
from io import BufferedReader
3232
except ImportError:
3333
pass
3434

@@ -37,7 +37,7 @@
3737

3838

3939
def load(
40-
file: BinaryIO,
40+
file: BufferedReader,
4141
header: bytes,
4242
*,
4343
bitmap: Bitmap_Constructor = None,
@@ -110,7 +110,11 @@ def load(
110110
from . import pbm_binary
111111

112112
return pbm_binary.load(
113-
file, pnm_header[0], pnm_header[1], bitmap=bitmap_obj, palette=palette_obj
113+
file,
114+
pnm_header[0],
115+
pnm_header[1],
116+
bitmap=bitmap_obj,
117+
palette=palette_obj,
114118
)
115119

116120
next_byte = file.read(1)

adafruit_imageload/pnm/pbm_ascii.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
try:
2020
from typing import Tuple, Optional
21-
from io import FileIO
21+
from io import BufferedReader
2222
from displayio import Palette, Bitmap
2323
except ImportError:
2424
pass
@@ -28,7 +28,11 @@
2828

2929

3030
def load(
31-
file: FileIO, width: int, height: int, bitmap: Bitmap, palette: Palette = None
31+
file: BufferedReader,
32+
width: int,
33+
height: int,
34+
bitmap: Bitmap,
35+
palette: Palette = None,
3236
) -> Tuple[Bitmap, Optional[Palette]]:
3337
"""
3438
Load a P1 'PBM' ascii image into the displayio.Bitmap

adafruit_imageload/pnm/pbm_binary.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
1717
"""
1818
try:
19-
from typing import Tuple, Iterator, Optional
20-
from io import FileIO
19+
from typing import Tuple, Optional, Iterator
20+
from io import BufferedReader
2121
from displayio import Palette, Bitmap
2222
except ImportError:
2323
pass
@@ -27,7 +27,11 @@
2727

2828

2929
def load(
30-
file: FileIO, width: int, height: int, bitmap: Bitmap, palette: Palette = None
30+
file: BufferedReader,
31+
width: int,
32+
height: int,
33+
bitmap: Bitmap,
34+
palette: Palette = None,
3135
) -> Tuple[Bitmap, Optional[Palette]]:
3236
"""
3337
Load a P4 'PBM' binary image into the Bitmap

adafruit_imageload/pnm/pgm/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@
1717
# pylint: disable=import-outside-toplevel
1818
try:
1919
from typing import Tuple, Optional, Set, List
20-
from io import FileIO
20+
from io import BufferedReader
2121
from displayio import Palette, Bitmap
2222
from ...displayio_types import Palette_Constructor, Bitmap_Constructor
2323
except ImportError:
2424
pass
2525

2626

2727
def load(
28-
file: FileIO,
28+
file: BufferedReader,
2929
magic_number: bytes,
3030
header: List[int],
3131
*,
3232
bitmap: Bitmap_Constructor = None,
3333
palette: Palette_Constructor = None
34-
) -> Tuple[Bitmap, Palette]:
34+
) -> Tuple[Optional[Bitmap], Optional[Palette]]:
3535
"""
3636
Perform the load of Netpbm greyscale images (P2, P5)
3737
"""

adafruit_imageload/pnm/pgm/ascii.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@
1515
1616
"""
1717
try:
18-
from typing import Tuple, Optional, Set
18+
from typing import Tuple, Set, Optional
1919
from displayio import Palette, Bitmap
20-
from io import FileIO
20+
from io import BufferedReader
2121
from ...displayio_types import Palette_Constructor, Bitmap_Constructor
2222
except ImportError:
2323
pass
2424

2525

2626
def load(
27-
file: FileIO,
27+
file: BufferedReader,
2828
width: int,
2929
height: int,
3030
bitmap: Bitmap_Constructor = None,
3131
palette: Palette_Constructor = None,
32-
):
32+
) -> Tuple[Optional[Bitmap], Optional[Palette]]:
3333
"""
3434
Load a PGM ascii file (P2)
3535
"""

adafruit_imageload/pnm/pgm/binary.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
"""
1717
try:
1818
from typing import Tuple, Optional, Set, List
19-
from io import FileIO
19+
from io import BufferedReader
2020
from displayio import Palette, Bitmap
2121
from ...displayio_types import Palette_Constructor, Bitmap_Constructor
2222
except ImportError:
2323
pass
2424

2525

2626
def load(
27-
file: FileIO,
27+
file: BufferedReader,
2828
width: int,
2929
height: int,
3030
bitmap: Bitmap_Constructor = None,
@@ -44,7 +44,7 @@ def load(
4444
palette = build_palette(palette, palette_colors) # type: Palette
4545
if bitmap:
4646
bitmap = bitmap(width, height, len(palette_colors)) # type: Bitmap
47-
palette_colors = list(palette_colors)
47+
palette_colors = list(palette_colors) # type: List[int]
4848
file.seek(data_start)
4949
for y in range(height):
5050
data_line = iter(bytes(file.read(width)))
@@ -53,7 +53,9 @@ def load(
5353
return bitmap, palette
5454

5555

56-
def build_palette(palette_class: Palette, palette_colors: Set[int]) -> Palette:
56+
def build_palette(
57+
palette_class: Palette_Constructor, palette_colors: Set[int]
58+
) -> Palette:
5759
"""
5860
construct the Palette, and populate it with the set of palette_colors
5961
"""

adafruit_imageload/pnm/ppm_ascii.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,17 @@
2525
Iterator,
2626
Optional,
2727
List,
28-
Union,
2928
Set,
30-
SupportsIndex,
3129
)
3230
from displayio import Palette, Bitmap
33-
from io import FileIO
31+
from io import BufferedReader
3432
from ..displayio_types import Palette_Constructor, Bitmap_Constructor
3533
except ImportError:
3634
pass
3735

3836

3937
def load(
40-
file: FileIO,
38+
file: BufferedReader,
4139
width: int,
4240
height: int,
4341
bitmap: Bitmap_Constructor = None,
@@ -73,7 +71,7 @@ def load(
7371
return bitmap, palette
7472

7573

76-
def read_three_colors(file: FileIO) -> Iterator[bytes]:
74+
def read_three_colors(file: BufferedReader) -> Iterator[bytes]:
7775
"""
7876
Generator to read integer values from file, in groups of three.
7977
Each value can be len 1-3, for values 0 - 255, space padded.

adafruit_imageload/pnm/ppm_binary.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
1717
"""
1818
try:
19-
from typing import Tuple, Iterator, Optional, Union, List, Set
20-
from io import FileIO
19+
from typing import Tuple, Optional, List, Set
20+
from io import BufferedReader
2121
from displayio import Palette, Bitmap
2222
from ..displayio_types import Palette_Constructor, Bitmap_Constructor
2323
except ImportError:
@@ -28,7 +28,7 @@
2828

2929

3030
def load(
31-
file: FileIO,
31+
file: BufferedReader,
3232
width: int,
3333
height: int,
3434
bitmap: Bitmap_Constructor = None,

adafruit_imageload/tilegrid_inflator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import adafruit_imageload
1818

1919
try:
20-
from typing import Tuple, Iterator, Optional, List, Iterable, Union
21-
from displayio import Palette, Bitmap, OnDiskBitmap, TileGrid, Colorspace
20+
from typing import Tuple, Optional, List, Union
21+
from displayio import Palette, Bitmap, OnDiskBitmap, TileGrid
2222
except ImportError:
2323
pass
2424

mypy.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
# SPDX-FileCopyrightText: 2022 Matt Land
2+
#
3+
# SPDX-License-Identifier: Unlicense
14
[mypy]
25
python_version = 3.9
36
disallow_untyped_defs = True
47
disable_error_code = no-redef
58
# type: ignore[no-redef]
6-
exclude = (examples|tests|setup.py|docs)
9+
exclude = (examples|tests|setup.py|docs)

requirements-dev.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)