python / python/mypy

More ideas about plugin system

Abierto
#5,905 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

needs discussion priority-1-normal topic-plugins
Lenguaje dominante
Python
Estrellas
20.6k
Forks
3.3k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

After some time spent on writing SQLAlchemy plugin and a discussion with @JukkaL here are some comments and ideas about our plugin :

  • Currently, member signature hook is not called on __init__ and __new__. Current workaround is to use function hook, but it is still painful. The solution would require moving type_object_type() (and maybe a bunch of other helpers) from checkmember.py to a separate module (which is probably a good idea on its own). We can also move some helpers from checker.py related to type objects to the same module.

  • During semantic analysis types of expressions are not known. This poses a problem in attrs and even more in SQLAlchemy: When generating an __init__ method for a model, plugin needs to figure out what is a type of attributes from definitions like name = Column(String(40)). Currently I do this using some heuristics that works in 95% of cases (and so does attrs plugin), but a better solution is probably to just store names of "magic" classes (SQLAlchemy models, dataclasses etc.) in the plugin state, add a dummy __init__ to symbol table, and defer figuring out actual type to the method signature hook that is called in type checking (depends on fixing previous bullet).

  • It is better to move calling semantic analysis hooks to the very end, or (probably even better) just allow them to defer current target (but this is currently not possible).

  • We should not allow most type operations in semantic analysis hooks (we can't enforce it, but should at least document it clearly). Some operations are still OK (like map_instance_to_supertype() or erase_type()).

  • The type checking hooks should also be able to defer current target using a special return value or an exception (e.g. __init__ signature hook in the SQLAlchemy example above if one would use a user-defined type in an import cycle).

Probably, most (or all) of decisions should be made after the upcoming semanal.py refactoring.

(Also function hook is inconvenient, but @gvanrossum already mentioned this in https://github.com/python/mypy/issues/5409 that has a bunch of good ideas about improving plugin system.)

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza leyendo la lógica relacionada con los plugins en checkmember.py y checker.py; después, revisa la refactorización prevista de semanal.py y la issue #5409 vinculada. La issue plantea varias preguntas de diseño sobre hooks de análisis semántico y comprobación de tipos, pero no define un único cambio ni un criterio concreto de finalización.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
compilers
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.