Plugin initialization hook
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
I have already asked about augmenting AST with new nodes in the initialization hook for plugins in
https://github.com/python/mypy/issues/5910
I was able to figure it out with get_back_class_hook and dummy base class like here
https://github.com/mkurnikov/django-stubs/blob/master/django-stubs/conf/__init__.pyi#L7
There's another use case.
In Django there's an INSTALLED_APPS setting:
INSTALLED_APPS = ('app1', 'app2')
which specifies apps to use to retrieve model definitions for database schema (using models.py files).
Those could be used in the model definition code like this
from django.db import models
class User(models.Model):
member = models.ForeignKey(to='app1.Model1')
In plugin, I can parse to= value, figure out the right type of a model, and set as return type of __get__ to have a proper value for member attribute.
For that I need to use lookup_fully_qualified
https://github.com/python/mypy/blob/master/mypy/semanal.py#L3453
and this requires module to be present in the self.modules list.
I need to create new MypyFile instances to populate that attr myself, but parse_file() method belongs to BuildManager class
https://github.com/python/mypy/blob/master/mypy/build.py#L648
and I wasn't able to find how to access it from the ClassDefContext.
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 ClassDefContext e traccia la relazione con BuildManager.parse_file() in mypy/build.py, quindi esamina lookup_fully_qualified() in mypy/semanal.py e la raccolta self.modules. L’issue è completa quando un plugin dispone di un modo supportato per rendere disponibili i moduli delle app Django configurati per la risoluzione dei riferimenti ai modelli.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- django, python
- Ambito
- devtools
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 30/100