Re: Unicode attributes of QObjects not raising AttributeError

Phil Thompson <[email protected]>
Newsgroups gmane.comp.python.pyqt-pykde
Message-ID <[email protected]>
On 22/06/2019 20:49, Arusekk wrote:
> 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

The second fix will be in tonight's snapshot.

Thanks,
Phil
_______________________________________________
PyQt mailing list    [email protected]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.