Reconciling pyqtProperty and mypy

Dmitri Bogomolov 4glitch at gmail.com
Wed Aug 19 10:15:38 BST 2020


Shouldn't the second method have a different name?

вт, 18 серп. 2020 о 21:55 Ben Green <ben.green at geckorobotics.com> пише:

> 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
>


-- 
;; -*- signature -*-
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20200819/72e91335/attachment-0001.htm>


More information about the PyQt mailing list