Read/write property does not work with "allow_interpreted_subclasses"
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
Code generated by mypyc crashes at run-time when accessing a read/write property of an interpreted subclass.
To Reproduce
The mypyc code:
#entity.py
from mypy_extensions import mypyc_attr
@mypyc_attr(allow_interpreted_subclasses=True)
class EntityBase:
def __init__(self) -> None:
self._name = 'hello'
@property
def name(self) -> str:
return self._name
@name.setter
def name(self, name: str):
self._name = name
def print_name_property(entity: EntityBase):
print(f'Property {type(entity)}: {entity.name}')
The driver code:
from reproducer import print_name_property, EntityBase
class EntitySubclass(EntityBase):
def __init__(self):
super().__init__()
def main():
entity_subclass = EntitySubclass()
print_name_property(entity_subclass)
if __name__ == '__main__':
main()
Expected Behavior
The code should print 'hello' regardless if the attribute is accessed directly or via property.
Actual Behavior
Program crashes, when calling print_name_property(entity_subclass):
Traceback (most recent call last):
File "/home/python/mypyc/reproducer.py", line 17, in <module>
main()
File "/home/python/mypyc/reproducer.py", line 13, in main
print_name_property(entity_subclass)
File "entity.py", line 20, in print_name_property
print(f'Property {type(entity)}: {entity.name}')
AttributeError: 'EntitySubclass' object has no attribute '__mypyc_setter__name'
Process finished with exit code 1
Your Environment
- Mypy version used: 1.4.1
- Python version used: 3.11.0
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
Inizia con la gestione generata da mypyc delle properties nelle classi contrassegnate con allow_interpreted_subclasses, usando il riproduttore EntityBase e EntitySubclass dell’issue. Esegui l’esempio con l’ambiente riportato e verifica che l’accesso a entity.name non generi più AttributeError e stampi l’output hello previsto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 45/100