[Python-Dev] 'import as' (original) (raw)
Thomas Wouters thomas@xs4all.net
Thu, 17 Aug 2000 23:19:42 +0200
- Previous message: [Python-Dev] Cookie.py module, and Web PEP
- Next message: [Python-Dev] 'import as'
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I have two remaining issues regarding the 'import as' statement, which I'm just about ready to commit. The first one is documentation: I have documentation patches, to the ref and the libdis sections, but I can't really test them :P I think they are fine, though, and they aren't really complicated. Should I upload a patch for them, so Fred or someone else can look at them, or just check them in ?
The other issue is the change in semantics for 'from-import'. Currently, 'IMPORT_FROM' is a single operation that retrieves a name (possible '*') from the module object at TOS, and stores it directly in the local namespace. This is contrary to 'import ', which pushes it onto the stack and uses a normal STORE operation to store it. It's also necessary for 'from ... import *', which can load any number of objects.
After the patch, 'IMPORT_FROM' is only used to load normal names, and a new opcode, 'IMPORT_STAR' (with no argument) is used for 'from module import '. 'IMPORT_FROM' pushes the result on the stack, instead of modifying the local namespace directly, so that it's possible to store it to a different name. This also means that a 'global' statement now has effect on objects 'imported from' a module, except those imported by ''.
I don't think that's a big issue. 'global' is not that heavily used, and old code mixing 'import from' and 'global' statements on the same identifier would not have been doing what the programmer intended. However, if it is a big issue, I can revert to an older version of the patch, that added a new bytecode to handle 'from x import y as z', and leave the bytecode for the currently valid cases unchanged. That would mean that only the '... as z' would be effected by 'global' statements.
-- Thomas Wouters <thomas@xs4all.net>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
- Previous message: [Python-Dev] Cookie.py module, and Web PEP
- Next message: [Python-Dev] 'import as'
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]