python / python/mypy

pyqtProperty setter always raises an error

Open
#9,911 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-descriptors
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

It seems that Mypy is not enjoying pyqtProperty setters. Someone already asked on the Qt mailing-list.

To Reproduce

from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal


class FeatureModel(QObject):

    stateChanged = pyqtSignal()

    def __init__(self, enabled: bool, /) -> None:
        super().__init__()
        self._enabled = enabled

    @pyqtProperty(bool, notify=stateChanged)
    def enabled(self):
        return self._enabled

    @enabled.setter
    def enabled(self, enabled):
        self._enabled = enabled
        self.stateChanged.emit()

Expected Behavior

Mypy should be happy.

Actual Behavior

$ python -m mypy file.py
file.py:16: error: Name 'enabled' already defined on line 12
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 0.790
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.8.6
  • Operating system and version: macOS Big Sur (arm64) and Windows 10.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided file.py reproducer and run python -m mypy file.py to confirm the duplicate-definition error. Then inspect how mypy handles pyqtProperty and its .setter form; done means the example type-checks without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.