PySide Bugzilla Closed for New Bugs

PySide is now a Qt Add-on and uses the Qt Project's JIRA Bug Tracker instead of this Bugzilla instance. This Bugzilla is left for reference purposes.

Bug 611 - enum values lack a tp_print implementation
: enum values lack a tp_print implementation
Status: CLOSED FIXED
Product: PySide
Classification: Unclassified
Component: Shiboken
: HEAD
: All All
: P3 normal
Assigned To: Marcelo Lira
:
:
:
  Show dependency treegraph
 
Reported: 2011-01-13 15:01 EET by Farsmo
Modified: 2011-01-21 15:44 EET (History)
8 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Farsmo 2011-01-13 15:01:57 EET
The Python doc says that print() should always print the str() of an object,
but since PySide enum values don't reimplement tp_print they effectively print
the str() of the int().
Comment 1 Matti Airas 2011-01-14 07:43:03 EET
Thanks for the bug report! Prioritizing P3 - this will be taken care during the
next sprint, at the latest (most likely sooner than that, though).
Comment 2 Lauro Moura 2011-01-20 18:42:03 EET
Could this be changed to implement a better __str__/__repr__ for enums? From
python docs:

"It is possible that the tp_print field will be deprecated. In any case, it is
recommended not to define tp_print, but instead to rely on tp_repr and tp_str
for printing."

Also: "The print function is only called when the instance is printed to a real
file; when it is printed to a pseudo-file (like a StringIO instance), the
instance’s tp_repr or tp_str function is called to convert it to a string."
Comment 3 Lauro Moura 2011-01-20 18:42:50 EET
Forgot the link :)

http://docs.python.org/c-api/typeobj.html?highlight=tp_print#tp_print
Comment 4 Farsmo 2011-01-20 21:26:48 EET
Ah, so the documentation seems to be inconsistent, because whatever your quote
says, the fact is that when you derive from the int type (as PySide enums do),
it's necessary to re-implement tp_print if you want print's documentation to
hold true:
http://docs.python.org/library/functions.html#print
http://docs.python.org/reference/simple_stmts.html#the-print-statement

At any rate, there are three hypotheses:
- the current PySide behavior is OK and the print() documentation is wrong.
- the tp_print documentation forgot to say that in the (rare) case when you
inherit from int you still have to redefine tp_print.
- int's tp_print implementation is buggy because it doesn't take derived
classes into account.

The first hypothesis seems very unlikely, so PySide's behavior will have to
change either through a fix in Python or a fix in PySide.

Did you check that the bug happens even with Python 2.7(.1)?


PS: the issue of a better __str__/__repr__ is completely independent of this
bug: a tp_print implementation would consider __str__ as a black box.
Comment 5 Marcelo Lira 2011-01-21 12:04:38 EET
Fixed in commit Shiboken/32938470.
Comment 6 renato filho 2011-01-21 15:44:50 EET
release beta4