[Python-Dev] Namespaces

Aahz aahz@pythoncraft.com
Mon, 1 Apr 2002 16:22:32 -0500


On Mon, Apr 01, 2002, Jeremy Hylton wrote:
>
> I think it's fairly common for people to talk about an object's
> attributes as its namespace.  The language reference does not call
> this a namespace.  In fact, the lang ref doesn't define namespace and
> often uses other words to discuss naming: names, blocks, scopes,
> environment.
> 
> Perhaps namespace is too fuzzy and we should introduce a precise term
> to talk about the attribute "namespace" of an object.

Actually, namespace seems fine and clear to me; what IMO needs
clarification is explicit namespaces (i.e. through object references)
versus implicit/execution-based namespaces (builtin/global/local).  

Which reminds me of another annoyance in that "global" is strictly
speaking "module global".

> The lang ref does say that the namespace of a class definition becomes
> the attribute dictionary of the class.  So "attribute dictionary"
> seems to be preferred to "object namespace" <0.5 wink>.

Yeah, those sound synonymous to me, but four syllables beats seven when
I'm teaching.  ;-)

> Aahz:
>   A> It seems pretty clear to me that f.permissions does not live in
>   A> the local/global/builtins namespace, but it sure lives in f's
>   A> namespace.  Because attributes are names like any other name and
>   A> can be bound to any Python object, I think it lends crucial
>   A> orthogonality to say that attributes live in object namespace.
> 
> Some people will be confused that a function f has two namespaces --
> the namespace for its code object and the namespace for its
> attributes.  This reinforces my sense that we shouldn't use the term
> namespace when we are trying to be precise.  (Or that we need a
> precise definition of namespace and a clear way to disambiguate the
> two kinds of namespaces assocaited with a function.)

I'm fine with "local scope" and "object attributes" to disambiguate
them; I just think it's important that people understand that a name is
a name is a name, and all names live in *some* namespace.

> I'd also like to observe that the language reference doesn't say
> anything about how attributes of objects are resolved.  The tutorial
> says a bit in the chapter on classes, but none of this made it to the
> language reference.
> 
> It would be nice to flesh out these issues in the reference manual.

Well, once we've got this hashed out, it's a SMOW.  ;-)
-- 
Aahz (aahz@pythoncraft.com)           <*>         http://www.pythoncraft.com/

Why is this newsgroup different from all other newsgroups?