QJsonDocument fails with a confusing error

Phil Thompson phil at riverbankcomputing.com
Wed Jun 10 15:17:45 BST 2020


On 10/06/2020 08:35, Anton Yablokov wrote:
> Dear developers,
> 
> Consider the following piece of code:
> 
> from PyQt5.QtCore import QJsonDocument
> 
> json = {
>     "catalog": [
>         {
>             "version": None,
>         },
>     ]}QJsonDocument(json)
> 
> Under Python 3.6+ and PyQt514+ (haven't checked other versions), it 
> results
> in the following error at the last line:
> 
> TypeError: a value has type 'list' but 'QJsonValue' is expected
> 
> QJsonDocument clearly supports lists: QJsonDocument({'a': []}) works 
> fine.
> 
> As it turns out, the None value is the reason. Although the docs
> <https://doc.qt.io/qt-5/qjsondocument.html#JsonFormat-enum> clearly 
> show
> that QJsonDocument supports null values, None is not supported in
> PyQt5: QJsonDocument({'a':
> None}) results in
> 
> TypeError: a value has type 'NoneType' but 'QJsonValue' is expected.
> 
> Is it a bug that None is not translated as null? If not, the error 
> message
> should be more informative, at least.

More an omission rather than a bug. Fixed in tonight's snapshot.

Phil


More information about the PyQt mailing list