Using QDebug for __repr__?

Florian Bruhin me at the-compiler.org
Mon May 2 19:45:33 BST 2022


Hi,

PyQt seems to have hand-written __repr__ implementations for a handful
of types:

QtGui/qgenericmatrix.sip
QtGui/qvectornd.sip
QtGui/qmatrix4x4.sip
QtGui/qquaternion.sip
QtCore/qdatetime.sip
QtCore/qregularexpression.sip
QtCore/qline.sip
QtCore/qsize.sip
QtCore/qpoint.sip
QtCore/qbytearray.sip
QtCore/quuid.sip
QtCore/qrect.sip
QtCore/qurl.sip

PySide takes a different approach there, by using QDebug writing to a
QBuffer and then returning that:
https://doc.qt.io/qt-6/qdebug.html

This often results in it having much more descriptive __repr__'s, e.g.:

    >>> from PySide6.QtGui import QAction, QGuiApplication
    >>> app = QGuiApplication([])
    >>> QAction()
    <PySide6.QtGui.QAction(0x55c428114b50 text="" menuRole=TextHeuristicRole enabled=true visible=true) at 0x7f09becb1a00>

vs.

    <PyQt6.QtGui.QAction object at 0x7f09beccda20>

Perhaps PyQt6 could do something similar too?

Thanks,
Florian

-- 
            me at the-compiler.org | https://www.qutebrowser.org 
       https://bruhin.software/ | https://github.com/sponsors/The-Compiler/
       GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
             I love long mails! | https://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20220502/c7bac3b4/attachment.sig>


More information about the PyQt mailing list