11from __future__ import annotations
22
3- from pathlib import Path
4- from typing import Union
5-
63import pytest
74
85from PIL import Image , ImageQt
118
129TYPE_CHECKING = False
1310if TYPE_CHECKING :
14- import PyQt6
15- import PySide6
16-
17- QApplication = Union [PyQt6 .QtWidgets .QApplication , PySide6 .QtWidgets .QApplication ]
18- QHBoxLayout = Union [PyQt6 .QtWidgets .QHBoxLayout , PySide6 .QtWidgets .QHBoxLayout ]
19- QImage = Union [PyQt6 .QtGui .QImage , PySide6 .QtGui .QImage ]
20- QLabel = Union [PyQt6 .QtWidgets .QLabel , PySide6 .QtWidgets .QLabel ]
21- QPainter = Union [PyQt6 .QtGui .QPainter , PySide6 .QtGui .QPainter ]
22- QPixmap = Union [PyQt6 .QtGui .QPixmap , PySide6 .QtGui .QPixmap ]
23- QPoint = Union [PyQt6 .QtCore .QPoint , PySide6 .QtCore .QPoint ]
24- QRegion = Union [PyQt6 .QtGui .QRegion , PySide6 .QtGui .QRegion ]
25- QWidget = Union [PyQt6 .QtWidgets .QWidget , PySide6 .QtWidgets .QWidget ]
11+ from pathlib import Path
12+
2613
2714if ImageQt .qt_is_installed :
2815 from PIL .ImageQt import QPixmap
3219 from PyQt6 .QtGui import QImage , QPainter , QRegion
3320 from PyQt6 .QtWidgets import QApplication , QHBoxLayout , QLabel , QWidget
3421 elif ImageQt .qt_version == "side6" :
35- from PySide6 .QtCore import QPoint
36- from PySide6 .QtGui import QImage , QPainter , QRegion
37- from PySide6 .QtWidgets import QApplication , QHBoxLayout , QLabel , QWidget
38-
39- class Example (QWidget ): # type: ignore[misc]
22+ from PySide6 .QtCore import QPoint # type: ignore[assignment]
23+ from PySide6 .QtGui import QImage , QPainter , QRegion # type: ignore[assignment]
24+ from PySide6 .QtWidgets import ( # type: ignore[assignment]
25+ QApplication ,
26+ QHBoxLayout ,
27+ QLabel ,
28+ QWidget ,
29+ )
30+
31+ class Example (QWidget ):
4032 def __init__ (self ) -> None :
4133 super ().__init__ ()
4234
@@ -47,9 +39,9 @@ def __init__(self) -> None:
4739 pixmap1 = getattr (ImageQt .QPixmap , "fromImage" )(qimage )
4840
4941 # hbox
50- QHBoxLayout (self ) # type: ignore[operator]
42+ QHBoxLayout (self )
5143
52- lbl = QLabel (self ) # type: ignore[operator]
44+ lbl = QLabel (self )
5345 # Segfault in the problem
5446 lbl .setPixmap (pixmap1 .copy ())
5547
@@ -63,7 +55,7 @@ def roundtrip(expected: Image.Image) -> None:
6355@pytest .mark .skipif (not ImageQt .qt_is_installed , reason = "Qt bindings are not installed" )
6456def test_sanity (tmp_path : Path ) -> None :
6557 # Segfault test
66- app : QApplication | None = QApplication ([]) # type: ignore[operator]
58+ app : QApplication | None = QApplication ([])
6759 ex = Example ()
6860 assert app # Silence warning
6961 assert ex # Silence warning
@@ -84,11 +76,11 @@ def test_sanity(tmp_path: Path) -> None:
8476 imageqt = ImageQt .ImageQt (im )
8577 data = getattr (QPixmap , "fromImage" )(imageqt )
8678 qt_format = getattr (QImage , "Format" ) if ImageQt .qt_version == "6" else QImage
87- qimage = QImage (128 , 128 , getattr (qt_format , "Format_ARGB32" )) # type: ignore[operator]
88- painter = QPainter (qimage ) # type: ignore[operator]
89- image_label = QLabel () # type: ignore[operator]
79+ qimage = QImage (128 , 128 , getattr (qt_format , "Format_ARGB32" ))
80+ painter = QPainter (qimage )
81+ image_label = QLabel ()
9082 image_label .setPixmap (data )
91- image_label .render (painter , QPoint (0 , 0 ), QRegion (0 , 0 , 128 , 128 )) # type: ignore[operator]
83+ image_label .render (painter , QPoint (0 , 0 ), QRegion (0 , 0 , 128 , 128 ))
9284 painter .end ()
9385 rendered_tempfile = str (tmp_path / f"temp_rendered_{ mode } .png" )
9486 qimage .save (rendered_tempfile )
0 commit comments