python-peps/pep-3100.txt

374 lines
14 KiB
Plaintext
Raw Normal View History

PEP: 3100
Title: Miscellaneous Python 3.0 Plans
2004-08-20 08:43:19 -04:00
Version: $Revision$
Last-Modified: $Date$
2004-08-20 11:05:39 -04:00
Author: A.M. Kuchling <amk@amk.ca>,
2004-08-20 08:43:19 -04:00
Brett Cannon <drifty@alum.berkeley.edu>
Status: Draft
Type: Informational
Content-Type: text/x-rst
Created: 20-Aug-2004
2004-08-20 11:05:39 -04:00
Post-History:
2004-08-20 08:43:19 -04:00
Abstract
========
This PEP, previously known as PEP 3000, describes smaller scale changes
and new features for which no separate PEP is written yet, all targeted
for Python 3000.
2004-08-20 08:43:19 -04:00
The list of features included in this document is subject to change
and isn't binding on the Python development community; features may be
added, removed, and modified at any time. The purpose of this list is
to focus our language development effort on changes that are steps to
3.0, and to encourage people to invent ways to smooth the transition.
This document is not a wish-list that anyone can extend. While there
are two authors of this PEP, we're just supplying the text; the
decisions for which changes are listed in this document are made by
2004-08-20 11:05:39 -04:00
Guido van Rossum, who has chosen them as goals for Python 3.0.
Guido's pronouncements on things that will not change in Python 3.0
are recorded in PEP 3099. [#pep3099]_
2004-08-20 08:43:19 -04:00
General goals
=============
A general goal is to reduce feature duplication by removing old ways
of doing things. A general principle of the design will be that one
obvious way of doing something is enough. [1]_
Influencing PEPs
================
* PEP 238 (Changing the Division Operator) [#pep238]_
* PEP 328 (Imports: Multi-Line and Absolute/Relative) [#pep328]_
* PEP 343 (The "with" Statement) [#pep343]_
* PEP 352 (Required Superclass for Exceptions) [#pep352]_
Style changes
=============
* The C style guide will be updated to use 4-space indents, never tabs.
This style should be used for all new files; existing files can be
updated only if there is no hope to ever merge a particular file from
the Python 2 HEAD. Within a file, the indentation style should be
consistent. No other style guide changes are planned ATM.
2004-08-20 08:43:19 -04:00
Core language
=============
* True division becomes default behavior [#pep238]_ [done]
2006-09-06 02:42:42 -04:00
* ``exec`` as a statement is not worth it -- make it a function [done]
2006-12-19 14:01:10 -05:00
* (Maybe) add optional declarations for static typing [10]_
* Support only new-style classes; classic classes will be gone [1]_ [done]
2006-12-19 14:01:10 -05:00
* Replace ``print`` by a function [14]_
* Use ``except E1, E2, E3 as err:`` if you want the error variable. [3]_
* ``None`` becomes a keyword [4]_ (What about ``True``, ``False``?)
2006-12-19 14:01:10 -05:00
* ``...`` to become a general expression element [16]_ [done]
2006-09-06 02:42:42 -04:00
* ``as`` becomes a keyword [5]_ (starting in 2.6 already) [done]
* Have list comprehensions be syntactic sugar for passing an
equivalent generator expression to ``list()``; as a consequence the
2006-12-19 14:01:10 -05:00
loop variable will no longer be exposed [#pep289]_
* Comparisons other than ``==`` and ``!=`` between disparate types
2006-09-06 02:42:42 -04:00
will raise an exception unless explicitly supported by the type [6]_ [done]
2006-12-19 14:01:10 -05:00
* Exceptions might grow an attribute to store the traceback [11]_
* floats will not be acceptable as arguments in place of ints for operations
where floats are inadvertantly accepted (PyArg_ParseTuple() i & l formats)
* Imports will be absolute by default. [done]
Relative imports must be explicitly specified [#pep328]_ [done]
* __init__.py might become optional in sub-packages. __init__.py will still
be required for top-level packages.
2006-02-27 11:26:26 -05:00
* Cleanup the Py_InitModule() variants {,3,4} (also import and parser APIs)
* Cleanup the APIs exported in pythonrun, etc.
2006-02-28 12:18:37 -05:00
* Some expressions will require parentheses that didn't in 2.x:
2006-02-27 12:38:27 -05:00
- List comprehensions will require parentheses around the iterables.
This will make list comprehensions more similar to generator comprehensions.
[x for x in 1, 2] will need to be: [x for x in (1, 2)]
2006-12-19 14:01:10 -05:00
- Lambdas may have to be parenthesized [#pep308]_
2006-02-27 13:29:14 -05:00
* Builtin module init function names (PyMODINIT_FUNC) will be prefixed
with _Py (or Py). Currently they aren't namespace safe since the names
start with init.
2006-03-15 00:25:39 -05:00
* __builtins__ should get a different name *or* completely unified
with __builtin__. Keeping both with confusingly similar spellings
and semantics is evil.
* Attributes on functions of the form ``func_whatever`` will be renamed
2006-12-19 14:01:10 -05:00
``__whatever__`` [17]_
* Set literals and comprehensions [19]_ [20]_ [done]
{x} means set([x]); {x, y} means set([x, y]).
{F(x) for x in S if P(x)} means set(F(x) for x in S if P(x)).
NB. {range(x)} means set([range(x)]), NOT set(range(x)).
There's no literal for an empty set; use set() (or {1}&{2} :-).
There's no frozenset literal; they are too rarely needed.
2006-12-19 14:01:10 -05:00
* Might reconsider PEP 299 [#pep299]_: special __main__() function in modules.
* The ``__nonzero__`` special method will be renamed to ``__bool__``
and have to return a bool. The typeobject slot will be called
2006-12-19 14:01:10 -05:00
``tp_bool`` [23]_ [done]
2004-08-20 08:43:19 -04:00
To be removed:
* String exceptions: use instances of an Exception class [2]_ [done]
2006-12-19 14:01:10 -05:00
* ``raise Exception, "message"``: use ``raise Exception("message")`` [12]_
* ```x```: use ``repr(x)`` [2]_ [done]
* The ``<>`` operator: use ``!=`` instead [3]_ [done]
2006-12-19 14:01:10 -05:00
* The __mod__ and __divmod__ special methods on float. [21]_
* Might drop unbound methods? [7]_
* METH_OLDARGS
* WITH_CYCLE_GC [done]
2006-12-19 14:01:10 -05:00
* __getslice__, __setslice__, __delslice__ [#sequence-types]_;
2006-09-06 02:42:42 -04:00
remove slice opcodes and use slice objects.
[Thomas Wouters is working on this in a branch]
* C APIs (see code):
PyFloat_AsString, PyFloat_AsReprString, PyFloat_AsStringEx,
PySequence_In, PyEval_EvalFrame, PyEval_CallObject,
_PyObject_Del, _PyObject_GC_Del, _PyObject_GC_Track, _PyObject_GC_UnTrack
PyString_AsEncodedString, PyString_AsDecodedString
PyArg_NoArgs, PyArg_GetInt, intargfunc, intintargfunc
Atomic Types
============
* Remove distinction between int and long types [1]_
(int may become an abstract base type, with short and long subtypes.)
2006-09-06 02:42:42 -04:00
[MvL is working on this in the int_unification branch]
* Make all strings be Unicode, and have a separate bytes() type [1]_
The new string type will be called 'str'.
* Return iterators instead of lists where appropriate for atomic type methods
(e.g. ``dict.keys()``, ``dict.values()``, ``dict.items()``, etc.); iter*
methods will be removed.
Better: make keys(), etc. return views ala Java collections???
2006-12-19 14:01:10 -05:00
* Make ``string.join()`` stringify its arguments? [18]_
To be removed:
* ``basestring.find()`` and ``basestring.rfind()``; use ``basestring.index()``
2006-09-06 02:42:42 -04:00
or ``basestring.[r]partition()`` or
2006-12-19 14:01:10 -05:00
or ``basestring.rindex()`` in a try/except block??? [13]_
* ``file.xreadlines()`` method [#file-object]_ [done]
2006-12-19 14:01:10 -05:00
* ``dict.setdefault()``? [15]_
* ``dict.has_key()`` method [done]
2004-08-20 08:43:19 -04:00
Built-in Namespace
==================
2004-08-20 08:43:19 -04:00
* Make built-ins return an iterator where appropriate (e.g. ``range()``,
``zip()``, etc.) [zip is done; Neal Norwitz has a patch for range()]
2004-08-20 11:05:39 -04:00
* Relevant functions should consume iterators (e.g. ``min()``,
``max()``) [They already do, since 2.2.]
* Introduce ``trunc()``, which would call the ``__trunc__()`` method on its
argument; suggested use is for objects like float where calling ``__int__()``
has data loss, but an integral representation is still desired? [8]_
* Exception hierarchy changes [#pep352]_ [done]
2004-08-20 11:05:39 -04:00
2004-08-20 08:43:19 -04:00
To be removed:
* ``apply()``: use ``f(*args, **kw)`` instead [2]_ [done]
* ``buffer()``: must die (use a bytes() type instead) (?) [2]_
2006-12-03 03:23:02 -05:00
* ``callable()``: just call the object and catch the exception??? [2]_
* ``compile()``: put in ``sys`` (or perhaps in a module of its own) [2]_
2004-08-20 11:05:39 -04:00
* ``coerce()``: no longer needed [2]_
* ``execfile()``, ``reload()``: use ``exec()`` [2]_
* ``input()``: use ``eval(sys.stdin.readline())`` [2]_ [done]
2006-12-19 14:01:10 -05:00
* ``intern()``, ``id()``: put in ``sys`` (?) [2]_, [22]_
* ``map()``, ``filter()``: use list comprehensions instead??? [1]_, [9]_
2006-09-06 02:42:42 -04:00
(Actually these can stay.)
* ``reduce()``: write a loop instead [2]_, [9]_ [done]
* ``raw_input()``: use ``sys.stdin.readline()`` ??? [2]_ [done]
2006-09-06 02:42:42 -04:00
* ``xrange()``: use ``range()`` instead [1]_ [See range() above]
2004-08-20 08:43:19 -04:00
Standard library
================
* Reorganize the standard library to not be as shallow?
* Move test code to where it belongs, there will be no more test() functions
in the standard library
* Convert all tests to use either doctest or unittest.
* For the procedures of standard library improvement, see PEP 3001 [#pep3001]_
2004-08-20 08:43:19 -04:00
To be removed:
* stdlib modules to be removed
+ see docstrings and comments in the source
- ``macfs``, ``new``, ``reconvert``, ``stringold``, ``xmllib``,
``pcre``, ``pypcre``, ``strop``
2006-12-19 14:01:10 -05:00
+ see PEP 4 [#pep4]_
- ``posixfile``, ``pre``, ``regsub``, ``rfc822``,
``statcache``, ``string``, ``TERMIOS`` ``mimetools``,
``MimeWriter``, ``mimify``, ``mpz``, ``rgbimage``
2006-12-19 14:01:10 -05:00
+ Everything in lib-old [#pep4]_
- ``Para``, ``addpack``, ``cmp``, ``cmpcache``, ``codehack``,
``dircmp``, ``dump``, ``find``, ``fmt``, ``grep``,
``lockfile``, ``newdir``, ``ni``, ``packmail``, ``poly``,
``rand``, ``statcache``, ``tb``, ``tzparse``, ``util``,
``whatsound``, ``whrandom``, ``zmod``
* ``sys.exitfunc``: use atexit module instead [#sys-module]_
* ``sys.exc_type``, ``sys.exc_values``, ``sys.exc_traceback``:
not thread-safe; use ``sys.exc_info()`` or an attribute
2006-12-19 14:01:10 -05:00
of the exception [2]_ [11]_ [#sys-module]_
* ``array.read``, ``array.write`` [#array-module]_
* ``operator.isCallable`` : ``callable()`` built-in is being removed
[#operator-module]_
* ``operator.sequenceIncludes`` : redundant thanks to
``operator.contains`` [#operator-module]_
* In the thread module, the aquire_lock() and release_lock() aliases
for the acquire() and release() methods on lock objects.
(Probably also just remove the thread module as a public API,
in favor of always using threading.py.)
* UserXyz classes, in favour of XyzMixins.
2004-08-20 08:43:19 -04:00
2006-03-22 00:24:31 -05:00
Outstanding Issues
==================
* Require C99, so we can use // comments, named initializers, declare variables
without introducing a new scope, among other benefits. (Also better support
for IEEE floating point issues like NaN and infinities?)
2006-03-22 00:24:31 -05:00
* Remove support for old systems, including: BeOS, RISCOS, (SGI) Irix, Tru64
2006-03-22 00:24:31 -05:00
2004-08-20 08:43:19 -04:00
References
==========
2004-08-20 11:05:39 -04:00
.. [1] PyCon 2003 State of the Union:
2004-08-20 08:43:19 -04:00
http://www.python.org/doc/essays/ppt/pycon2003/pycon2003.ppt
2004-08-20 11:05:39 -04:00
.. [2] Python Regrets:
2004-08-20 08:43:19 -04:00
http://www.python.org/doc/essays/ppt/regrets/PythonRegrets.pdf
2004-08-20 11:05:39 -04:00
.. [3] Python Wiki:
2004-08-20 08:43:19 -04:00
http://www.python.org/moin/Python3.0
.. [4] python-dev email ("Constancy of None")
http://mail.python.org/pipermail/python-dev/2004-July/046294.html
.. [5] python-dev email (' "as" to be a keyword?')
http://mail.python.org/pipermail/python-dev/2004-July/046316.html
.. [6] python-dev email ("Comparing heterogeneous types")
http://mail.python.org/pipermail/python-dev/2004-June/045111.html
.. [7] python-dev email ("Let's get rid of unbound methods")
http://mail.python.org/pipermail/python-dev/2005-January/050625.html
.. [8] python-dev email ("Fixing _PyEval_SliceIndex so that integer-like
objects can be used")
http://mail.python.org/pipermail/python-dev/2005-February/051674.html
2006-12-19 14:01:10 -05:00
.. [9] Guido's blog ("The fate of reduce() in Python 3000")
http://www.artima.com/weblogs/viewpost.jsp?thread=98196
.. [10] Guido's blog ("Python Optional Typechecking Redux")
http://www.artima.com/weblogs/viewpost.jsp?thread=89161
.. [11] python-dev email ("anonymous blocks")
http://mail.python.org/pipermail/python-dev/2005-April/053060.html
2006-12-19 14:01:10 -05:00
.. [12] python-dev email ("PEP 8: exception style")
http://mail.python.org/pipermail/python-dev/2005-August/055190.html
2006-12-19 14:01:10 -05:00
.. [13] python-dev email (Remove str.find in 3.0?)
http://mail.python.org/pipermail/python-dev/2005-August/055705.html
2006-12-19 14:01:10 -05:00
.. [14] python-dev email (Replacement for print in Python 3.0)
http://mail.python.org/pipermail/python-dev/2005-September/056154.html
2006-12-19 14:01:10 -05:00
.. [15] python-dev email ("defaultdict")
2006-02-19 02:10:16 -05:00
http://mail.python.org/pipermail/python-dev/2006-February/061261.html
2006-12-19 14:01:10 -05:00
.. [16] python-3000 email
2006-04-19 17:56:53 -04:00
http://mail.python.org/pipermail/python-3000/2006-April/000996.html
2006-12-19 14:01:10 -05:00
.. [17] python-3000 email ("Pronouncement on parameter lists")
http://mail.python.org/pipermail/python-3000/2006-April/001175.html
2006-12-19 14:01:10 -05:00
.. [18] python-3000 email ("More wishful thinking")
http://mail.python.org/pipermail/python-3000/2006-April/000810.html
2006-12-19 14:01:10 -05:00
.. [19] python-3000 email ("sets in P3K?")
http://mail.python.org/pipermail/python-3000/2006-April/001286.html
2006-12-19 14:01:10 -05:00
.. [20] python-3000 email ("sets in P3K?")
http://mail.python.org/pipermail/python-3000/2006-May/001666.html
2006-12-19 14:01:10 -05:00
.. [21] python-3000 email ("bug in modulus?")
http://mail.python.org/pipermail/python-3000/2006-May/001735.html
2006-12-19 14:01:10 -05:00
.. [22] SF patch "sys.id() and sys.intern()"
http://www.python.org/sf/1601678
.. [23] python-3000 email ("__nonzero__ vs. __bool__")
http://mail.python.org/pipermail/python-3000/2006-November/004524.html
.. [#sys-module] Python docs (sys -- System-specific parameters and functions)
http://docs.python.org/lib/module-sys.html
.. [#operator-module] Python docs (operator -- Standard operators as functions)
http://docs.python.org/lib/module-operator.html
.. [#array-module] Python docs (array -- Efficient arrays of numeric values)
http://docs.python.org/lib/module-array.html
.. [#file-object] Python docs (File objects)
http://docs.python.org/lib/bltin-file-objects.html
2006-12-19 14:01:10 -05:00
.. [#sequence-types] Python docs (Additional methods for emulation of sequence types)
http://docs.python.org/ref/sequence-methods.html
.. [#pep4] PEP 4 ("Deprecation of Standard Modules")
http://www.python.org/dev/peps/pep-0004
2006-06-28 02:47:51 -04:00
.. [#pep238] PEP 238 (Changing the Division Operator)
http://www.python.org/dev/peps/pep-0238
2006-12-19 14:01:10 -05:00
.. [#pep289] PEP 289 ("Generator Expressions")
http://www.python.org/dev/peps/pep-0289
2006-12-19 14:01:10 -05:00
.. [#pep299] PEP 299 ("Special __main__() function in modules")
http://www.python.org/dev/peps/pep-0299
2006-12-19 14:01:10 -05:00
.. [#pep308] PEP 308 ("Conditional Expressions")
http://www.python.org/dev/peps/pep-0308
.. [#pep328] PEP 328 (Imports: Multi-Line and Absolute/Relative)
http://www.python.org/dev/peps/pep-0328
.. [#pep343] PEP 343 (The "with" Statement)
http://www.python.org/dev/peps/pep-0343
.. [#pep352] PEP 352 (Required Superclass for Exceptions)
http://www.python.org/dev/peps/pep-0352
2006-05-02 14:32:39 -04:00
.. [#pep3001] PEP 3001 (Process for reviewing and improving standard
library modules) http://www.python.org/dev/peps/pep-3001
.. [#pep3099] PEP 3099 (Things that will Not Change in Python 3000)
http://www.python.org/dev/peps/pep-3099
2004-08-20 08:43:19 -04:00
Copyright
=========
This document has been placed in the public domain.
..
Local Variables:
mode: indented-text
indent-tabs-mode: nil
sentence-end-double-space: t
fill-column: 70
End: