Recognise the ``@object.__new__`` decorator on a class definition
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
For the following code:
@object.__new__
class A:
...
class B:
...
reveal_type(A)
reveal_type(B)
mypy returns:
test.py:8: note: Revealed type is "def () -> test.A"
test.py:9: note: Revealed type is "def () -> test.B"
If you print instead of reveal_type it shows that:
<__main__.A object at 0x1081cfb50>
<class '__main__.B'>
Following screenshot shows that ``pyright` does recognise this.
Expected Behavior
Recognise that the @object.__new__ decorator turns A into an instance of A and set that as its type.
Actual Behavior
A is now inferred as Type[A].
Your Environment
- Mypy version used: 0.931
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.10
- Operating system and version: MacOS
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, das Beispiel in test.py mit mypy zu reproduzieren, und vergleiche die Ergebnisse von reveal_type mit dem erwarteten Laufzeitverhalten. Verfolge die bestehende Behandlung von Decorators, die auf Klassendefinitionen angewendet werden; als abgeschlossen gilt die Aufgabe, wenn @object.new dazu führt, dass A als Instanz von A inferiert wird, während B eine Klasse bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100