Bug 333683

Summary: PyKDE4 KDialog.None is illegal syntax for python3
Product: [Developer tools] bindings Reporter: Wolfgang Rohdewald <wolfgang>
Component: pykdeAssignee: kde-bindings
Status: RESOLVED UNMAINTAINED    
Severity: normal CC: flying-sheep, rakuco
Priority: NOR    
Version: 4.13.0   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed In:

Description Wolfgang Rohdewald 2014-04-21 09:50:35 UTC
as the summary says. In python3, None is illegal for user defined attributes. Please define a new name like NoButton for both python2-pykde4 and python3-pykde4 (and KF5 of course), otherwise it is more difficult to write portable python code.

See https://docs.python.org/3.2/library/constants.html

actually this was illegal even with Python2.7, but it seems its C bindings did not enforce that, letting pykde4 get through with that bug:

https://docs.python.org/2.7/library/constants.html

Please check if there are more such definitions for constants None, False, True

This fails with python 3.4.0:

i5:[Exit 1 (SIGHUP)]~/vpn/kajongg/src (master) cat xx.py ; python3 xx.py
from PyKDE4.kdeui import KDialog
# print(KDialog.Default) this works as expected
print(KDialog.None) # this fails with a syntax error

  File "xx.py", line 3
    print(KDialog.None) # this fails with a syntax error
                     ^
SyntaxError: invalid syntax
Comment 1 Raphael Kubo da Costa 2014-07-29 17:23:55 UTC
Isn't this an upstream issue? I get the same thing with PyQt4 and Python 3 if I try to access QAbstractPrintDialog::None as QAbstractPrintDialog.None.
Comment 2 Philipp A. 2014-07-30 11:00:04 UTC
Ah, so the symbol is actually exposed by a Qt superclass?

Yeah, then this is an upstream issue.

A workaround would be getattr(KDialog, 'None'), i guess.
Comment 3 Raphael Kubo da Costa 2014-07-30 11:06:16 UTC
In KDialog's case, the symbol comes from KDialog itself. My point is that PyQt has the same problem with enums in Qt that have "None" as one of their values.
Comment 4 Philipp A. 2014-07-30 11:30:35 UTC
Maybe the best idea would be to make SIP/DIP automatically create a “<keyword>_” property when encountering a python keyword?

because the same problem (but more visibly) also existed for exec() on python 2, which is why PyQt has an exec_() alias for it.

so something like:

for cpp_fieldname in ...:
    field_proxy = ...
    if cpp_fieldname in python_keywords:
        setattr(current_python_class, cpp_fieldname + '_', field_proxy)
    setattr(current_python_class, cpp_fieldname, field_proxy)
Comment 5 Andrew Crouthamel 2018-11-12 02:56:03 UTC
Dear Bug Submitter,

This bug has been stagnant for a long time. Could you help us out and re-test if the bug is valid in the latest version? I am setting the status to NEEDSINFO pending your response, please change the Status back to REPORTED when you respond.

Thank you for helping us make KDE software even better for everyone!
Comment 6 Andrew Crouthamel 2018-11-17 05:28:12 UTC
Hello, unfortunately this bug is being closed as unmaintained, per request of einar77.