python/nondist/peps pep-0328.txt,1.5,1.6

Update of /cvsroot/python/python/nondist/peps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13223 Modified Files: pep-0328.txt Log Message: upadte from Aahz Index: pep-0328.txt =================================================================== RCS file: /cvsroot/python/python/nondist/peps/pep-0328.txt,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** pep-0328.txt 6 Apr 2004 13:09:14 -0000 1.5 --- pep-0328.txt 2 May 2004 16:32:32 -0000 1.6 *************** *** 42,49 **** You may use relative imports freely. In Python 2.5, any ``import`` ! statement that results in an intra-package import will generate a ! ``PendingDeprecation`` warning (this also applies to ``from <> import`` ! that fails to use the relative import syntax). In Python 2.6, ``import`` ! will always be an absolute import. --- 42,50 ---- You may use relative imports freely. In Python 2.5, any ``import`` ! statement that results in an intra-package import will raise ! ``DeprecationWarning`` (this also applies to ``from <> import`` that ! fails to use the relative import syntax). In Python 2.6, ``import`` will ! always be an absolute import (and the ``__future__`` directive will no ! longer be needed). *************** *** 72,76 **** LEFT, DISABLED, NORMAL, RIDGE, END) ! This part of the proposal already has BDFL approval. --- 73,77 ---- LEFT, DISABLED, NORMAL, RIDGE, END) ! This part of the proposal had BDFL approval from the beginning. *************** *** 78,82 **** ============================== ! In current Python, if you're reading a module located inside a package, it is not clear whether :: --- 79,83 ---- ============================== ! In Python 2.3 and earlier, if you're reading a module located inside a package, it is not clear whether :: *************** *** 84,102 **** refers to a top-level module or to another module inside the package. ! Let's say today it refers to a module internal to the package. Then ! tomorrow, the standard library decides to add its own foo package that ! you'd like to use. You can't without renaming your internal module. ! To resolve these ambiguities, it is proposed that ``foo`` will always be a ! module or package reachable from ``sys.path``. Because this represents a change in semantics, absolute imports will ! be optional in Python 2.4 through the use of :: from __future__ import absolute_import ! This PEP will be updated when it is decided to make absolute imports ! the default, probably Python 2.5 or 2.6. ! ! This part of the proposal already has BDFL approval. --- 85,107 ---- refers to a top-level module or to another module inside the package. ! As Python's library expands, more and more existing package internal ! modules suddenly shadow standard library modules by accident. It's a ! particularly difficult problem inside packages because there's no way to ! specify which module is meant. To resolve the ambiguity, it is proposed ! that ``foo`` will always be a module or package reachable from ! ``sys.path``. This is called an absolute import. ! ! The python-dev community chose absolute imports as the default because ! they're the more common use case and because absolute imports can provide ! all the functionality of relative (intra-package) imports -- albeit at ! the cost of difficulty when renaming package pieces higher up in the ! hierarchy or when moving one package inside another. Because this represents a change in semantics, absolute imports will ! be optional in Python 2.4 and 2.5 through the use of :: from __future__ import absolute_import ! This part of the proposal had BDFL approval from the beginning. *************** *** 208,227 **** Guido's Decision ! ---------------- ! Guido has Pronounced [1]_ that relative imports will use leading dots, ! one per level of parent. Further discussion led to the following ! clarification of the semantics. Given a package layout:: ! package ! subpackage1 ! moduleX ! moduleY ! subpackage2 ! moduleZ ! moduleA ! Assuming that the current file is ``moduleX.py``, following are correct ! usages of the new syntax:: from .moduleY import spam --- 213,238 ---- Guido's Decision ! ================ ! Guido has Pronounced [1]_ that relative imports will use leading dots. ! A single leading dot indicates a relative import, starting with the ! current package. Two or more leading dots give a relative import to the ! parent(s) of the current package, one level per dot after the first. ! Here's a sample package layout:: ! package/ ! __init__.py ! subpackage1/ ! __init__.py ! moduleX.py ! moduleY.py ! subpackage2/ ! __init__.py ! moduleZ.py ! moduleA.py ! Assuming that the current file is either ``moduleX.py`` or ! ``subpackage1/__init__.py``, following are correct usages of the new ! syntax:: from .moduleY import spam *************** *** 237,243 **** ("insane" was the word Guido used). ! Reminder: relative imports must always use ``from <> import``; ! ``import <>`` is always absolute. Of course, absolute imports can use ! ``from <> import`` by omitting the leading dots. --- 248,268 ---- ("insane" was the word Guido used). ! Relative imports must always use ``from <> import``; ``import <>`` is ! always absolute. Of course, absolute imports can use ``from <> import`` ! by omitting the leading dots. The reason ``import .foo`` is prohibited ! is because after :: ! ! import XXX.YYY.ZZZ ! ! then :: ! ! XXX.YYY.ZZZ ! ! is usable in an expression. But :: ! ! .moduleY ! ! is not usable in an expression. !
participants (1)
-
goodger@users.sourceforge.net