Improvements Related to Namespace Package Portions for PathEntryFinders
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 36k
- Merge moyen
- 1 j 9 h
- PR mergées (30 j)
- 558
Description
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
Nonethen the portion is ignored (not even a warning is set)
find_spec()returns aModuleSpecwithloaderset toNoneandsubmodule_search_locationsset 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
- do nothing
- use a dedicated singleton instead of None
- use a dedicated ModuleSpec subclass (e.g. NamespacePackagePortionSpec)
- use a dedicated ModuleSpec-compatible class (e.g. NamespacePackagePortionSpec)
explicitly deal with unexpectedly set data
(This is basically just if spec.origin is set.)
- do nothing
- emit a warning
- fail
explicitly deal with spec.loader_state
- do nothing
- emit a warning
- fail
- preserve the info on the spec of the combined namespace package
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par l’entrée de documentation de PathEntryFinder.find_spec() et par la section language-reference namespace-packages liée dans l’issue. Lisez le contexte de PEP 420 et de PEP 451, puis examinez les alternatives non résolues pour identifier les portions et gérer les données Spec supplémentaires. Le travail est considéré comme terminé lorsque le comportement choisi par le projet est clairement documenté et que toute modification de comportement associée a été convenue avant l’implémentation.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- documentation, tooling
- Type d'issue
- Documentation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 25/100