Python 2 namespace change? (was Re: [Python-Dev] Changing existing class instances)

Guido van Rossum guido@CNRI.Reston.VA.US
Thu, 20 Jan 2000 10:45:40 -0500


> I've suggested this to Guido in the past.  His 
> reasonable response is that this would be too big a 
> change for Python 1. Maybe this is something to consider
> for Python 2?

Note: from now on the new name for Python 2 is Python 3000. :-)

> The basic idea (borrowed from Smalltalk) is to have a kind 
> of dictionary that is a collection of "association" 
> objects.  An association object is simply a pairing of a 
> name with a value. Association objects can be shared among 
> multiple namespaces.

I've never liked this very much, mostly because it breaks simplicity:
the idea that a namespace is a mapping from names to values
(e.g. {"limit": 100, "doit": <function...>, ...}) is beautifully
simple, while the idea of inserting an extra level of indirection, no
matter how powerful, is much murkier.

There's also the huge change in semantics, as you point out;
currently,

	from foo import bar

has the same effect (on bar anyway) as

	import foo
	bar = foo.bar		# i.e. copying an object reference
	del foo

while under your proposal it would be more akin to changing all
references to bar to become references to foo.bar.

Of course that's what the moral equivalent of "from ... import ..."
does in most other languages anyway, so we might consider this for
Python 3000; however it would break a considerable amount of old code,
I think.  (Not to mention brain and book breakage. :-)

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