update from Aahz

This commit is contained in:
David Goodger 2004-04-03 15:02:46 +00:00
parent 0a9b3b929c
commit af60734c54
1 changed files with 41 additions and 13 deletions

View File

@ -2,13 +2,13 @@ PEP: 328
Title: Imports: Multi-Line and Absolute/Relative
Version: $Revision$
Last-Modified: $Date$
Author: Aahz <aahz@pythoncraft.com
Status: Draft
Author: Aahz <aahz@pythoncraft.com>
Status: Accepted
Type: Standards Track
Python-Version: 2.4
Content-Type: text/x-rst
Created: 21-Dec-2003
Post-History:
Post-History: 8-Mar-2004
Abstract
@ -39,7 +39,7 @@ package, you have to choose one of several unpalatable options:
* Write a long line with backslash continuations::
from Tkinter import Tk, Frame, Button, Entry, Canvas, Text \
from Tkinter import Tk, Frame, Button, Entry, Canvas, Text, \
LEFT, DISABLED, NORMAL, RIDGE, END
* Write multiple ``import`` statements::
@ -52,7 +52,7 @@ package, you have to choose one of several unpalatable options:
Instead, it should be possible to use Python's standard grouping
mechanism (parentheses) to write the ``import`` statement::
from Tkinter import (Tk, Frame, Button, Entry, Canvas, Text
from Tkinter import (Tk, Frame, Button, Entry, Canvas, Text,
LEFT, DISABLED, NORMAL, RIDGE, END)
This part of the proposal already has BDFL approval.
@ -101,11 +101,11 @@ Here are the contenders:
* One from Guido::
from .foo import
from .foo import bar
and ::
from ...foo import
from ...foo import bar
These two forms have a couple of different suggested semantics. One
semantic is to make each dot represent one level. There have been
@ -118,6 +118,13 @@ Here are the contenders:
"search up from current package directory until the ultimate package
parent gets hit".)
Some people have suggested other punctuation as the separator, such
as "-" or "^".
Some people have suggested using "*"::
from *.foo import bar
* The next set of options is conflated from several posters::
from __pkg__.__pkg__ import
@ -130,6 +137,26 @@ Here are the contenders:
clear and explicit. Overall, more people prefer ``__pkg__`` as the
shorter option.
* One suggestion was to allow only sibling references. In other words,
you would not be able to use relative imports to refer to modules
higher in the package tree. You would then be able to do either ::
from .spam import eggs
or ::
import .spam.eggs
* Some people favor allowing indexed parents::
from -2.spam import eggs
In this scenario, importing from the current directory would be a
simple ::
from .spam import eggs
* Finally, some people dislike the way you have to change ``import``
to ``from ... import`` when you want to dig inside a package. They
suggest completely rewriting the ``import`` syntax::
@ -160,12 +187,11 @@ Here are the contenders:
import foo as bar, spam as ham searching XXX
Open Issues
===========
Guido's Decision
================
The BDFL needs to decide which of the various options for relative
imports works best. Additional proposals are still welcome. As
usual, Guido prefers reasons to histrionics.
Guido has Pronounced [1]_ that relative imports will use leading dots,
one per level of parent.
References
@ -185,6 +211,8 @@ For more background, see the following python-dev threads:
- `Another Strategy for Relative Import
<http://mail.python.org/pipermail/python-dev/2003-December/041418.html>`__
.. [1] http://mail.python.org/pipermail/python-dev/2004-March/043739.html
Copyright
=========