Wiki

Clone wiki

reimport / Ideas

Ideas and plans

Ideas and plans for reimport. Good and bad, fantasy and reality.

  • Allow classes to “opt-out” of rejiggering. Can protect from instances that have their methods swapped, but not their dictionary state. Modules should be less fragile, don’t need.

  • Allow classes a magic callback that allows them to modify each of their instances as they are rejiggered. Waiting for actual use case on this. Should the callback happen before, after, or instead of the normal rejigger?

  • Consider the effects of reload() running during the reimport transaction? Should reload builtin be hijacked during the reload process? Does it buy us anything?

  • Extension modules? I don't believe extensions can be reliably unloaded. Windows locks pyd files in use anyways, making them hard to overwrite. Could implement some sort of freeze,unload then allow the user to modify, then reload,thaw. Does not seem doable or cross platform in any way.

    • Could try to allow loading a new extension module as a replacement for an existing one? Would want niceties from a build system to give unique temporarily named extensions.
  • Propagation of module global constants? Does not seem possible. Module A does "from B import value1, value2, value3". Module B is reloaded. There is no way to push the new constant values from B into A.

    • With bytecode analysis, this style of import could be detected. This would require analyzing bytecode for all loaded modules. Would help in some cases, be bad in others. Do not want.
    • A simple version of this is already implemented for pushing changes from a reimported module up to it's parent package.
  • Classes with __slots__ present an interesting challenge. The classes can be modified, but the instances cannot. vars() will also not work on slotted instances. As long as the attributes of the slotted class do not change, things should work well enough. If the attributes do change, thinking of a way to create a dummy subclass of the slotted class that itself is not slotted. Then vars can be copied from the once instance to another. Then can swap references from old slotted objects to new non-slotted instance. Also note that setting __class__ fails on an instance that has a slotted class in its type hierarchy.

Updated