3

I'm encountering an issue trying to use true_property and/or snake_case in PySide6. Without either, I can construct widgets using a form like this:

text = QtWidgets.QLabel('Example', margin=10)

where I specify Qt properties as keyword arguments when creating the widget. This does the same thing as:

text = QtWidgets.QLabel('Example', margin=10)
text.setMargin(10)
# Or with snake_case:
text.set_margin(10)
# Or with true_property:
text.margin = 10

However, importing snake_case and/or true_property breaks this "shortcut" constructor. I get the following results:

from PySide6 import QtWidgets
from __feature__ import snake_case

app = QtWidgets.QApplication()
text = QtWidgets.QLabel('Example', margin=10)

# AttributeError: PySide6.QtWidgets.QLabel.__init__(): 'margin' is not a Qt property or a signal
from PySide6 import QtWidgets
from __feature__ import true_property
# Same results from either of these:
# from __feature__ import snake_case, true_property
# from __feature__ import true_property, snake_case

app = QtWidgets.QApplication()
text = QtWidgets.QLabel('Example', margin=10)

# Segmentation fault: 11

Is this a bug, or is there something I'm missing here?

Do I really have to choose between these ergonomic Pythonifications and convenient constructors, or is there a way to get them to work together?

What's causing this behavior?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
CrazyChucky
  • 3,263
  • 4
  • 11
  • 25
  • I've to say, while interesting, I never liked the snake_case feature introduced in Qt6 (and I also have reservations about `true_property` too, even if usage of Qt properties in Python is inconsistent - but still possible to work around). It makes documentation and usage *very* incoherent, especially considering that: 1. some names don't fully respect casing; 2. it makes code much less sharable (consider using snake case on extended code snippets here on SO, for instance); 3. Qt has some (justified) *very* long namings already with camelCase, snake case makes it really less readable. – musicamante Nov 08 '21 at 19:59
  • I, for one, would suggest to avoid that feature at all. While snake case is considered more pythonic, it's not an absolute rule (it's a style *guide*), and there's plenty of modules and libraries that don't use it for many reasons. The PEP-8 doesn't directly mention naming rules for bindings (it only refers to "the prevailing style", and considering the context, Qt documentation and common usage is *already* the prevailing style), so I really don't see any *real* benefit in using snake against camel: their readability is certainly a matter of habit and taste, but consistency is foremost. – musicamante Nov 08 '21 at 20:07
  • 1
    That said, I'm not able to test it as I don't have Qt6 yet, but I believe this is almost certainly a bug. I suggest you to submit it, after waiting a reasonable amount of time to get more reliable replies. Maybe they'll finally realize that it's a bad idea too ;-) – musicamante Nov 08 '21 at 20:10
  • 1
    It's clearly a bug, those features are short on time and have not been sufficiently tested. I recommend you report it. – eyllanesc Nov 09 '21 at 00:16

1 Answers1

0

This was indeed a bug in PySide, which I reported here: PYSIDE-1705.

It has now been fixed as of PySide 6.2.4.

CrazyChucky
  • 3,263
  • 4
  • 11
  • 25