[New-bugs-announce] [issue21087] imp.frozen_init() incorrectly removes module during reload

Eric Snow report at bugs.python.org
Fri Mar 28 19:30:43 CET 2014


New submission from Eric Snow:

While reviewing code[1] for issue 20942, I noticed that when someone uses imp.frozen_init[2], the module is removed from sys.modules in some error cases.  However, this should not be done when the module already exists (e.g. reload).

As Brett pointed out in his reply to my comment in the review, frozen modules really shouldn't be reloaded, so this isn't something we necessarily need to worry about.  I.E. it's a rare corner case.  I brought it up because there's a comment in PyImport_ExecCodeModuleObject() implying a reload-related use-case.

We have 3 options:

1. don't worry about it (imp.frozen_init() is deprecated, etc.),
2. stop calling remove_module() in the reload case (i.e. be accommodating),
3. disallow reloading frozen modules (and remove that comment from import.c).

I'll shy away from #3 (consenting adults, etc.).  If someone felt like it they could work on #2, but keep in mind that there may be other reload-unfriendly code in this code path that would need adjusting if we wanted to really accommodate the use case.  I'm not convinced it's worth the trouble.

If anyone else agrees, feel free to close this issue.

[1] http://bugs.python.org/review/20942/#msg4
[2] really, anything that directly or indirectly uses PyImport_ExecCodeModuleObject() (or module_dict_for_exec() from #20942) is impacted.  In addition to imp.frozen_init(), that includes PyImport_ImportFrozenModule and PyImport_ImportFrozenModuleObject

----------
components: Library (Lib)
messages: 215063
nosy: brett.cannon, eric.snow, ncoghlan
priority: low
severity: normal
stage: test needed
status: open
title: imp.frozen_init() incorrectly removes module during reload
type: behavior
versions: Python 3.4, Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21087>
_______________________________________


More information about the New-bugs-announce mailing list