python / python/mypy

"Name already defined" for PySide6 Property

Open
#17,406 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Bug Report

When using PySide6.QtCore.Property, I get a [no-redef] error on the property setter that says it's already defined. If this is a problem that PySide6 needs to fix I will create a bug report there instead.

To Reproduce

from PySide6 import QtCore, QtWidgets

class MyWidget(QtWidgets.QWidget):
    myNum: int = 0
    
    @QtCore.Property(int)
    def myProperty(self) -> int:
        return self.myNum
    
    @myProperty.setter
    def myProperty(self, value: int) -> None:
        self.myNum = value

Expected Behavior

If you use a python property, it gives no errors. Using QtCore.Property should also give no errors.

Actual Behavior

test.py:10: error: Name "myProperty" already defined on line 6  [no-redef]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.10.0
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.11.9
  • PySide6 version used: 6.7.1
    Link to PySide6: https://doc.qt.io/qtforpython-6/

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

The reproduction is in test.py, where the QtCore.Property getter and setter trigger [no-redef]. Start by running mypy on that snippet and inspect how stacked property decorators are handled. Done means the PySide6 pattern no longer reports this false positive while ordinary Python properties remain unaffected.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.