[mypyc] property setter and deleter don't work with parameterized attributes
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug Report
mypyc fails to compile a class with a property setter and deleter and a weakref attribute.
To Reproduce
- Defined (in a file
foo.py) a classBarwith a property that has a setter and deleter and weakref attribute. - run
mypyc foo.py3.
e.g.
from __future__ import annotations
from typing import TypeVar, Generic
import weakref
T = TypeVar("T")
class Bar(Generic[T]):
_attr: weakref.ReferenceType[T] | None
def __init__(self) -> None:
self._attr = None
@property
def attr(self) -> T | None:
return self._attr() if self._attr is not None else None
@attr.setter
def attr(self, value: T) -> None:
self._attr = weakref.ref(value)
@attr.deleter
def attr(self) -> None:
self._attr = None
Actual Behavior
I get the following error:
File "mypyc/irbuild/classdef.py", line 87, in transform_class_def
File "mypyc/irbuild/classdef.py", line 200, in add_method
File "mypyc/irbuild/function.py", line 369, in handle_ext_method
File "mypyc/irbuild/function.py", line 312, in gen_func_item
File "mypyc/irbuild/function.py", line 351, in gen_func_ir
...: KeyError: <mypy.nodes.FuncDef object at 0x7f93d4876b80>
This error does not occur when setter and deleter are omitted.
Your Environment
- Mypy version used: 0.950
- Mypy command-line flags: N/A
- Mypy configuration options from
mypy.ini(and other config files): N/A - Python version used: 3.9
- Operating system and version: macOS Monterey, version 12.4
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci il fallimento con l’esempio foo.py, quindi traccia il percorso segnalato attraverso mypyc/irbuild/classdef.py e mypyc/irbuild/function.py. Aggiungi la copertura per un attributo parametrizzato con property setter e deleter e considera il problema completato quando mypyc foo.py lo compila senza il KeyError.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 42/100