-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:python/peps
- Loading branch information
Showing
36 changed files
with
3,880 additions
and
1,862 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,73 +5,79 @@ Last-Modified: $Date$ | |
Author: Fred L. Drake, Jr. <[email protected]> | ||
Status: Final | ||
Type: Informational | ||
Content-Type: text/x-rst | ||
Created: 25-Jul-2000 | ||
Python-Version: 1.6 | ||
Post-History: | ||
|
||
|
||
Introduction | ||
============ | ||
|
||
This PEP describes the Python 1.6 release schedule. The CVS | ||
revision history of this file contains the definitive historical | ||
record. | ||
This PEP describes the Python 1.6 release schedule. The CVS | ||
revision history of this file contains the definitive historical | ||
record. | ||
|
||
This release will be produced by BeOpen PythonLabs staff for the | ||
Corporation for National Research Initiatives (CNRI). | ||
This release will be produced by BeOpen PythonLabs staff for the | ||
Corporation for National Research Initiatives (CNRI). | ||
|
||
|
||
Schedule | ||
======== | ||
|
||
August 1 1.6 beta 1 release (planned). | ||
August 3 1.6 beta 1 release (actual). | ||
August 15 1.6 final release (planned). | ||
September 5 1.6 final release (actual). | ||
* August 1: 1.6 beta 1 release (planned). | ||
* August 3: 1.6 beta 1 release (actual). | ||
* August 15: 1.6 final release (planned). | ||
* September 5: 1.6 final release (actual). | ||
|
||
|
||
Features | ||
======== | ||
|
||
A number of features are required for Python 1.6 in order to | ||
fulfill the various promises that have been made. The following | ||
are required to be fully operational, documented, and forward | ||
compatible with the plans for Python 2.0: | ||
A number of features are required for Python 1.6 in order to | ||
fulfill the various promises that have been made. The following | ||
are required to be fully operational, documented, and forward | ||
compatible with the plans for Python 2.0: | ||
|
||
* Unicode support: The Unicode object defined for Python 2.0 must | ||
be provided, including all methods and codec support. | ||
* Unicode support: The Unicode object defined for Python 2.0 must be provided, | ||
including all methods and codec support. | ||
|
||
* SRE: Fredrik Lundh's new regular expression engine will be used | ||
to provide support for both 8-bit strings and Unicode strings. | ||
It must pass the regression test used for the pcre-based version | ||
of the re module. | ||
* SRE: Fredrik Lundh's new regular expression engine will be used | ||
to provide support for both 8-bit strings and Unicode strings. It must pass | ||
the regression test used for the pcre-based version of the re module. | ||
|
||
* The curses module was in the middle of a transformation to a | ||
package, so the final form was adopted. | ||
* The curses module was in the middle of a transformation to a package, so the | ||
final form was adopted. | ||
|
||
|
||
Mechanism | ||
========= | ||
|
||
The release will be created as a branch from the development tree | ||
rooted at CNRI's close of business on 16 May 2000. Patches | ||
required from more recent checkins will be merged in by moving the | ||
branch tag on individual files whenever possible in order to | ||
reduce mailing list clutter and avoid divergent and incompatible | ||
implementations. | ||
The release will be created as a branch from the development tree | ||
rooted at CNRI's close of business on 16 May 2000. Patches | ||
required from more recent checkins will be merged in by moving the | ||
branch tag on individual files whenever possible in order to | ||
reduce mailing list clutter and avoid divergent and incompatible | ||
implementations. | ||
|
||
The branch tag is "cnri-16-start". | ||
The branch tag is "cnri-16-start". | ||
|
||
Patches and features will be merged to the extent required to pass | ||
regression tests in effect on 16 May 2000. | ||
Patches and features will be merged to the extent required to pass | ||
regression tests in effect on 16 May 2000. | ||
|
||
The beta release is tagged "r16b1" in the CVS repository, and the | ||
final Python 1.6 release is tagged "release16" in the repository. | ||
The beta release is tagged "r16b1" in the CVS repository, and the | ||
final Python 1.6 release is tagged "release16" in the repository. | ||
|
||
|
||
Copyright | ||
========= | ||
|
||
This document has been placed in the public domain. | ||
This document has been placed in the public domain. | ||
|
||
|
||
|
||
Local Variables: | ||
mode: indented-text | ||
indent-tabs-mode: nil | ||
End: | ||
|
||
.. | ||
Local Variables: | ||
mode: indented-text | ||
indent-tabs-mode: nil | ||
End: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,15 @@ Last-Modified: $Date$ | |
Author: [email protected] (David Ascher) | ||
Status: Rejected | ||
Type: Standards Track | ||
Content-Type: text/x-rst | ||
Created: 15-Jul-2000 | ||
Python-Version: 2.1 | ||
Post-History: | ||
|
||
|
||
|
||
Local Variables: | ||
mode: indented-text | ||
indent-tabs-mode: nil | ||
End: | ||
|
||
.. | ||
Local Variables: | ||
mode: indented-text | ||
indent-tabs-mode: nil | ||
End: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,139 +5,154 @@ Last-Modified: $Date$ | |
Author: [email protected] (Ka-Ping Yee) | ||
Status: Superseded | ||
Type: Standards Track | ||
Content-Type: text/x-rst | ||
Created: 24-Jul-2000 | ||
Python-Version: 2.1 | ||
Post-History: | ||
Superseded-By: 292 | ||
|
||
|
||
Abstract | ||
======== | ||
|
||
This document proposes a string interpolation feature for Python | ||
to allow easier string formatting. The suggested syntax change | ||
is the introduction of a '$' prefix that triggers the special | ||
interpretation of the '$' character within a string, in a manner | ||
reminiscent to the variable interpolation found in Unix shells, | ||
awk, Perl, or Tcl. | ||
This document proposes a string interpolation feature for Python | ||
to allow easier string formatting. The suggested syntax change | ||
is the introduction of a '$' prefix that triggers the special | ||
interpretation of the '$' character within a string, in a manner | ||
reminiscent to the variable interpolation found in Unix shells, | ||
awk, Perl, or Tcl. | ||
|
||
|
||
Copyright | ||
========= | ||
|
||
This document is in the public domain. | ||
This document is in the public domain. | ||
|
||
|
||
Specification | ||
============= | ||
|
||
Strings may be preceded with a '$' prefix that comes before the | ||
leading single or double quotation mark (or triplet) and before | ||
any of the other string prefixes ('r' or 'u'). Such a string is | ||
processed for interpolation after the normal interpretation of | ||
backslash-escapes in its contents. The processing occurs just | ||
before the string is pushed onto the value stack, each time the | ||
string is pushed. In short, Python behaves exactly as if '$' | ||
were a unary operator applied to the string. The operation | ||
performed is as follows: | ||
Strings may be preceded with a '$' prefix that comes before the | ||
leading single or double quotation mark (or triplet) and before | ||
any of the other string prefixes ('r' or 'u'). Such a string is | ||
processed for interpolation after the normal interpretation of | ||
backslash-escapes in its contents. The processing occurs just | ||
before the string is pushed onto the value stack, each time the | ||
string is pushed. In short, Python behaves exactly as if '$' | ||
were a unary operator applied to the string. The operation | ||
performed is as follows: | ||
|
||
The string is scanned from start to end for the '$' character | ||
(\x24 in 8-bit strings or \u0024 in Unicode strings). If there | ||
are no '$' characters present, the string is returned unchanged. | ||
The string is scanned from start to end for the '$' character | ||
(``\x24`` in 8-bit strings or ``\u0024`` in Unicode strings). If there | ||
are no '$' characters present, the string is returned unchanged. | ||
|
||
Any '$' found in the string, followed by one of the two kinds of | ||
expressions described below, is replaced with the value of the | ||
expression as evaluated in the current namespaces. The value is | ||
converted with str() if the containing string is an 8-bit string, | ||
or with unicode() if it is a Unicode string. | ||
Any '$' found in the string, followed by one of the two kinds of | ||
expressions described below, is replaced with the value of the | ||
expression as evaluated in the current namespaces. The value is | ||
converted with ``str()`` if the containing string is an 8-bit string, | ||
or with ``unicode()`` if it is a Unicode string. | ||
|
||
1. A Python identifier optionally followed by any number of | ||
trailers, where a trailer consists of: | ||
- a dot and an identifier, | ||
- an expression enclosed in square brackets, or | ||
- an argument list enclosed in parentheses | ||
(This is exactly the pattern expressed in the Python grammar | ||
by "NAME trailer*", using the definitions in Grammar/Grammar.) | ||
1. A Python identifier optionally followed by any number of | ||
trailers, where a trailer consists of: | ||
- a dot and an identifier, | ||
- an expression enclosed in square brackets, or | ||
- an argument list enclosed in parentheses | ||
(This is exactly the pattern expressed in the Python grammar | ||
by "``NAME`` trailer*", using the definitions in Grammar/Grammar.) | ||
|
||
2. Any complete Python expression enclosed in curly braces. | ||
2. Any complete Python expression enclosed in curly braces. | ||
|
||
Two dollar-signs ("$$") are replaced with a single "$". | ||
Two dollar-signs ("$$") are replaced with a single "$". | ||
|
||
|
||
Examples | ||
|
||
Here is an example of an interactive session exhibiting the | ||
expected behaviour of this feature. | ||
|
||
>>> a, b = 5, 6 | ||
>>> print $'a = $a, b = $b' | ||
a = 5, b = 6 | ||
>>> $u'uni${a}ode' | ||
u'uni5ode' | ||
>>> print $'\$a' | ||
5 | ||
>>> print $r'\$a' | ||
\5 | ||
>>> print $'$$$a.$b' | ||
$5.6 | ||
>>> print $'a + b = ${a + b}' | ||
a + b = 11 | ||
>>> import sys | ||
>>> print $'References to $a: $sys.getrefcount(a)' | ||
References to 5: 15 | ||
>>> print $"sys = $sys, sys = $sys.modules['sys']" | ||
sys = <module 'sys' (built-in)>, sys = <module 'sys' (built-in)> | ||
>>> print $'BDFL = $sys.copyright.split()[4].upper()' | ||
BDFL = GUIDO | ||
======== | ||
|
||
Here is an example of an interactive session exhibiting the | ||
expected behaviour of this feature:: | ||
|
||
>>> a, b = 5, 6 | ||
>>> print $'a = $a, b = $b' | ||
a = 5, b = 6 | ||
>>> $u'uni${a}ode' | ||
u'uni5ode' | ||
>>> print $'\$a' | ||
5 | ||
>>> print $r'\$a' | ||
\5 | ||
>>> print $'$$$a.$b' | ||
$5.6 | ||
>>> print $'a + b = ${a + b}' | ||
a + b = 11 | ||
>>> import sys | ||
>>> print $'References to $a: $sys.getrefcount(a)' | ||
References to 5: 15 | ||
>>> print $"sys = $sys, sys = $sys.modules['sys']" | ||
sys = <module 'sys' (built-in)>, sys = <module 'sys' (built-in)> | ||
>>> print $'BDFL = $sys.copyright.split()[4].upper()' | ||
BDFL = GUIDO | ||
|
||
|
||
Discussion | ||
========== | ||
|
||
'$' is chosen as the interpolation character within the | ||
string for the sake of familiarity, since it is already used | ||
for this purpose in many other languages and contexts. | ||
'$' is chosen as the interpolation character within the | ||
string for the sake of familiarity, since it is already used | ||
for this purpose in many other languages and contexts. | ||
|
||
It is then natural to choose '$' as a prefix, since it is a | ||
mnemonic for the interpolation character. | ||
It is then natural to choose '$' as a prefix, since it is a | ||
mnemonic for the interpolation character. | ||
|
||
Trailers are permitted to give this interpolation mechanism | ||
even more power than the interpolation available in most other | ||
languages, while the expression to be interpolated remains | ||
clearly visible and free of curly braces. | ||
Trailers are permitted to give this interpolation mechanism | ||
even more power than the interpolation available in most other | ||
languages, while the expression to be interpolated remains | ||
clearly visible and free of curly braces. | ||
|
||
'$' works like an operator and could be implemented as an | ||
operator, but that prevents the compile-time optimization | ||
and presents security issues. So, it is only allowed as a | ||
string prefix. | ||
'$' works like an operator and could be implemented as an | ||
operator, but that prevents the compile-time optimization | ||
and presents security issues. So, it is only allowed as a | ||
string prefix. | ||
|
||
|
||
Security Issues | ||
=============== | ||
|
||
"$" has the power to eval, but only to eval a literal. As | ||
described here (a string prefix rather than an operator), it | ||
introduces no new security issues since the expressions to be | ||
evaluated must be literally present in the code. | ||
"$" has the power to eval, but only to eval a literal. As | ||
described here (a string prefix rather than an operator), it | ||
introduces no new security issues since the expressions to be | ||
evaluated must be literally present in the code. | ||
|
||
|
||
Implementation | ||
============== | ||
|
||
The ``Itpl`` module at [1]_ provides a | ||
prototype of this feature. It uses the tokenize module to find | ||
the end of an expression to be interpolated, then calls ``eval()`` | ||
on the expression each time a value is needed. In the prototype, | ||
the expression is parsed and compiled again each time it is | ||
evaluated. | ||
|
||
As an optimization, interpolated strings could be compiled | ||
directly into the corresponding bytecode; that is:: | ||
|
||
$'a = $a, b = $b' | ||
|
||
The Itpl module at http://www.lfw.org/python/Itpl.py provides a | ||
prototype of this feature. It uses the tokenize module to find | ||
the end of an expression to be interpolated, then calls eval() | ||
on the expression each time a value is needed. In the prototype, | ||
the expression is parsed and compiled again each time it is | ||
evaluated. | ||
could be compiled as though it were the expression:: | ||
|
||
As an optimization, interpolated strings could be compiled | ||
directly into the corresponding bytecode; that is, | ||
('a = ' + str(a) + ', b = ' + str(b)) | ||
|
||
$'a = $a, b = $b' | ||
so that it only needs to be compiled once. | ||
|
||
could be compiled as though it were the expression | ||
|
||
('a = ' + str(a) + ', b = ' + str(b)) | ||
References | ||
========== | ||
|
||
so that it only needs to be compiled once. | ||
.. [1] http://www.lfw.org/python/Itpl.py | ||
|
||
|
||
Local Variables: | ||
mode: indented-text | ||
indent-tabs-mode: nil | ||
End: | ||
.. | ||
Local Variables: | ||
mode: indented-text | ||
indent-tabs-mode: nil | ||
End: |
Oops, something went wrong.