[Python-checkins] CVS: python/nondist/peps pep-0221.txt,1.1,1.2

Thomas Wouters python-dev@python.org
Sun, 20 Aug 2000 03:49:48 -0700


Update of /cvsroot/python/python/nondist/peps
In directory slayer.i.sourceforge.net:/tmp/cvs-serv22030

Modified Files:
	pep-0221.txt 
Log Message:

Make the PEP conform to reality, and add the suggestion to generalize the
expressions allowed after the 'as' clause. Change some markup, and mark it
as Accepted (which it is, since the change has been checked in.) Barry, this
should probably also change in the PEP Index PEP.



Index: pep-0221.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep-0221.txt,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** pep-0221.txt	2000/08/15 13:42:44	1.1
--- pep-0221.txt	2000/08/20 10:49:45	1.2
***************
*** 4,8 ****
  Owner: thomas@xs4all.net (Thomas Wouters)
  Python-Version: 2.0
! Status: Draft
  Created: 15-Aug-2000
  Type: Standard
--- 4,8 ----
  Owner: thomas@xs4all.net (Thomas Wouters)
  Python-Version: 2.0
! Status: Accepted
  Created: 15-Aug-2000
  Type: Standard
***************
*** 28,47 ****
      round-about way has to be used to achieve this:
  
!     import os
!     real_os = os
!     del os
      
      And similar for the `from ... import' statement:
      
!     from os import fdopen, exit, stat
!     os_fdopen = fdopen
!     os_stat = stat
!     del fdopen, stat
      
      The proposed syntax change would add an optional `as' clause to
      both these statements, as follows:
  
!     import os as real_os
!     from os import fdopen as os_fdopen, exit, stat as os_stat
      
      The `as' name is not intended to be a keyword, and some trickery
--- 28,47 ----
      round-about way has to be used to achieve this:
  
!         import os
!         real_os = os
!         del os
      
      And similar for the `from ... import' statement:
      
!         from os import fdopen, exit, stat
!         os_fdopen = fdopen
!         os_stat = stat
!         del fdopen, stat
      
      The proposed syntax change would add an optional `as' clause to
      both these statements, as follows:
  
!         import os as real_os
!         from os import fdopen as os_fdopen, exit, stat as os_stat
      
      The `as' name is not intended to be a keyword, and some trickery
***************
*** 49,93 ****
      more advanced parsers/tokenizers, however, this should not be a
      problem.
  
  
  Implementation details
  
!     A proposed implementation of this new clause can be found in the
!     SourceForge patch manager[XX]. The patch uses a NAME field in the
!     grammar rather than a bare string, to avoid the keyword issue. It
!     also introduces a new bytecode, IMPORT_FROM_AS, which loads an
!     object from a module and pushes it onto the stack, so it can be
!     stored by a normal STORE_NAME opcode.
!     
      The special case of `from module import *' remains a special case,
!     in that it cannot accomodate an `as' clause. Also, the current
!     implementation does not use IMPORT_FROM_AS for the old form of
!     from-import, even though it would make sense to do so. The reason
!     for this is that the current IMPORT_FROM bytecode loads objects
!     directly from a module into the local namespace, in one bytecode
!     operation, and also handles the special case of `*'. As a result
!     of moving to the IMPORT_FROM_AS bytecode, two things would happen:
!     
!     - Two bytecode operations would have to be performed, per symbol,
!       rather than one.
!       
!     - The names imported through `from-import' would be susceptible to
!       the `global' keyword, which they currently are not. This means
!       that `from-import' outside of the `*' special case behaves more
!       like the normal `import' statement, which already follows the
!       `global' keyword. It also means, however, that the `*' special
!       case is even more special, compared to the ordinary form of
!       `from-import'
! 
!     However, for consistency and for simplicity of implementation, it
!     is probably best to split off the special case entirely, making a
!     separate bytecode `IMPORT_ALL' that handles the special case of
!     `*', and handle all other forms of `from-import' the way the
!     proposed `IMPORT_FROM_AS' bytecode does.
! 
!     This dilemma does not apply to the normal `import' statement,
!     because this is alread split into two opcodes, a `LOAD_MODULE' and a
!     `STORE_NAME' opcode. Supporting the `import as' syntax is a slight
!     change to the compiler only.
  
  
--- 49,98 ----
      more advanced parsers/tokenizers, however, this should not be a
      problem.
+     
+     To avoid confusion, importing a submodule `as' another module is
+     not allowed. When importing a submodule in the normal way,
+     
+         import os.path
+         
+     The actual name stored locally is `os', not `path' (so that the
+     newly imported module can be referenced as `os.path'.) When
+     introducing the `as' keyword, it is unclear whether the `os'
+     module or the `path' sub-module should be stored `as' the
+     requested local name.
  
  
  Implementation details
  
!     This PEP has been accepted, and the suggested code change has been
!     checked in. The patch can still be found in the SourceForge patch
!     manager[1]. Currently, a NAME field is used in the grammar rather
!     than a bare string, to avoid the keyword issue. It introduces a
!     new bytecode, IMPORT_STAR, which performs the `from module import
!     *' behaviour, and changes the behaviour of the IMPORT_FROM
!     bytecode so that it loads the requested name (which is always a
!     single name) onto the stack, to be subsequently stored by a STORE
!     opcode.
! 
      The special case of `from module import *' remains a special case,
!     in that it cannot accomodate an `as' clause, and that no STORE
!     opcodes are generated; the objects imported are loaded directly
!     into the local namespace.
!     
!     An additional change to this syntax has also been suggested, to
!     generalize the expression given after the `as' clause. Rather than
!     a single name, it could be allowed to be any expression that
!     yields a valid l-value; anything that can be assigned to. The
!     change to accomodate this is minimal, as the patch proves[2], and
!     the resulting generalization allows a number of new constructs
!     that run completely parallel with other Python assignment
!     constructs.
! 
!         import sys as x['sys']
! 
!         from MyFastcPickle import Pickler as shelve.Pickler
!         
!         from sys import version_info as (maj, min, pl, relnam, relno)
!         
!         from sys import path as mypath[-1:]
  
  
***************
*** 101,104 ****
--- 106,112 ----
      [1]
  http://sourceforge.net/patch/?func=detailpatch&patch_id=101135&group_id=5470
+ 
+     [2]
+ http://sourceforge.net/patch/?func=detailpatch&patch_id=101234&group_id=5470