Eric Snow <ericsnowcurren...@gmail.com> added the comment:

On Wed, Oct 20, 2021 at 11:11 AM Barry A. Warsaw <rep...@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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue45540>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to