Improvements Related to Namespace Package Portions for PathEntryFinders

Aperta
#92,896 8 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Documentazione
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python

Direzione di ricerca

Inizia dalla voce di documentazione di PathEntryFinder.find_spec() e dalla sezione language-reference namespace-packages collegata nell’issue. Leggi il contesto di PEP 420 e PEP 451, quindi esamina le alternative ancora irrisolte per identificare le porzioni e gestire i dati Spec aggiuntivi. Il lavoro è completo quando il comportamento scelto dal progetto è documentato chiaramente e ogni modifica comportamentale correlata è stata concordata prima dell’implementazione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
Python
Stelle
77.2k
Fork
36k
Merge medio
1g 9h
PR unite (30g)
558

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python/cpython

Tutte le issue di python/cpython

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.