After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 639904 - make representation of enum members follow common Python recommendations
make representation of enum members follow common Python recommendations
Status: RESOLVED DUPLICATE of bug 657915
Product: pygobject
Classification: Bindings
Component: general
unspecified
Other All
: Normal minor
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2011-01-18 22:14 UTC by Paul Pogonyshev
Modified: 2012-04-22 08:02 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
draft of a patch (2.68 KB, patch)
2012-04-21 12:53 UTC, Martin Pitt
needs-work Details | Review

Description Paul Pogonyshev 2011-01-18 22:14:10 UTC
From __repr__ documentation:

    Called by the repr() built-in function and by string conversions (reverse quotes) to compute the “official” string representation of an object. If at all possible, this should look like a valid Python expression that could be used to recreate an object with the same value (given an appropriate environment).

Enum members obviously have a trivial evaluatable representation in an environment with some required imports.  Therefore, by Python rules it should hold that e.g.:

    repr (gtk.RESPONSE_ACCEPT) == 'gtk.RESPONSE_ACCEPT'

I.e. __repr__ in enum members should drop '<...>' representation as not useful and instead return the member name with the required modules.
Comment 1 Paul Pogonyshev 2011-01-18 22:15:28 UTC
Mentioned in IRC channel and two people decided to submit this bug.

*** This bug has been marked as a duplicate of bug 639903 ***
Comment 2 Paul Pogonyshev 2011-01-18 22:16:26 UTC
Hm, should have read the other before closing.
Comment 3 Martin Pitt 2012-04-21 11:46:41 UTC
Still an issue with current 3.2:

>>> from gi.repository import Gtk
>>> Gtk.ResponseType.ACCEPT
<enum GTK_RESPONSE_ACCEPT of type GtkResponseType>
>>> repr(Gtk.ResponseType.ACCEPT)
'<enum GTK_RESPONSE_ACCEPT of type GtkResponseType>'
Comment 4 Martin Pitt 2012-04-21 12:53:25 UTC
Created attachment 212501 [details] [review]
draft of a patch

This is a sketch how this would look like, including a test case. The repr() comes out as gi.repository.GIMarshallingTests.Enum.value1.

Problems:
 - This affects all identifiers in PyGObject, not just enums, it's a global problem.
 - The enum value is in lower case, but needs to be upper case (I can't find the code which parses a value like Gtk.ResponseType.CANCEL to match the nick "cancel" or name "GTK_RESPONSE_TYPE_CANCEL")
 - This currently prepends __module__, which is gi.repository.GIMarshallingTests. But it should be "GIMarshallingtests", unless you actually did "import gi.repository.GIMarshallingTests" instead of the usual "from gi.repository import GIMarshallingTests".
Comment 5 Martin Pitt 2012-04-22 08:02:08 UTC

*** This bug has been marked as a duplicate of bug 657915 ***