[Python-Dev] Re: [Python-checkins] CVS: python/dist/src/Misc NEWS,1.108,1.109

Guido van Rossum guido@digicool.com
Wed, 31 Jan 2001 11:23:37 -0500

> >> Using global on an import name is currently ignored by Jython because
> >> the name assignment is done by the runtime, not the compiler.

> >So it's impossible to do, in Jython, something like:
> >
> >def fillme():
> >    global me
> >    import me
> >
> >but it is possible to do:
> >
> >def fillme():
> >    global me
> >    import me as _me
> >    me = _me
> >
> >?

[Finn again]
> Yes, only the second example will make a global variable.
> > I have to say I don't like that; we're always claiming 'import' (and
> >'def' and 'class' for that matter) are 'just another way of writing
> >assignment'. All these special cases break that.
> I don't like it either, I was only reported what jython currently does.
> The current design used by Jython does lend itself directly towards a
> solution, but I don't see anything that makes it impossible to solve.

Tentatively, I'd say that this should be documented as a Jython
difference and Jython should strive to fix this.  So I see no good
reason to rule it out in CPython.

That doesn't mean I like Thomas's example!  It should probably be
redesigned along the lines of

    def fillme():
	import me
	return me

    me = fillme()

to avoid needing side effects on globals.

--Guido van Rossum (home page: http://www.python.org/~guido/)