Unicode attributes of QObjects not raising AttributeError
Arusekk <[email protected]>
| Newsgroups | gmane.comp.python.pyqt-pykde |
|---|---|
| Message-ID | <[email protected]> |
Hi!
I just encountered a misguiding error message while using unicode identifiers
that cost me several hours of debugging.
The code to reproduce is as easy as:
>>> from PyQt5.QtCore import QObject
>>> QObject().ą
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character '\u0105'
in position 0: ordinal not in range(128)
Whereas the expected behaviour would be like here:
>>> "".ą
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'ą'
The possible solutions to it are (fix1, possibly having negative impact
elsewhere):
--- sip/QtCore/QtCoremod.sip 2019-05-06 11:03:34.000000000 +0200
+++ sip/QtCore/QtCoremod.sip.fix0 2019-06-22 20:03:35.190091685 +0200
@@ -64,7 +64,7 @@
%Plugin PyQt5
%If (Py_v3)
-%DefaultEncoding "ASCII"
+%DefaultEncoding "UTF-8"
%End
%If (!Py_v3)
Or the following (fix2, only changing QObject's getattr):
--- sip/QtCore/qobject.sip 2019-05-06 11:03:34.000000000 +0200
+++ sip/QtCore/qobject.sip.fix2 2019-06-22 20:10:16.075104723 +0200
@@ -434,7 +434,7 @@
return qpycore_pyqtconfigure(sipSelf, sipArgs, sipKwds);
%End
- SIP_PYOBJECT __getattr__(const char *name) const;
+ SIP_PYOBJECT __getattr__(const char *name /Encoding="UTF-8"/) const;
%MethodCode
sipRes = qpycore_qobject_getattr(sipCpp, sipSelf, a0);
%End
--
Arusekk
_______________________________________________
PyQt mailing list [email protected]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEaTU5Qye/OuVpjOkDYvWiou5ZCKwFAl0OhlYACgkQYvWiou5Z CKwZxRAAlmjQL7bk5QrcrGnWt6OYq7fEHvNSzef8yUq7LgfgsQrD+qI321A7XmZ4 p2EOEsYU03aQBCacJ5pgdp5CD6y4JlJFrEWAPYoJhDfLDFM3v8CbcK0IpnvPd0Ch NHhtrjSYRb1ao6TO2Te6IgT2nhYSlcSE1WW1hbKRLDHMP6Plg6uVpPXMJbp0Z0iQ +m9QkPYYImG0TS5Z7/pxa/88vI1lKboGgBnn3G0qv5a0bQfUkPOz8sVS73F8QeLK V+9+M+vpVu9SqzB6RXYkI+oo2hzTwseTpa2ExQn4by2wIzyDZCO891l0vSC7SCon jzQTeOZYcJuGgKV3kObiVFPjSfxa5ohn69xRtB80SvtDdM3dAXPlxVD5t4pHa7gz NvsyVMbTjWU4HLnWM5fhT3jljEs1NPlgqRIBnyk1CwgRJoPwF5O0exWB20mYmZ8+ egsbVA/J6UQ/O4AdpZej2DDFtW1aTOt2mCTeAe5T8OHA3Pfu0ukAgfVfiblduDbz Bx3jhMy4PgMwi63MzRrao+gqdxLlH45jE3jZszaOZlMEDJZ+ISYhDSUn1lDz/mri cJ7BFKd6tPo9klBLOdyHL83izfRhqnZp1NsACIyCkPjtbyKMCGvet2BacoC+FLzd dvVykzbj9i3A4u9jyU8aW+lhcbNaZaKv+W4FrFlAegj08QzE3oo= =EvLA -----END PGP SIGNATURE-----