Message 404512 - Python tracker (original) (raw)

On Wed, Oct 20, 2021 at 11:11 AM Barry A. Warsaw <report@bugs.python.org> wrote:

Maybe we should relax the restriction on module.spec.parent so that it's writeable just like module.package.

Hmm, I hadn't realized package is used in import(). That makes things messier.

Regardless, I expect the primary reason package is writable is because modules have never had any read-only attrs.

The more important question now is, when is package ever modified? I can think of 2 cases:

  1. legacy (pre-451) importers set it when they load the module
  2. someone wants to customize the import system without writing an importer

With the latter, specifically they are trying to change how the module is reloaded or submodules are imported. In that case there should probably be an explicit way to do so without having to hack the import machinery.

My only concern with any support/encouragement for modifying the spec after import is it results in less confidence about how the module was imported originally.