[PyQt] Fwd: QtProperty docstrings

Javier Santacruz López-Cepero jsl at taric.es
Mon Oct 26 08:44:58 GMT 2015


Hi Phil,


Thank you for the fix! :)

However, I've got to install PyQt 5.5.1 and got the following behaviour;
When repeating my previous example, I get indeed a docstring, but its
always the same and it comes from the standard docstring `str.__doc__`.

I've tried both Python 3 and Python 2 with PyQt5 5.5.1

    Python 3.5.0 (default, Sep 20 2015, 11:28:25)
    Python 2.7.10 (default, Sep  7 2015, 13:51:49)

    print(PYQT_VERSION_STR)
    5.5.1
    print(QT_VERSION_STR)
    5.5.1
    print(SIP_VERSION_STR)
    4.16.9

Now the tests:

    # Trying to get __doc__ from the property docstring

    from PyQt5.QtWidgets import QApplication, QWidget
    from PyQt5.QtCore import pyqtProperty

    app = QApplication([])

    class Widget(QWidget):
        def __init__(self):
            super(Widget, self).__init__()
        @pyqtProperty(str)
        def prop(self):
            """from docstring"""
            return ""

    w = Widget()

    print(w.prop.__doc__)

    str(object='') -> str
    str(bytes_or_buffer[, encoding[, errors]]) -> str

    Create a new string object from the given object. If encoding or
    errors is specified, then the object must expose a data buffer
    that will be decoded using the given encoding and error handler.
    Otherwise, returns the result of object.__str__() (if defined)
    or repr(object).
    encoding defaults to sys.getdefaultencoding().
    errors defaults to 'strict'.

    # Trying to get __doc__ from the doc parameter

    class Widget(QWidget):
        def __init__(self):
            super(Widget, self).__init__()
        @pyqtProperty(str, doc="from parameter")
        def prop(self):
            return ""

    w = Widget()

    print(w.prop.__doc__)

    str(object='') -> str
    str(bytes_or_buffer[, encoding[, errors]]) -> str

    Create a new string object from the given object. If encoding or
    errors is specified, then the object must expose a data buffer
    that will be decoded using the given encoding and error handler.
    Otherwise, returns the result of object.__str__() (if defined)
    or repr(object).
    encoding defaults to sys.getdefaultencoding().
    errors defaults to 'strict'.

    # Trying to change the property type

    class Widget(QWidget):
        def __init__(self):
            super(Widget, self).__init__()
        @pyqtProperty(object, doc="from parameter")
        def prop(self):
            return ""

    w = Widget()

    print(w.prop.__doc__)

    str(object='') -> str
    str(bytes_or_buffer[, encoding[, errors]]) -> str

    Create a new string object from the given object. If encoding or
    errors is specified, then the object must expose a data buffer
    that will be decoded using the given encoding and error handler.
    Otherwise, returns the result of object.__str__() (if defined)
    or repr(object).
    encoding defaults to sys.getdefaultencoding().
    errors defaults to 'strict'.

I would love to help with this, though It's not totally clear to me, from
searching the web, how a patch should be submitted or a pull request or any
other mean of collaboration.

Thank you.

Javier




2015-10-25 12:10 GMT+01:00 Phil Thompson <phil at riverbankcomputing.com>:

    On 8 Oct 2015, at 1:10 p.m., Javier Santacruz López-Cepero <jsl at taric.es>
wrote:
    >
    > Hello to all,
    >
    > I think I detected a strange behaviour with docstrings when using the
pyqtProperty decorator.
    > It does get the docstring from the doc pyqtProperty parameter but not
from the docstring itself:
    >
    >     from PyQt5 import QtCore, QtWidgets
    >
    >     class Test(QtWidgets.QWidget):
    >         @pyqtProperty(str)
    >         def data(self):
    >             """docstring"""
    >             return "result"
    >
    > When defining a property like this, the __doc__ attribute is not
initialized:
    >
    >
    >     In [11]: print(Test.data.__doc__)
    >     None
    >
    > But it does work when set directly from the doc parameter:
    >
    >
    >     from PyQt5 import QtCore, QtWidgets
    >
    >     class Test(QtWidgets.QWidget):
    >         @pyqtProperty(str, doc="docstring")
    >         def data(self):
    >             return "result"
    >
    >     In [13]: print(Test.data.__doc__)
    >     doctoring

    Should be fixed in tonight's snapshots.

    Thanks,
    Phil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20151026/2725f37b/attachment-0001.html>


More information about the PyQt mailing list