I am working on a PyQt application and have encountered an issue where a parameter seems to be evaluated as False
at runtime rather than None
. Here's a snippet of the code:
def createMenu(self):
"""Overrides Main menu"""
super().createMenu()
action = QAction('Import to MyPlugin', self, triggered=self.importFileToMyPlugin)
self.file_menu.insertAction(self.file_menu.actions()[6], action)
def importFileToMyPlugin(self, filename=None):
"""Overrides Import file"""
from myplugin.myplugin.plugins.plugin_module import MyPlugin
self.loadPlugin(MyPlugin)
self.addSheet()
w = self.getCurrentTable()
w.importMyPluginFile(filename, dialog=True)
return
In the importFileToMyPlugin
function, I set the default value of the filename
parameter to None
. However, at runtime, it seems to become False
. I can't figure out why this is happening.
Has anyone encountered this issue before? How can I ensure that the filename
stays as None
when it's not provided?
Any insight would be greatly appreciated. Thank you!
I have looked at an answer that suggested using the @QtCore.pyqtSlot() decorator to avoid this issue but I'm not convicend that's the easiest solution.