Reconciling pyqtProperty and mypy

Ben Green ben.green at geckorobotics.com
Tue Aug 18 19:54:14 BST 2020


Hello,

I'm using pyqtProperty a lot, and mypy doesn't seem to play nicely with it.
When defining the setter, it gives a "name already defined" error. Also,
since the type is "Callable[..., Any]", instead of the actual type of the
property, references to that property can give errors.

For example:

class Foo(QObject):
    @pyqtProperty(QAbstractSeries)
    def series(self) -> QAbstractSeries:
        return self._series

    @series.setter  # mypy error here: Name 'series' already defined on
line x
    def series(self, val):
        self._series = val

    def do_something(self):
        self.series.replace([])  # mypy error here: "Callable[..., Any]"
has no attribute "replace"

Is there any way to reconcile these so I don't have to put in "type:
ignore" comments all over the place?

-- 
Ben Green  |  Software Engineer I

*GeckoRobotics* | geckorobotics.com
<http://www.geckorobotics.com/?utm_source=signature&utm_medium=email&utm_campaign=signature>

*o:* 412.407.2444  *m:* 484.895.5793
*e:* ben.green at geckorobotics.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20200818/2a6abaa9/attachment.htm>


More information about the PyQt mailing list