[Python-Dev] Re: [Import-sig] Re: Proposal for a modified import mechanism.

Jeremy Hylton jeremy@zope.com
Wed, 14 Nov 2001 13:14:39 -0500 (EST)


>>>>> "GW" == Greg Ward <gward@python.net> writes:

  GW> Nobody else has responded to this, so I should.  The above page
  GW> (just a paragraph, really) claims that "from foo import bar" is
  GW> bad because it binds the same object to two different names (or
  GW> rather, to the same name in two different namespace).

I this were a bad thing, we'd have to recommend that people not use
assignments. 

  GW> True enough, but it then claims this is a Bad Thing because
  GW> things can go wrong in the face of module reloading, or (aack!)
  GW> changes to function definitions at run-time.

  [discussion of various attempts to do a useful reload()]

  GW> If anyone has a solution to this, I'm all ears, but for now I'm
  GW> pretty well convinced that it cannot be done.

The current behavior is a natural consequence of the way references
work.  I don't think there's any sensible way to change it.  Even if
you change import to bind a name to a reference-to-a-module, such that
the reference was checked on each use and always refered to the most
recent copy of a module, it wouldn't be sufficient.  Each instance
that uses a class was a reference to the class itself, not the
class-in-the-current module.  The same pattern occurs for every
possible kind of reference.

I'm strongly opposed to changing import because it would create one
special case and that special case would cause confusion more than
anything. 

Jeremy