Repository navigation
Ensure project bootstraps generate ruff-clean code. - #3144
Conversation
|
|
||
| app = QtWidgets.QApplication(sys.argv) | ||
| main_window = {{ cookiecutter.class_name }}() | ||
| _ = {{ cookiecutter.class_name }}() |
There was a problem hiding this comment.
Is it necessary to assign this to a variable to keep it in existence? Doesn't showing the window automatically add a reference from the app?
If it is necessary, I think a normal variable name and a noqa comment with an explanation would be better than relying on _ for something so important.
There was a problem hiding this comment.
It has to be assigned to something - otherwise the object passes out of scope and is garbage collected, so the window is never displayed.
I'd rather avoid a noqa in freshly generated template code; I've found another solution - factor the show() out of init_ui so that main_window is used. It's arguably a better idea to keep displaying the window indpendent of construction anyway, so we can kill 2 birds with 1 stone.
Clean up some unused imports and variables to ensure that generated projects pass a default Ruff configuration.
ROWandCOLUMNimports were unused in the default Toga configuration (but can be easily added when needed)main_windowobject was never used in the PySide6 configuration.Refs beeware/.github#380.
PR Checklist: