Python3.0

Legacy Wiki Page

This page was migrated from the old MoinMoin-based wiki. Information may be outdated or no longer applicable. For current documentation, see python.org.

This page lists features that Guido van Rossum himself has mentioned as goals for Python 3.0. Parts of this page have been consolidated into PEP 3000 [5]

Status

Python 3.0 is currently (2008-07-12) in beta testing, and has much accumulated documentation. More official sources of information include:

Unfortunately there does not appear to be a well-maintained single point of entry for someone to find all relevant changes that will occur in Python 3.0.

Core Language Changes

  • Remove distinction between int{.backtick} and long{.backtick} types. [4]

  • Make true division the default behavior. [4]

  • Make all strings unicode [4], and have a separate bytes{.backtick} [2] type. [13]

  • Make the exec{.backtick} statement a function again. [1]

  • Remove old-style classes. [4]

  • Replace the print{.backtick} statement with a function or functions. (e.g. write(x, y, z), writeline(x, y, z){.backtick}) [1] [21]

  • Make as{.backtick} a real keyword. [7]

  • Add an attribute to exceptions for storing the traceback. [22]

  • Remove raise Exception, 'message'{.backtick} syntax in favor of raise Exception('message'){.backtick}. [11] [20]

  • Require that the first statement of a suite be on its own line. [1]

  • Make True{.backtick} and False{.backtick} keywords. [6]

    • Reason: make assignment to them impossible.

  • Raise an exception when making comparisons (other than equality and inequality) between two incongruent types. [24]

    • Reason: such comparisons do not make sense and are especially confusing to new users of Python.

  • Require that all exceptions inherit a common base class. [9]

    • Reason: forces the use of classes as objects raised by exceptions and simplifies the implementation.

  • Make the traceback a standard attribute of Exception instances [18]

    • Reason: inconvenient to pass the (type, value, traceback) triple that currently represents an exception around.

  • Remove `x`. [1]

    • Instead: use repr(x){.backtick}.

    • Reason: backticks are hard to read in many fonts and can be mangled by typesetting software.

  • Remove the <>{.backtick} operator.

    • Instead: use !={.backtick}.

  • Remove support for string exceptions. [1]

    • Instead: use a class.

  • Add a mechanism so that multiple exceptions can be caught using except E1, E2, E3:{.backtick}. For instance:

       1 except E1, E2, E3 as err:  # Store error variable
       2    ...
    

    (Added by GvR, suggested by Bram Cohen.)

    • JimD’s suggested syntax:

         1 except (E1, E2, E3), e:
         2    ...
         3 
         4 except E1, e:
         5    ...
      

      The except{.backtick} code would then basically do the equivalent of if issubclass(arg1, Exception) or isinstance(arg1, Exception): ... else if len(arg1): ...{.backtick} (excepting, obviously, that this is implemented at a lower level in the C core). –JimD

  • Perhaps have optional declarations for static typing.

    • GvR suggested the syntax [17]: (but NOT for static typing - for declaring type information that would be checked at runtime, not compile time)

         1 def bar(low: int, high: int) -> float:
         2     ...
      
    • Since some types only implement parts of an interface have ‘strict’ and ‘lax’ interfaces. Strict requires a complete implementation of the interface, lax requiring only a partial implementation with the rest being taken from interface defaults or ignored. This would require a new keyword/reserved word (strict) with lax mode being the default. This is to help duck typing. Ex:

         1 def baz(x as list, y as strict file):
         2     # x must only (be adapted to) implement part of the list interface
         3     # y must (be adapted to) implement the whole file interface
      
    • Another proposal: Use -> and => as type conversion operators (lax and strict, respectively).

         1 def qux(x -> list, y => file):
         2     # x must only (be adapted to) implement part of the list interface
         3     # y must (be adapted to) implement the whole file interface
      

Built-In Changes

  • Have range(){.backtick}, zip(){.backtick}, dict.keys(){.backtick}, dict.items(){.backtick}, and dict.values(){.backtick} return iterators.

  • Move compile(){.backtick}, intern(){.backtick} and id(){.backtick} to the sys{.backtick} module. [1]

  • Change max(){.backtick} and min(){.backtick} to consume iterators.

  • Remove coerce(){.backtick} as it is obsolete. [1]

  • Introduce trunc(){.backtick}, which would call the __trunc__(){.backtick} method on its argument.

    • Reason: used for objects like float{.backtick}s where calling __int__(){.backtick} has data loss but an integral representation is still desired. [25]

  • Remove dict.iteritems(){.backtick}, dict.iterkeys(){.backtick}, and dict.itervalues(){.backtick}.

    • Instead: use dict.items(){.backtick}, dict.keys(){.backtick}, and dict.values(){.backtick} respectively.

  • Remove apply(){.backtick}. [1]

    • Instead: use f(*args, **kw){.backtick}.

  • Remove xrange(){.backtick}. [1] [4]

    • Instead: use range(){.backtick}.

  • Remove reduce(){.backtick}. [1]

    • Instead: use functools.reduce(){.backtick}.

  • Remove callable(){.backtick}. [1]

    • Instead: use hasattr{.backtick} to check for __call__{.backtick} attribute.

  • Remove buffer(){.backtick}. [1] [2]

    • Instead: use new bytes{.backtick} type.

  • Remove raw_input(){.backtick}. [1]

    • Instead: use input(){.backtick}.

  • Remove input(){.backtick}. [1]

    • Instead: use eval(input()){.backtick}.

  • Remove execfile(){.backtick} and reload(){.backtick}. [1]

    • Instead: use exec(){.backtick}.

  • Remove basestring.find(){.backtick} and basestring.rfind(){.backtick}. [23]

    • Instead: use basestring.index(){.backtick} and basestring.rindex(){.backtick} in a try/except{.backtick} block.

Standard Library Changes

  • Remove types{.backtick} module.

    • Instead: use the types in __builtins__{.backtick}.

  • Remove other deprecated modules. [3]

  • Remove sys.exc_type{.backtick}. [1]

    • Instead: use sys.exc_info{.backtick}.

    • Reason: it is not thread safe.

  • Reorganize standard library to have more package structure.

    • Reason: there are too many modules to keep a flat hierarchy.

Open Issues

  • L += x{.backtick} and L.extend(x){.backtick} are equivalent. No, they are not. The former creates a new list without modifying the original list (which other people might have references to). The latter modifies the original list.

  • Can the parameter order of the insert{.backtick} method be changed so the the index parameter is optional and list.append{.backtick} may be removed?

  • If only Exception{.backtick} subclasses can be raise{.backtick}d [9], should the raise{.backtick} statement be kept? Could x(y).raise(){.backtick} be used instead?

  • Are repr(){.backtick} and str(){.backtick} both needed? [1]

  • Should globals(){.backtick}, locals(){.backtick} and vars(){.backtick} be removed? [1]

  • Should there be a keyword for allowing the shadowing of built-ins?

  • Should injecting into another module’s global namespace be prevented?

  • If line continuations (\{.backtick}) are removed from the language [1], what should be done about the instances where statements do not allow parentheses? Furthermore, the Python style guide [11] recommends their usage in some cases.

  • Should __cmp__{.backtick} (and possibly cmp(){.backtick}) be removed? [8]

    • Reason: TOOWTDI and rich comparisons are another way.

  • Should list comprehensions be equivalent to passing a generator expression to list(){.backtick}?

    • Reason: they are essentially the same and it would remove edge-case differences between them.

  • With a new string substitution scheme [14], will old-style (%(var)s{.backtick}) substitutions be removed?

  • There are things in the string{.backtick} module that I think belong there, for example string.letters{.backtick} and string.digits{.backtick}. I don’t think that all the string manipulations that we might include with the standard libraries need to be in the core interpreter (any more than I would condone putting the regular expression engine into the core). – JimD

  • Should a with{.backtick} (or using{.backtick}) statement be added? [10] [19]

       1 with self:
       2     .foo = [1, 2, 3]
       3     .bar(4, .foo)
    

References