You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
mypy has some special casing to make pythons @property (and a few other decorators) work.
The easy solution would probably be to add a special case for @pyqtProperty.
Cleaner solutions would be to either somehow make it possible to annotate that a decorator creates a property (This could be problematic, as I don't know if existing type annotations can handle this) or write a mypy plugin. I only took a quick look at the plugin interface and think it should be possible to do this. The problem here would be that the plugin API is unstable (See #6617).
EDIT:
Looks like writing a plugin for this isn't that easy after all. There is a "get_class_decorator_hook", but no corresponding hook for methods and functions. If such hooks would be added writing a plugin would be possible.
Should the plugin hook I suggested in #9915 get added to mypy you could solve this using the following mypy plugin (function and class names subject to change):
Activity
[-]pyqtProperty setter always raise an error[/-][+]pyqtProperty setter always raises an error[/+]freundTech commentedon Jan 15, 2021
On the Qt mailing-list someone already posted these two links to the mypy source-code:
https://github.com/python/mypy/blob/v0.782/mypy/semanal.py#L964-L973
https://github.com/python/mypy/blob/v0.782/mypy/semanal.py#L842-L869
mypy has some special casing to make pythons
@property(and a few other decorators) work.The easy solution would probably be to add a special case for
@pyqtProperty.Cleaner solutions would be to either somehow make it possible to annotate that a decorator creates a property (This could be problematic, as I don't know if existing type annotations can handle this) or write a mypy plugin. I only took a quick look at the plugin interface and think it should be possible to do this. The problem here would be that the plugin API is unstable (See #6617).
EDIT:
Looks like writing a plugin for this isn't that easy after all. There is a "get_class_decorator_hook", but no corresponding hook for methods and functions. If such hooks would be added writing a plugin would be possible.
gvanrossum commentedon Jan 15, 2021
The way to do that without baking knowledge of qt into mypy is to write a mypy extension.
freundTech commentedon Jan 16, 2021
Should the plugin hook I suggested in #9915 get added to mypy you could solve this using the following mypy plugin (function and class names subject to change):
Resolve mypy issues in 'qml_utils.py'