On 08/11/2015 18:01, Chris Angelico wrote:
On Mon, Nov 9, 2015 at 4:54 AM, BartC <b...@freeuk.com> wrote:
That would be true for locals as well. But as far as I can tell from the
CPython source code, byte-codes uses an index to represent a local, which
represents an entry into a linear table.

I can't quite see why that can't be done for global names and for attributes
too (ie. the names that follow a ".").

At compilation time, the set of local names is locked in permanently.
That's not true of any other namespace (except nonlocals, which are
still locals, just not yours). Attributes and global names (which are
attributes of the current module) can be added and removed
dynamically, so they can't be assigned to slots; attributes can even
be simulated via __getattr__ and __getattribute__.

Yes, that's yet another way that the language design makes things difficult (for those who want to streamline its implementation).

For most purposes, the set of attribute names that can follow a dot are limited and fixed, by the occurrences of such names in a source file. So they can be assigned a slot.

But then, you say that additional attributes, potentially millions of different ones, can be invented at runtime. Although I don't see how it can remove names that are part of the source code: if "A.B" is in the file, then surely "A" and "B" always have to be present in some table or other.

--
Bartc
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to