Plugin initialization hook
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con ClassDefContext y rastrea cómo se relaciona con BuildManager.parse_file() en mypy/build.py; después inspecciona lookup_fully_qualified() en mypy/semanal.py y la colección self.modules. El issue estará completo cuando un plugin tenga una forma compatible de hacer que los módulos de aplicaciones Django configurados estén disponibles para resolver referencias a modelos.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- django, python
- Área
- devtools
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 30/100