python / python/cpython

Non-package module loaded from ModInfo object retains __path__ from previously loaded package.

Offen
#97,694 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

type-bug
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
36k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Bug report

Assume you have two separate modules with the same name. One is a package, one is not.

Use pkgutil.itermodules to get a ModuleInfo object for the package, then load the it using find_module and load_module. This object has a __path__ object with the location of package, as expected.

Next, do the same for the non-package module. The resulting module object should have no __path__ attribute, but instead it has one with the location of the package opened previously.

This can be replicated with a structure such as \module\submodule\submodule.py, using \module and \module\submodule as the arguments for the two calls to pkgutil.itermodules.

Your environment

  • CPython versions tested on: 3.10.7, 3.11.0rc2
  • Operating system and architecture: Windows 10

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Reproduziere das Verhalten mit den beiden im Issue beschriebenen Modul-Layouts, wobei du pkgutil.itermodules gefolgt von find_module und load_module verwendest. Vergleiche die Paket- und Nicht-Paket-Modulobjekte; abgeschlossen ist die Aufgabe, wenn das Nicht-Paket-Modul nicht länger ein path vom zuvor geladenen Paket beibehält.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
backend
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.