Speaker Anthony Baxter
Time 2008-02-01 09:00
Conference LCA2008

Python 3.0

  • release where we break all your code.
  • would this cute kitten lie to you?
  • backwards incompatable, rather a lot.
  • every program will need some big changes. sorry.

Changes:

  • print becomes a function print()
  • unicode strings default
  • byte strings if required and specified
  • set literals - remove syntax ambigiouty
  • set dict comprehensions
  • function annotations, define types for function parameters and return
  • new style division = 1/0 no longer 0, now 0.5
  • iterators everywhere, what the hell, we a breaking everyones code, lets fix it
  • dictionary views
  • new I/O layer to replace standard IO, standard IO not very standard.
  • standard library reorganisation - standard library known as batteries included part of python - includes everything
    • standard library names don’t comply with standard. Also make library hierarchy structure.
  • stuff going away
    • old style classes going away, old style classes confusing
    • string exceptions; can’t attach non-string objects to exceptions; this will be fixed
    • <> - not equals - now !=
    • dict.has_key() changed
    • apply() is very slow - goodbye
    • reduce() takes list and operator, only used to add bunch of numbers, replace with sum()
    • coerce()
    • str.find() is confusing, so removing them
  • 2.x is not going away. 2.6 will be released, about the same time as 3.0 (sometime in the next 12 months), and 2.7 will be release. 2.9 will be the absolutely last 2.x release, and security fixes will continue.
  • migration tools will be provided
    • 2to3
    • -Wpy3k - warnings for python 3 mode.

Why?

Python has annoying features. eg blink tag in HTML.

Example:

  • backticks syntax for repr()
  • syntax shouldn’t look like a dead pixel on the screen.

Python breaks its on rules:

  • There is only one (right) way to do it. Why do we have:
    • map and list
    • string functions and methods
    • etc
    • usual reason, is a better solution is found, and backwards compatability required.
  • “Python fits in your brain”
    • Except for regular expressions which make no sense.
    • brains are limited
    • no longer applies, language has grown

Python is great language for teaching to kids, easy to learn.

  • How to think like a (Python) Programmer, by Allen B. Downey, available for free on the Internet.

Language complexity

  • 1.0.1 (1994): 40 builtins
  • 1.5.2 (1999): 54 builtins (development stalled)
  • 2.1 (2001) 69 builtins
  • 2.5 (2006) 82 builtins

Lots of builtins are rubbish, e.g.:

  • apply()
  • callable()
  • input() vs raw_input() - raw_input() is better, input() uses eval().

People constantly bounce in and out of languages. Context switch. Simplier language is a huge benefit.

Python - executable pseudocode - simpler is better - keep the language in your brain.

migration strategies

  • we have lots of code too
  • conversion program
    • unit tests recommended
    • suggested workflow will be suggested
    • automatic conversion program won’t be able to do everything
  • mode for warning about 3.x problems in 2.x
  • from_future_import to import feature from 3.x into 2.6 and more in 2.7
  • -3 flag, gradual migration

Other stuff

  • massive code change
  • python will remain using whitespace for marking blocks
  • multi line lambdas
  • remove the GIL, use processes instead of threads, threads are evil
  • not rewriting the interpreter
  • avoid serious hacks, they hurt portability, and hurt developers
  • python on mono or .net
    • Microsoft open source - BSD style license
    • can’t accept patches
  • jython - running on jvm - stalled project

Summary

3.0 is our one change. No intention of ever doing this again. Won’t be a 4.0 ever.

2.x is not going away. 3.0 is the future. It is a 2 snake future.

Questions

Timeframe involved in 3.0?

  • started about a year ago
  • will still be a couple of years work
  • so much work required
  • without a rewrite

2.5.2 about to come out soon.

we will keep maintaining 2.x as long as there is interest.

Changes to C code not mentioned in this talk.

Not appropriate for new users to start using 3.0 when it is released, wait at least 6 months.

We don’t break things between maintaince releases, but 3.1 might break things if we have to.

“Teaching C++ to first years is child abuse”

“Every language steals from every other language, they might as well steal from the best.”