Skip to content

Commit 4ac9e2e

Browse files
committed
issues.md: Add issue #5 and #6.
1 parent 9780c30 commit 4ac9e2e

File tree

1 file changed

+78
-1
lines changed

1 file changed

+78
-1
lines changed

issues.md

+78-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
# Errors in PyQt5-Stubs
2+
# Common issues in PyQt5-Stubs
33

44
## #1 Mixed overloads with static and non-static methods
55

@@ -196,3 +196,80 @@ definition in base class "QPaintDevice".`
196196

197197
This error is due to the Qt5 codebase and can not be fixed without breaking the current
198198
codebase. So silencing the error with # type: ignore seems to be the right way to go.
199+
200+
## #5 Signals need to be defined as pyqtSignal instead of functions
201+
202+
### Description
203+
204+
To allow the proper use of signal functions like connect() it is necessary to define
205+
signals as variables of type pyqtSignal instead of functions.
206+
207+
### Example
208+
209+
```python
210+
class QSignalMapper(QObject):
211+
212+
from PyQt5.QtWidgets import QWidget
213+
214+
def __init__(self, parent: typing.Optional[QObject] = ...) -> None: ...
215+
216+
# ...
217+
@typing.overload
218+
def mapped(self, a0: int) -> None: ...
219+
@typing.overload
220+
def mapped(self, a0: str) -> None: ...
221+
@typing.overload
222+
def mapped(self, a0: QWidget) -> None: ...
223+
@typing.overload
224+
def mapped(self, a0: QObject) -> None: ...
225+
# ...
226+
```
227+
228+
### Solution
229+
230+
```python
231+
class QSignalMapper(QObject):
232+
233+
from PyQt5.QtWidgets import QWidget
234+
235+
def __init__(self, parent: typing.Optional[QObject] = ...) -> None: ...
236+
237+
mapped: pyqtSignal
238+
239+
# ...
240+
# @typing.overload
241+
# def mapped(self, a0: int) -> None: ...
242+
# @typing.overload
243+
# def mapped(self, a0: str) -> None: ...
244+
# @typing.overload
245+
# def mapped(self, a0: QWidget) -> None: ...
246+
# @typing.overload
247+
# def mapped(self, a0: QObject) -> None: ...
248+
# ...
249+
```
250+
The disadvantage of this approach is that the signature of the signal is lost. But that
251+
actually does not matter as you will always need to define a slot function with the
252+
right signature anyway.
253+
254+
This should be fixed in the original PyQt5 stubs.
255+
256+
## #6 Missing type annotation for typing.Any
257+
258+
### Description
259+
260+
By default PyQt5 stubs do not contain type annotations for typing.Any.
261+
262+
### Example
263+
264+
```python
265+
def Q_FLAGS(*a0) -> None: ...
266+
```
267+
268+
**mypy error:**
269+
`Function is missing a type annotation for one or more arguments.`
270+
271+
### Solution
272+
273+
Add type annotation of type `typing.Any`.
274+
275+
This should be fixed in the original PyQt5 stubs.

0 commit comments

Comments
 (0)