Skip to content

Commit a865345

Browse files
authored
Remove type hint ignore (#9538)
2 parents e81acb8 + 1dd1c9a commit a865345

3 files changed

Lines changed: 10 additions & 18 deletions

File tree

Tests/test_file_jpeg2k.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ def test_default_num_resolutions(
178178

179179
def test_reduce() -> None:
180180
with Image.open("Tests/images/test-card-lossless.jp2") as im:
181-
assert callable(im.reduce)
181+
assert isinstance(im, Jpeg2KImagePlugin.Jpeg2KImageFile)
182182

183-
im.reduce = 2 # type: ignore[assignment, method-assign]
183+
im.reduce = 2
184184
assert im.reduce == 2
185185

186186
im.load()

Tests/test_file_png.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
import warnings
66
import zlib
7-
from io import BytesIO
7+
from io import BytesIO, TextIOWrapper
88
from pathlib import Path
99
from types import ModuleType
1010
from typing import Any, cast
@@ -821,19 +821,15 @@ def test_seek(self) -> None:
821821
@pytest.mark.parametrize("buffer", (True, False))
822822
def test_save_stdout(self, buffer: bool, monkeypatch: pytest.MonkeyPatch) -> None:
823823

824-
class MyStdOut:
825-
buffer = BytesIO()
826-
827-
mystdout: MyStdOut | BytesIO = MyStdOut() if buffer else BytesIO()
824+
fp = BytesIO()
825+
mystdout = TextIOWrapper(fp) if buffer else fp
828826

829827
monkeypatch.setattr(sys, "stdout", mystdout)
830828

831829
with Image.open(TEST_PNG_FILE) as im:
832830
im.save(sys.stdout, "PNG") # type: ignore[arg-type]
833831

834-
if isinstance(mystdout, MyStdOut):
835-
mystdout = mystdout.buffer
836-
with Image.open(mystdout) as reloaded:
832+
with Image.open(fp) as reloaded:
837833
assert_image_equal_tofile(reloaded, TEST_PNG_FILE)
838834

839835
def test_truncated_end_chunk(self, monkeypatch: pytest.MonkeyPatch) -> None:

Tests/test_file_ppm.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import sys
4-
from io import BytesIO
4+
from io import BytesIO, TextIOWrapper
55
from pathlib import Path
66

77
import pytest
@@ -381,17 +381,13 @@ def test_mimetypes(tmp_path: Path) -> None:
381381
@pytest.mark.parametrize("buffer", (True, False))
382382
def test_save_stdout(buffer: bool, monkeypatch: pytest.MonkeyPatch) -> None:
383383

384-
class MyStdOut:
385-
buffer = BytesIO()
386-
387-
mystdout: MyStdOut | BytesIO = MyStdOut() if buffer else BytesIO()
384+
fp = BytesIO()
385+
mystdout = TextIOWrapper(fp) if buffer else fp
388386

389387
monkeypatch.setattr(sys, "stdout", mystdout)
390388

391389
with Image.open(TEST_FILE) as im:
392390
im.save(sys.stdout, "PPM") # type: ignore[arg-type]
393391

394-
if isinstance(mystdout, MyStdOut):
395-
mystdout = mystdout.buffer
396-
with Image.open(mystdout) as reloaded:
392+
with Image.open(fp) as reloaded:
397393
assert_image_equal_tofile(reloaded, TEST_FILE)

0 commit comments

Comments
 (0)