[BUG] Cython has problems recognizing signals from PyQt6.
Describe the bug
A common button signal and slot function in PyQt6 has problems when compiled with cython. (The original py file works fine)
Code to reproduce the behaviour:
class ProjectDialog(QDialog, Ui_project_dialog_layout):
def __init__(self):
super().__init__()
self.setupUi(self)
self.dir_button.clicked.connect(self.get_path)
def get_path(self):
# do something
print('work well')
Expected behaviour
- In the original py file, the minimal example shown above performs the function inside the get_path method when the button is clicked.
- I use cythonize -i -3 ProjectDialog.py to compile the py file.
- Call the class ProjectDialog compiled by cython, and the following error message appears after executing the button clicking function: Traceback (most recent call last): File "ProjectDialog.py", line 55, in ProjectDialog.get_path TypeError: get_path() takes exactly 1 positional argument (2 given)
- I found two solutions for this case, one is to add a parameter to the get_path method to accept the bool value emitted by PyQt6's clicked signal, and the other is to use a lambda function:
class ProjectDialog(QDialog, Ui_project_dialog_layout):
def __init__(self):
super().__init__()
self.setupUi(self)
self.dir_button.clicked.connect(self.get_path)
def get_path(self, click_status):
# do something
print('work well')
class ProjectDialog(QDialog, Ui_project_dialog_layout):
def __init__(self):
super().__init__()
self.setupUi(self)
self.dir_button.clicked.connect(lambda: self.get_path())
def get_path(self):
# do something
print('work well')
- i would like to know why cython is causing this?
OS
Windows 11 Professional
Python version
Python 3.12.0
Cython version
Cython version 3.0.6
Additional context
No response
I'm relatively convinced that this is a bug in PyQt6 (and that it internally relies on being passed a Python function, therefore is incompatible pretty much by definition) and thus there's nothing Cython can do to fix this. But I'm not absolutely certain and it's fairly difficult to investigate.
Qt code doesn't usually benefit from being processed by Cython. And we aren't hugely interested in supporting obfuscation (which is the main reason that people want to do it).
So it'll probably only get fixed if someone else wants to investigate and propose a fix (either to Cython, or more likely to PyQt6).