Improvements Related to Namespace Package Portions for PathEntryFinders

Abierto
#92,896 8 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Documentación
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python

Línea de trabajo

Comienza con la entrada de documentación de PathEntryFinder.find_spec() y la sección language-reference namespace-packages enlazada en el issue. Lee el contexto de PEP 420 y PEP 451, y después revisa las alternativas aún no resueltas para identificar las partes y gestionar datos adicionales de Spec. Se considera terminado cuando el comportamiento elegido por el proyecto está documentado con claridad y cualquier cambio de comportamiento relacionado se ha acordado antes de la implementación.

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

Descripción

interpreter-core topic-importlib type-feature

tl;dr there are some oddities we should consider addressing with namespace package portions coming from path entry finders. It probably isn't worth bothering though (except for the docs fixes).


PEP 420 added (implicit) namespace packages. At that time, and since then, namespace packages (and portions) have gotten special-casing throughout the import machinery. Generally, we treat them like normal modules (or specs) even though certain characteristics don't apply. This isn't a problem generally because namespace packages aren't that common (and because, I expect, only builtin importers ever deal with them). However, there are a few things that it might be worth addressing.

PEP 451 introduced ModuleSpec, etc. PathEntryFinder.find_spec() as the replacement for PathEntryFinder.find_loader(), with some notable differences:

  • find_loader() returns (loader, portion)
    • the interpretation of this value is clearly documented
    • the finder can't provide any other possible information
    • if the returned loader is not None then the portion is ignored (not even a warning is set)
  • find_spec() returns a ModuleSpec with loader set to None and submodule_search_locations set to the portion
    • the interpretation of this value for portions is not clearly documented anywhere
    • the path entry finder may set addition info on the spec (e.g. loader_state) but it is all ignored (not even a warning if set)

In both cases, the language reference is not clear about how to identify namespace package portions from a path entry finder.

What to Do?

  • update the PathEntryFinder.find_spec() docs entry
  • (a weak maybe) add the details to the language reference
  • (maybe) be more explicit when returning a namespace package portion
  • (maybe) strictly disallow (or warn) for extraneous information tied to a portion
explicitly identify namespace package portions
  1. do nothing
  2. use a dedicated singleton instead of None
  3. use a dedicated ModuleSpec subclass (e.g. NamespacePackagePortionSpec)
  4. use a dedicated ModuleSpec-compatible class (e.g. NamespacePackagePortionSpec)
explicitly deal with unexpectedly set data

(This is basically just if spec.origin is set.)

  1. do nothing
  2. emit a warning
  3. fail
explicitly deal with spec.loader_state
  1. do nothing
  2. emit a warning
  3. fail
  4. preserve the info on the spec of the combined namespace package
Lenguaje dominante
Python
Estrellas
77.2k
Forks
36k
Merge medio
1 d 9 h
PR fusionados (30 d)
558

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.

Más de python/cpython

Todos los issues de python/cpython

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.