Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ def test_check_size(self) -> None:
im = Image.new("L", (100, 0))
assert im.size == (100, 0)

assert Image.new("RGB", (1, 1))
assert isinstance(Image.new("RGB", (1, 1)), Image.Image)
# Should pass lists too
i = Image.new("RGB", [1, 1])
assert isinstance(i.size, tuple)
Expand Down
2 changes: 0 additions & 2 deletions Tests/test_pyarrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ def test_to_array(mode: str, dtype: pyarrow.DataType, mask: list[int] | None) ->

reloaded = Image.fromarrow(arr, mode, img.size)

assert reloaded
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could also change this to an assert isinstance or something, but I figured that'd also be kinda obvious.


assert_image_equal(img, reloaded)


Expand Down
3 changes: 1 addition & 2 deletions Tests/test_qt_image_qapplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ def roundtrip(expected: Image.Image) -> None:
def test_sanity(tmp_path: Path) -> None:
# Segfault test
app: QApplication | None = QApplication([])
ex = Example()
ex = Example() # noqa: F841
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the idea here is, but it looked as if the assert was purely there to avoid this F841 error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not preferable to avoid noqa where possible? My solution would have been assert ex is not None

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I prefer being explicit about ignored errors. And assert statements aren't "free" (the runtime impact is probably negligible, but still).
And, if at some point, some change causes this so that ex could actually become None, then ruff will complain about an unused # noqa, which would prevent a potential bug.

assert app # Silence warning
assert ex # Silence warning

for mode in ("1", "RGB", "RGBA", "L", "P"):
# to QPixmap
Expand Down
3 changes: 1 addition & 2 deletions checks/check_png_dos.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ def test_dos_text() -> None:
try:
im = Image.open(TEST_FILE)
im.load()
except ValueError as msg:
assert msg, "Decompressed Data Too Large"
except ValueError:
return

assert isinstance(im, PngImagePlugin.PngImageFile)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ python_version = "3.10"
pretty = true
disallow_any_generics = true
disallow_untyped_defs = true
enable_error_code = "ignore-without-code"
enable_error_code = [ "ignore-without-code", "truthy-bool" ]
extra_checks = true
follow_imports = "silent"
warn_redundant_casts = true
Expand Down
15 changes: 5 additions & 10 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,33 +438,28 @@ def preinit() -> None:
return

try:
from . import BmpImagePlugin
from . import BmpImagePlugin as BmpImagePlugin
Copy link
Author

@jorenham jorenham Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might look a bit weird (unless you're used to writing type stubs), but it avoids a # noqa. I wouldn't mind using # noqa here instead if that's preferred


assert BmpImagePlugin
except ImportError:
pass
try:
from . import GifImagePlugin
from . import GifImagePlugin as GifImagePlugin

assert GifImagePlugin
except ImportError:
pass
try:
from . import JpegImagePlugin
from . import JpegImagePlugin as JpegImagePlugin

assert JpegImagePlugin
except ImportError:
pass
try:
from . import PpmImagePlugin
from . import PpmImagePlugin as PpmImagePlugin

assert PpmImagePlugin
except ImportError:
pass
try:
from . import PngImagePlugin
from . import PngImagePlugin as PngImagePlugin

assert PngImagePlugin
except ImportError:
pass

Expand Down
2 changes: 1 addition & 1 deletion src/PIL/ImageFont.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _load_pilfont(self, filename: str) -> None:
except Exception:
pass
else:
if image and image.mode in ("1", "L"):
if image.mode in ("1", "L"):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at this point image cannot be None anymore

break
else:
if image:
Expand Down
Loading