PEP 3100 -- Miscellaneous Python 3.0 Plans
PEP: | 3100 |
Title: | Miscellaneous Python 3.0 Plans |
Author: | Brett Cannon <brett at python.org> |
Status: | Final |
Type: | Process |
Created: | 20-Aug-2004 |
Post-History: | |
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.
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
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.
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.
- PEP 238 (Changing the Division Operator)
- PEP 328 (Imports: Multi-Line and Absolute/Relative)
- PEP 343 (The "with" Statement)
- PEP 352 (Required Superclass for Exceptions)
- 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.
- True division becomes default behavior [done]
- exec as a statement is not worth it -- make it a function [done]
- Add optional declarations for static typing [done]
- Support only new-style classes; classic classes will be gone [done]
- Replace print by a function [done]
- The softspace attribute of files goes away. [done]
- Use except E1, E2, E3 as err: if you want the error variable. [done]
- None becomes a keyword ; also True and False [done]
- ... to become a general expression element [done]
- as becomes a keyword (starting in 2.6 already) [done]
- Have list comprehensions be syntactic sugar for passing an
equivalent generator expression to list(); as a consequence the
loop variable will no longer be exposed [done]
- Comparisons other than == and != between disparate types
will raise an exception unless explicitly supported by the type [done]
- floats will not be acceptable as arguments in place of ints for operations
where floats are inadvertently accepted (PyArg_ParseTuple() i & l formats)
- Remove from ... import * at function scope. [done] This means that functions
can always be optimized and support for unoptimized functions can go away.
- Imports
- Imports will be absolute by default. [done]
- Relative imports must be explicitly specified. [done]
- Indirection entries in sys.modules (i.e., a value of None for
A.string means to use the top-level string module) will not be
supported.
- __init__.py might become optional in sub-packages? __init__.py will still
be required for top-level packages.
- Cleanup the Py_InitModule() variants {,3,4} (also import and parser APIs)
- Cleanup the APIs exported in pythonrun, etc.
- Some expressions will require parentheses that didn't in 2.x:
- 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)] [done]
- Lambdas may have to be parenthesized [NO]
- In order to get rid of the confusion between __builtin__ and __builtins__,
it was decided to rename __builtin__ (the module) to builtins, and to leave
__builtins__ (the sandbox hook) alone. [done]
- Attributes on functions of the form func_whatever will be renamed
__whatever__ [done]
- Set literals and comprehensions [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.
- The __nonzero__ special method will be renamed to __bool__
and have to return a bool. The typeobject slot will be called
tp_bool [done]
- Dict comprehensions, as first proposed in [done]
{K(x): V(x) for x in S if P(x)} means dict((K(x), V(x)) for x in S if P(x)).
To be removed:
String exceptions: use instances of an Exception class [done]
raise Exception, "message": use raise Exception("message")
[done]
`x`: use repr(x) [done]
The <> operator: use != instead [done]
The __mod__ and __divmod__ special methods on float. [they should stay]
Drop unbound methods [done]
METH_OLDARGS [done]
WITH_CYCLE_GC [done]
__getslice__, __setslice__, __delslice__ ;
remove slice opcodes and use slice objects. [done]
__oct__, __hex__: use __index__ in oct() and hex()
instead. [done]
__methods__ and __members__ [done]
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
PyImport_ReloadModule ?
- Remove distinction between int and long types; 'long' built-in type and
literals with 'L' or 'l' suffix disappear [done]
- Make all strings be Unicode, and have a separate bytes() type
The new string type will be called 'str'. See PEP 3137. [done]
- Return iterable views instead of lists where appropriate for atomic
type methods (e.g. dict.keys(), dict.values(),
dict.items(), etc.); iter* methods will be removed. [done]
- Make string.join() stringify its arguments? [NO]
- Fix open() so it returns a ValueError if the mode is bad rather than IOError.
[done]
To be removed:
- basestring.find() and basestring.rfind(); use basestring.index()
or basestring.[r]partition() or
basestring.rindex() in a try/except block??? [UNLIKELY]
- file.xreadlines() method [done]
- dict.setdefault()? [UNLIKELY]
- dict.has_key() method; use in operator [done]
- list.sort() and builtin.sorted() methods: eliminate cmp
parameter [done]
- Make built-ins return an iterator where appropriate (e.g. range(),
zip(), map(), filter(), etc.) [done]
- Remove input() and rename raw_input() to input().
If you need the old input(), use eval(input()). [done]
- 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? [done]
- Exception hierarchy changes [done]
- Add a bin() function for a binary representation of integers [done]
To be removed:
- apply(): use f(*args, **kw) instead [done]
- buffer(): must die (use a bytes() type instead) (?) [done]
- callable(): just use isinstance(x, collections.Callable) (?) [done]
- compile(): put in sys (or perhaps in a module of its own)
- coerce(): no longer needed [done]
- execfile(), reload(): use exec() [done]
- intern(): put in sys , [done]
- reduce(): put in functools, a loop is more readable most of the
times , [done]
- xrange(): use range() instead [See range() above] [done]
- StandardError: this is a relic from the original exception hierarchy;
- subclass Exception instead. [done]
- 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
To be removed:
- The sets module. [done]
- stdlib modules to be removed
- see docstrings and comments in the source
- macfs [to do]
- new, reconvert, stringold, xmllib,
pcre, pypcre, strop [all done]
- see PEP 4
- buildtools,
mimetools,
multifile,
rfc822,
[to do]
- mpz, posixfile, regsub, rgbimage,
sha, statcache, sv, TERMIOS, timing [done]
- cfmfile, gopherlib, md5, MimeWriter, mimify [done]
- cl, sets, xreadlines, rotor, whrandom [done]
- Everything in lib-old [done]
- 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 ,
[done]
- sys.exc_type, sys.exc_values, sys.exc_traceback:
not thread-safe; use sys.exc_info() or an attribute
of the exception [done]
- sys.exc_clear: Python 3's except statements provide the same
functionality [done]
- array.read, array.write
- operator.isCallable : callable() built-in is being removed
[done]
- operator.sequenceIncludes : redundant thanks to
operator.contains [done]
- In the thread module, the acquire_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.
- Remove the unreliable empty() and full() methods from Queue.py?
- Remove jumpahead() from the random API?
- Make the primitive for random be something generating random bytes
rather than random floats?
- Get rid of Cookie.SerialCookie and Cookie.SmartCookie?
- Modify the heapq.heapreplace() API to compare the new value to the top
of the heap?
- 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?)
- Remove support for old systems, including: BeOS, RISCOS, (SGI) Irix, Tru64
This document has been placed in the public domain.
Source: https://github.com/python/peps/blob/master/pep-3100.txt