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 655623 - [glib build error] AttributeError: 'dict' object has no attribute 'has_key' with Python3
[glib build error] AttributeError: 'dict' object has no attribute 'has_key' w...
Status: RESOLVED DUPLICATE of bug 678066
Product: glib
Classification: Platform
Component: gdbus
2.29.x
Other Linux
: Normal normal
: ---
Assigned To: David Zeuthen (not reading bugmail)
gtkdev
Depends on:
Blocks: 684103
 
 
Reported: 2011-07-30 09:38 UTC by Douglas
Modified: 2012-09-29 08:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
a proper patch, with working version sort (8.65 KB, patch)
2011-11-10 19:22 UTC, Mantas Mikulėnas (grawity)
none Details | Review
one that works with older versions again (hopefully) (8.98 KB, patch)
2011-11-10 19:41 UTC, Mantas Mikulėnas (grawity)
none Details | Review

Description Douglas 2011-07-30 09:38:06 UTC
I'm building current git devel (glib-v2.29.14-56-gc3af3d8). That's what I've got on 'make' stage:

make[4]: Entering directory `/root/build-farm/glib-v2.29.14-56-gc3af3d8.builddir/gio/tests'
  GEN      gdbus-test-codegen-generated.c
Traceback (most recent call last):
  • File "../../gio/gdbus-codegen/codegen_main.py", line 200 in <module>
    codegen_main()
  • File "../../gio/gdbus-codegen/codegen_main.py", line 171 in codegen_main
    parsed_ifaces = parser.parse_dbus_xml(xml_data)
  • File "/root/build-farm/glib-v2.29.14-56-gc3af3d8.builddir/gio/gdbus-codegen/parser.py", line 289 in parse_dbus_xml
    parser = DBusXMLParser(xml_data)
  • File "/root/build-farm/glib-v2.29.14-56-gc3af3d8.builddir/gio/gdbus-codegen/parser.py", line 57 in __init__
    self._parser.Parse(xml_data)
  • File "/root/build-farm/glib-v2.29.14-56-gc3af3d8.builddir/gio/gdbus-codegen/parser.py", line 155 in handle_start_element
    if attrs.has_key('name') and self.doc_comment_last_symbol == attrs['name']:
AttributeError: 'dict' object has no attribute 'has_key'
make[4]: *** [gdbus-test-codegen-generated.c] Error 1
make[4]: Leaving directory `/root/build-farm/glib-v2.29.14-56-gc3af3d8.builddir/gio/tests'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/root/build-farm/glib-v2.29.14-56-gc3af3d8.builddir/gio'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/root/build-farm/glib-v2.29.14-56-gc3af3d8.builddir/gio'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/build-farm/glib-v2.29.14-56-gc3af3d8.builddir'
make: *** [all] Error 2
ERROR: 'make' error. Abort.

By searching for this error message (AttributeError: 'dict' object has no attribute 'has_key'), I found that this is the problem of using python2-specific syntax (my setup doesn't have any ancient py2, only current python3).

   1. eng2sp = { "one":"uno", "two":"dos", "three":"tres" }
   2.
   3. # works in Python2, but not Python3
   4. # Python3 gives error ...
   5. # AttributeError: 'dict' object has no attribute 'has_key'
   6. #print( eng2sp.has_key( "one" ) ) # True
   7.
   8. # works with Python2 and Python3
   9. print( "one" in eng2sp ) # True
Comment 1 Douglas 2011-07-30 17:13:01 UTC
The following patch commands can lead you to successfull build even with current python (to bootstrap, you do also need to copy a lot of .libs/* from 3 different directories to /usr/lib/ at the build time):

# gio's 'gdbus-codegen' has a lot of ancient-python2-specific stuff, which is absolutely unacceptable in 2011;
# so let's update the code to current python implementation,
# and forget completely about using/supporting ancient python2:
sed -i "s/attrs\.has_key('name')/'name' in attrs/" ./gio/gdbus-codegen/parser.py 
sed -i "s/self\.doc_comment_params\.has_key(attrs\['name'])/attrs['name'] in self.doc_comment_params/" ./gio/gdbus-codegen/parser.py
sed -i "s/self\.doc_comment_params\.has_key('short_description')/'short_description' in self.doc_comment_params/" ./gio/gdbus-codegen/parser.py
sed -i "s/self\.doc_comment_params\.has_key('since')/'since' in self.doc_comment_params/" ./gio/gdbus-codegen/parser.py
sed -i "s/self\.expand_member_dict\.keys()/list(self.expand_member_dict.keys())/" ./gio/gdbus-codegen/codegen_docbook.py 
sed -i "s/self\.expand_iface_dict\.keys()/list(self.expand_iface_dict.keys())/" ./gio/gdbus-codegen/codegen_docbook.py
sed -i "s/self\.out = file/self.out = open/" ./gio/gdbus-codegen/codegen_docbook.py
sed -i "s/h = file(/h = open(/" ./gio/gdbus-codegen/codegen_main.py
sed -i "s/c = file(/c = open(/" ./gio/gdbus-codegen/codegen_main.py
sed -i "s/sort(cmp=/sort(/" ./gio/gdbus-codegen/codegen.py

They do fix:
1) using of 'has_key' instead of 'in';
2) wrong thoughts that keys() on dict does return a list;
3) 'open' instead of 'file';
4) ancient snake-2 only 'cpm=' inside sort().
Comment 2 Mantas Mikulėnas (grawity) 2011-11-10 19:22:10 UTC
Created attachment 201180 [details] [review]
a proper patch, with working version sort
Comment 3 Mantas Mikulėnas (grawity) 2011-11-10 19:41:20 UTC
Created attachment 201181 [details] [review]
one that works with older versions again (hopefully)

I've really got to start testing what I write - functools.cmp_to_key was only added in 2.7...
Comment 4 Simon Feltman 2012-09-29 08:41:24 UTC
A duplicated effort of the patch for this ticket was already applied to glib.

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