Python 3000 and You. Guido van Rossum EuroPython July 7, 2008

Similar documents
Python 3000 and You. Guido van Rossum PyCon March 14, 2008

Single Source Python 2 3

Python - a Dynamic Programming Language. Guido van Rossum May 31, 2007

Beyond Blocks: Python Session #1

CSCE 110 Programming I

Porting Python 2 Code to Python 3 Release 2.7.6

The State of Python. and the web. Armin Ronacher

Python Reference (The Right Way) Documentation

CIS192: Python Programming

redis-lua Documentation

What's New in Python 2.2

Babu Madhav Institute of Information Technology, UTU 2015

Outline. Simple types in Python Collections Processing collections Strings Tips. 1 On Python language. 2 How to use Python. 3 Syntax of Python

Guido van Rossum 9th LASER summer school, Sept. 2012

Practical uses for. Function Annotations. Manuel Ceron

GIS 4653/5653: Spatial Programming and GIS. More Python: Statements, Types, Functions, Modules, Classes

Table of Contents EVALUATION COPY

Python 3 10 years later

pybdg Documentation Release 1.0.dev2 Outernet Inc

CNRS ANF PYTHON Objects everywhere

Algorithms and Programming I. Lecture#12 Spring 2015

Ruby: Introduction, Basics

(CC)A-NC 2.5 by Randall Munroe Python

About Python. Python Duration. Training Objectives. Training Pre - Requisites & Who Should Learn Python

PYTHON FOR MEDICAL PHYSICISTS. Radiation Oncology Medical Physics Cancer Care Services, Royal Brisbane & Women s Hospital

COMP519 Web Programming Lecture 17: Python (Part 1) Handouts

Ruby: Introduction, Basics

CS 11 python track: lecture 3. n Today: Useful coding idioms

Python 2-to-3 Migration Guide

CIS192 Python Programming. Robert Rand. August 27, 2015

Introduction to Python for IBM i

Senthil Kumaran S

msgpack Documentation

Python INTRODUCTION: Understanding the Open source Installation of python in Linux/windows. Understanding Interpreters * ipython.

funcsigs Documentation

DaMPL. Language Reference Manual. Henrique Grando

CMSC 330: Organization of Programming Languages. Rust Basics

Using Type Annotations in Python. by Philippe Fremy / IDEMIA

The float type and more on variables FEB 6 TH 2012

Exceptions & a Taste of Declarative Programming in SQL

Final thoughts on functions F E B 2 5 T H

Project 6 Due 11:59:59pm Thu, Dec 10, 2015

Programming in Python

21 Years of Python. From Pet Project to Programming Language of the Year. Guido van Rossum May 2011

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

Fluent Python. Luciano Ramalho. Tokyo O'REILLY. Beijing. Sebastopol. Farnham. Boston

3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017

And Parallelism. Parallelism in Prolog. OR Parallelism

django-crucrudile Documentation

Ruby: Introduction, Basics

Java Bytecode (binary file)

Guido van Rossum 9th LASER summer school, Sept. 2012

Announcements for this Lecture

OOP and Scripting in Python Advanced Features

Python Basics. Lecture and Lab 5 Day Course. Python Basics

CS 360 Programming Languages Interpreters

About Variables in Python F E B 1 1 T H

Modules and scoping rules

Notes from a Short Introductory Lecture on Scala (Based on Programming in Scala, 2nd Ed.)

Introduction to Scientific Python, CME 193 Jan. 9, web.stanford.edu/~ermartin/teaching/cme193-winter15

ARG! Language Reference Manual

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Sequence types. str and bytes are sequence types Sequence types have several operations defined for them. Sequence Types. Python

Data Structures (list, dictionary, tuples, sets, strings)

Project 5 Due 11:59:59pm Wed, Nov 25, 2015 (no late submissions)

PYTHON TRAINING COURSE CONTENT

Python Workshop. January 18, Chaitanya Talnikar. Saket Choudhary

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

egrapher Language Reference Manual

Getting Started. Office Hours. CSE 231, Rich Enbody. After class By appointment send an . Michigan State University CSE 231, Fall 2013

The WSGI Reference Library

Python 3: The Next Generation

TH IRD EDITION. Python Cookbook. David Beazley and Brian K. Jones. O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Tokyo

PTN-102 Python programming

COMP1730/COMP6730 Programming for Scientists. Testing and Debugging.

Lecture #12: Quick: Exceptions and SQL

DEBUGGING TIPS. 1 Introduction COMPUTER SCIENCE 61A

python-aspectlib Release 0.4.1

python-aspectlib Release 0.5.0

Index. Cache, 20 Callables, 185 call () method, 290 chain() function, 41 Classes attributes descriptors, 145 properties, 143

Positional, keyword and default arguments

Advanced Python. Executive Summary, Session 1

STSCI Python Introduction. Class URL

contacts= { bill : , rich : , jane : } print contacts { jane : , bill : , rich : }

1 Decorators. 2 Descriptors. 3 Static Variables. 4 Anonymous Classes. Sandeep Sadanandan (TU, Munich) Python For Fine Programmers July 13, / 19

Connexion Documentation

Topic 1: Introduction

Swift. Introducing swift. Thomas Woodfin

archery Documentation

Big Bang. Designing a Statically Typed Scripting Language. Pottayil Harisanker Menon, Zachary Palmer, Scott F. Smith, Alexander Rozenshteyn

CMPT 120 Basics of Python. Summer 2012 Instructor: Hassan Khosravi

Requests Mock Documentation

Programming. We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems.

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

Getting started with Java

Perl. Many of these conflict with design principles of languages for teaching.

Data type built into Python. Dictionaries are sometimes found in other languages as associative memories or associative arrays.

Sorting HOW TO Release 2.7.6

Python I. Some material adapted from Upenn cmpe391 slides and other sources

Transcription:

Python 3000 and You Guido van Rossum EuroPython July 7, 2008

Why Py3k Open source needs to move or die Matz (creator of Ruby) To fix early, sticky design mistakes e.g. classic classes, int division, print statement Changing times: time/space trade-off e.g. str/unicode, int/long New paradigms come along e.g. dict views, argument annotations

Major Breakages Print function: print(a, b, file=sys.stderr) Distinguish sharply btw. text and data b" " for bytes literals " " for (Unicode) str literals Dict keys() returns a set view [+items()/values()] No default <, <=, >, >= implementation 1/2 returns 0.5 Library cleanup and reorganization

Long Anticipated Breakages Kill classic classes Int/long unification Kill string exceptions Exceptions must subclass BaseException Raise syntax: raise Exc(args) [from tb] Except syntax: except Exc as var: Also makes var undefined at block exit

Many Small Breakages Remove cmp() builtin Remove cmp arg to sorted() and list.sort() Kill map(none, ); use zip() map(), filter() return iterators Disallow int( - 1 ) Explicit relative import Removed ` ` Removed <> None, True, False are keywords New keywords as, with, nonlocal raw_input() -> input() xrange() -> range() Changed metaclass syntax Kill compiler package Kill tuple parameters e.g. def f(a, (b, c)):... New octal literals (0o777).next() ->. next (); next() built-in.func_code ->. code Removed dict.has_key() Removed dict.iteritems() etc. Removed sys.maxint; use sys.maxsize Removed reload(); use imp.reload() Removed reduce(); use functools.reduce() Removed apply(); use f(*args) Removed callable(); use Callable ABC Removed basestring; use str. nonzero () ->. bool () Must override hash when defining eq Module builtin renamed to builtins (no ) Removed many modules, e.g. gopherlib, cfmfile, md5 (use hashlib), mimify (use email pkg), and all the MacOS 9 support Etc, etc.

Major New Features, e.g. Argument annotations: def f(a: 2*2, b: 'hello') -> 42: Abstract Base Classes Extended iterable unpacking: a, b, *x, y = range(5) # 0, 1, [2, 3], 4 New str.format() method: "Got {0} {kind}".format(42, kind='bugs') "Got 42 bugs"

Many Smaller Improvements I/O no longer depends on C <stdio.h> Source code encoding defaults to UTF-8 Allow Unicode letters in names Class decorators prepare () method on metaclass Nonlocal statement Keyword-only arguments Default implementation of!= negates == Binary literals 0b10101, bin() function Mutable bytes type (bytearray) Overloadable isinstance(), issubclass() fractions.py defines Fraction type super() without arguments Set literals and set comprehensions Dict comprehensions New exception attributes: traceback cause (raise <exc> from <cause>) context (when raised in handler) Exceptions aren t sequences; use e.args Abstract Base Classes: In abc.py: infrastructure In collections.py: Set, Sequence, Mapping, MutableSet etc. In numbers.py: Number, Complex, Real, Rational, Integer In io.py: IOBase and more New modules e.g. json, multiprocessing Etc, etc.

What s In It For You More predictable Unicode handling Smaller language Makes Python fits in your brain more true TOOWTDI (There s Only One Way To Do It -- The Zen of Python) Common traps removed Fewer surprises Fewer exceptions

Enables Future Evolution Examples: Argument annotations print() function str.format() method Abstract Base Classes Unicode letters in names

The 2to3 Tool Context-free source code translator Handles syntactic changes best E.g. print; ` `; <>; except E, v: Handles built-ins pretty well E.g. xrange(), apply(), d.keys() Doesn t do type inferencing Doesn t follow variables in your code

When To Switch No hurry! 2.6 will be fully supported Probably 3-5 years or more Release of 2.7 possible, maybe even 2.8 Switch when both of these are true: 1. You re ready 2. All your dependencies have been ported There are tools to help you switch!

Be Prepared Start writing future-proof code for 2.5 Don t bother with the trivial stuff though: The 2to3 tool will handle this E.g. callable(), ` `, <>, L suffix Instead, focus on what 2to3 can t do: Stop using obsolete modules Start using iterators and generators

Things You Can Do Now Inherit classes from object Use dict.iterkeys() etc. Use xrange(), sorted(), zip() Use // for floor division Inherit exceptions from [Base]Exception Use rich comparisons ( eq etc.) Etc., etc.

What About Text Handling There's no silver bullet Isolate handling of encoded text In 2.6: Use bytes and b' ' for all data Knowing these are just aliases for str and ' ' Use unicode and u'...' for all text In 2.5: '...' for data, u'...' for text

The Role of Python 2.6 Stable, compatible, supported! Many 3.0 features backported But not the new text / data distinction Warns about non-3.0-isms with -3 flag Especially for things that 2to3 can't fix

Transition Strategies If you can: burn your bridges! :-) Otherwise: Port to 2.6 first Maintain 2.6 and 3.0 version together Derive 3.0 version from 2.6 source Using 2to3 whenever you can Using forked code only where you have to Enables feature parity of your app or lib

Porting C Extensions Fork your code or sprinkle with #ifdef We try to delete APIs or add new ones But not break existing APIs that stay I.e. number & type of arguments won't change 2.6: str, unicode -> PyString, PyUnicode PyBytes is an alias for PyString 3.0: bytes, str -> PyBytes, PyUnicode Also: PyInt vs. PyLong

Release Schedule Releasing 2.6 and in lock step beta 1: June 18 (just released!) beta 2: July 15 (coming up next!) beta 3: August 23 release candidates: Sept 3, Sept 17 final release: October 1

I Have This Great Idea If your idea hasn t made it into 3.0 yet, it s definitely too late to get it in Current focus is on: Fixing bugs Perfecting backwards compatibility Improving performance

Wrapping Up Don t fear Py3k! Have fun with the new features Enjoy fewer bugs, traps, surprises Take your time to convert! You will get lots of time, lots of help 2.6 will be stable, compatible, supported For many years to come!

Resources Docs: docs.python.org/dev/3.0/ docs.python.org/dev/3.0/whatsnew/3.0.html Download: python.org/3.0/ PEPs: python.org/dev/peps/pep-3000/ Mailing list: python-3000@python.org Subversion: svn.python.org/view/python/branches/py3k/