Movatterモバイル変換


[0]ホーム

URL:


Following system colour schemeSelected dark colour schemeSelected light colour scheme

Python Enhancement Proposals

PEP 3100 – Miscellaneous Python 3.0 Plans

Author:
Brett Cannon <brett at python.org>
Status:
Final
Type:
Process
Created:
20-Aug-2004
Post-History:


Table of Contents

Abstract

This PEP, previously known asPEP 3000, describes smaller scale changesand new features for which no separate PEP is written yet, all targetedfor Python 3000.

The list of features included in this document is subject to changeand isn’t binding on the Python development community; features may beadded, removed, and modified at any time. The purpose of this list isto focus our language development effort on changes that are steps to3.0, and to encourage people to invent ways to smooth the transition.

This document is not a wish-list that anyone can extend. While thereare two authors of this PEP, we’re just supplying the text; thedecisions for which changes are listed in this document are made byGuido van Rossum, who has chosen them as goals for Python 3.0.

Guido’s pronouncements on things that will not change in Python 3.0are recorded inPEP 3099.

General goals

A general goal is to reduce feature duplication by removing old waysof doing things. A general principle of the design will be that oneobvious way of doing something is enough.[1]

Influencing PEPs

  • 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)

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 beupdated only if there is no hope to ever merge a particular file fromthe Python 2 HEAD. Within a file, the indentation style should beconsistent. No other style guide changes are planned ATM.

Core language

  • True division becomes default behaviorPEP 238 [done]
  • exec as a statement is not worth it – make it a function [done]
  • Add optional declarations for static typingPEP 3107[10] [done]
  • Support only new-style classes; classic classes will be gone[1] [done]
  • Replaceprint by a function[14]PEP 3105 [done]
  • Thesoftspace attribute of files goes away. [done]
  • UseexceptE1,E2,E3aserr: if you want the error variable.[3] [done]
  • None becomes a keyword[4]; alsoTrue andFalse [done]
  • ... to become a general expression element[16] [done]
  • as becomes a keyword[5] (starting in 2.6 already) [done]
  • Have list comprehensions be syntactic sugar for passing anequivalent generator expression tolist(); as a consequence theloop variable will no longer be exposedPEP 289 [done]
  • Comparisons other than== and!= between disparate typeswill raise an exception unless explicitly supported by the type[6] [done]
  • floats will not be acceptable as arguments in place of ints for operationswhere floats are inadvertently accepted (PyArg_ParseTuple() i & l formats)
  • Remove from … import * at function scope. [done] This means that functionscan always be optimized and support for unoptimized functions can go away.
  • ImportsPEP 328
    • Imports will be absolute by default. [done]
    • Relative imports must be explicitly specified. [done]
    • Indirection entries insys.modules (i.e., a value ofNone forA.string means to use the top-levelstring module) will not besupported.
  • __init__.py might become optional in sub-packages? __init__.py will stillbe 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 parenthesizedPEP 308 [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.[33][34] [done]
  • Attributes on functions of the formfunc_whatever will be renamed__whatever__[17] [done]
  • 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.
  • The__nonzero__ special method will be renamed to__bool__and have to return a bool. The typeobject slot will be calledtp_bool[23] [done]
  • Dict comprehensions, as first proposed inPEP 274 [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[2] [done]
  • raiseException,"message": useraiseException("message")[12][done]
  • x: userepr(x)[2] [done]
  • The<> operator: use!= instead[3] [done]
  • The __mod__ and __divmod__ special methods on float. [they should stay][21]
  • Drop unbound methods[7][26] [done]
  • METH_OLDARGS [done]
  • WITH_CYCLE_GC [done]
  • __getslice__, __setslice__, __delslice__[32];remove slice opcodes and use slice objects. [done]
  • __oct__,__hex__: use__index__ inoct() andhex()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_UnTrackPyString_AsEncodedString, PyString_AsDecodedStringPyArg_NoArgs, PyArg_GetInt, intargfunc, intintargfunc

    PyImport_ReloadModule ?

Atomic Types

  • Remove distinction between int and long types; ‘long’ built-in type andliterals with ‘L’ or ‘l’ suffix disappear[1] [done]
  • Make all strings be Unicode, and have a separate bytes() type[1]The new string type will be called ‘str’. SeePEP 3137. [done]
  • Return iterable views instead of lists where appropriate for atomictype methods (e.g.dict.keys(),dict.values(),dict.items(), etc.); iter* methods will be removed. [done]
  • Makestring.join() stringify its arguments?[18] [NO]
  • Fix open() so it returns a ValueError if the mode is bad rather than IOError.[done]

To be removed:

  • basestring.find() andbasestring.rfind(); usebasestring.index()orbasestring.[r]partition() orbasestring.rindex() in a try/except block???[13] [UNLIKELY]
  • file.xreadlines() method[31] [done]
  • dict.setdefault()?[15] [UNLIKELY]
  • dict.has_key() method; usein operator [done]
  • list.sort() andbuiltin.sorted() methods: eliminatecmpparameter[27] [done]

Built-in Namespace

  • Make built-ins return an iterator where appropriate (e.g.range(),zip(),map(),filter(), etc.) [done]
  • Removeinput() and renameraw_input() toinput().If you need the old input(), use eval(input()). [done]
  • Introducetrunc(), which would call the__trunc__() method on itsargument; suggested use is for objects like float where calling__int__()has data loss, but an integral representation is still desired?[8] [done]
  • Exception hierarchy changesPEP 352 [done]
  • Add abin() function for a binary representation of integers [done]

To be removed:

  • apply(): usef(*args,**kw) instead[2] [done]
  • buffer(): must die (use a bytes() type instead) (?)[2] [done]
  • callable(): just use isinstance(x, collections.Callable) (?)[2] [done]
  • compile(): put insys (or perhaps in a module of its own)[2]
  • coerce(): no longer needed[2] [done]
  • execfile(),reload(): useexec()[2] [done]
  • intern(): put insys[2],[22] [done]
  • reduce(): put infunctools, a loop is more readable most of thetimes[2],[9] [done]
  • xrange(): userange() instead[1] [See range() above] [done]
  • StandardError: this is a relic from the original exception hierarchy;
    subclassException instead. [done]

Standard library

  • Reorganize the standard library to not be as shallow?
  • Move test code to where it belongs, there will be no more test() functionsin the standard library
  • Convert all tests to use either doctest or unittest.
  • For the procedures of standard library improvement, seePEP 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]
    • seePEP 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-oldPEP 4 [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[28],[35] [done]
  • sys.exc_type,sys.exc_values,sys.exc_traceback:not thread-safe; usesys.exc_info() or an attributeof the exception[2][11][28] [done]
  • sys.exc_clear: Python 3’s except statements provide the samefunctionality[24]PEP 3110[28] [done]
  • array.read,array.write[30]
  • operator.isCallable :callable() built-in is being removed[29][36] [done]
  • operator.sequenceIncludes : redundant thanks tooperator.contains[29][36] [done]
  • In the thread module, the acquire_lock() and release_lock() aliasesfor 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?[25]
  • Remove jumpahead() from the random API?[25]
  • Make the primitive for random be something generating random bytesrather than random floats?[25]
  • Get rid of Cookie.SerialCookie and Cookie.SmartCookie?[25]
  • Modify the heapq.heapreplace() API to compare the new value to the topof the heap?[25]

Outstanding Issues

  • Require C99, so we can use // comments, named initializers, declare variableswithout introducing a new scope, among other benefits. (Also better supportfor IEEE floating point issues like NaN and infinities?)
  • Remove support for old systems, including: BeOS, RISCOS, (SGI) Irix, Tru64

References

[1] (1,2,3,4,5)
PyCon 2003 State of the Union:https://legacy.python.org/doc/essays/ppt/pycon2003/pycon2003.ppt
[2] (1,2,3,4,5,6,7,8,9,10,11)
Python Regrets:https://legacy.python.org/doc/essays/ppt/regrets/PythonRegrets.pdf
[3] (1,2)
Python Wiki:https://wiki.python.org/moin/Python3.0
[4]
python-dev email (“Constancy of None”)https://mail.python.org/pipermail/python-dev/2004-July/046294.html
[5]
python-dev email (’ “as” to be a keyword?’)https://mail.python.org/pipermail/python-dev/2004-July/046316.html
[6]
python-dev email (“Comparing heterogeneous types”)https://mail.python.org/pipermail/python-dev/2004-June/045111.html
[7]
python-dev email (“Let’s get rid of unbound methods”)https://mail.python.org/pipermail/python-dev/2005-January/050625.html
[8]
python-dev email (“Fixing _PyEval_SliceIndex so that integer-likeobjects can be used”)https://mail.python.org/pipermail/python-dev/2005-February/051674.html
[9]
Guido’s blog (“The fate of reduce() in Python 3000”)https://www.artima.com/weblogs/viewpost.jsp?thread=98196
[10]
Guido’s blog (“Python Optional Typechecking Redux”)https://www.artima.com/weblogs/viewpost.jsp?thread=89161
[11]
python-dev email (“anonymous blocks”)https://mail.python.org/pipermail/python-dev/2005-April/053060.html
[12]
python-dev email (“PEP 8: exception style”)https://mail.python.org/pipermail/python-dev/2005-August/055190.html
[13]
python-dev email (Remove str.find in 3.0?)https://mail.python.org/pipermail/python-dev/2005-August/055705.html
[14]
python-dev email (Replacement for print in Python 3.0)https://mail.python.org/pipermail/python-dev/2005-September/056154.html
[15]
python-dev email (“defaultdict”)https://mail.python.org/pipermail/python-dev/2006-February/061261.html
[16]
python-3000 emailhttps://mail.python.org/pipermail/python-3000/2006-April/000996.html
[17]
python-3000 email (“Pronouncement on parameter lists”)https://mail.python.org/pipermail/python-3000/2006-April/001175.html
[18]
python-3000 email (“More wishful thinking”)https://mail.python.org/pipermail/python-3000/2006-April/000810.html
[19]
python-3000 email (“sets in P3K?”)https://mail.python.org/pipermail/python-3000/2006-April/001286.html
[20]
python-3000 email (“sets in P3K?”)https://mail.python.org/pipermail/python-3000/2006-May/001666.html
[21]
python-3000 email (“bug in modulus?”)https://mail.python.org/pipermail/python-3000/2006-May/001735.html
[22]
SF patch “sys.id() and sys.intern()”https://bugs.python.org/issue1601678
[23]
python-3000 email (“__nonzero__ vs. __bool__”)https://mail.python.org/pipermail/python-3000/2006-November/004524.html
[24]
python-3000 email (“Pre-peps on raise and except changes”)https://mail.python.org/pipermail/python-3000/2007-February/005672.html
[25] (1,2,3,4,5)
python-3000 email (“Py3.0 Library Ideas”)https://mail.python.org/pipermail/python-3000/2007-February/005726.html
[26]
python-dev email (“Should we do away with unbound methods in Py3k?”)https://mail.python.org/pipermail/python-dev/2007-November/075279.html
[27]
python-dev email (“Mutable sequence .sort() signature”)https://mail.python.org/pipermail/python-dev/2008-February/076818.html
[28] (1,2,3)
Python docs (sys – System-specific parameters and functions)https://docs.python.org/release/2.6/library/sys.html
[29] (1,2)
Python docs (operator – Standard operators as functions)https://docs.python.org/release/2.6/library/operator.html
[30]
Python docs (array – Efficient arrays of numeric values)https://docs.python.org/release/2.6/library/array.html
[31]
Python docs (File objects)https://docs.python.org/release/2.6/library/stdtypes.html
[32]
Python docs (Additional methods for emulation of sequence types)https://docs.python.org/release/2.6/reference/datamodel.html#additional-methods-for-emulation-of-sequence-types
[33]
Approach to resolving __builtin__ vs __builtins__https://mail.python.org/pipermail/python-3000/2007-March/006161.html
[34]
New name for __builtins__https://mail.python.org/pipermail/python-dev/2007-November/075388.html
[35]
Patch to remove sys.exitfunchttps://github.com/python/cpython/issues/44715
[36] (1,2)
Remove deprecated functions from operatorhttps://github.com/python/cpython/issues/43602

Copyright

This document has been placed in the public domain.


Source:https://github.com/python/peps/blob/main/peps/pep-3100.rst

Last modified:2025-02-01 08:55:40 GMT


[8]ページ先頭

©2009-2025 Movatter.jp