state of the python union oscon portland, oregon july 29, 2004 guido van rossum elemental security,...

29
State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. [email protected] [email protected]

Upload: grace-craig

Post on 27-Mar-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

State of thePython Union

OSCONPortland, Oregon

July 29, 2004

Guido van Rossum

Elemental Security, Inc.

[email protected]@elementalsecurity.com

Page 2: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 2

Page 3: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 3

Keynote Overview

• PSF Grants

• Release status

• Python 2.4:

– Generator expressions

– Decorators

– Other news

• Beyond Python 2.4

• Miscellaneous remarks

• Cute demos

• Question time

Page 4: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 4

Page 5: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 5

PSF Grants

• Grants for projects related to:– the further development of Python

– Python-related technology

– educational resources

• Proposals to be submitted by October 1, 2004– proposals granted by November 1, 2004

– work to be completed by October 30, 2005

• Up to $40,000 available in total

• See python.org for details and how to submit

Page 6: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 6

Page 7: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 7

Release Status

• Python 2.2 is resting ("pining for the fjords")

• Python 2.3 is actively maintained

– 2.3.4 came out in May

– 2.3.5 planned later this year

– Anthony Baxter is release manager

• I am out of the loop!

• Python 2.4 alpha 2 to be released next week

– 2.4 final release expected Q4 2004

– Anthony Baxter is release manager

• I am mostly out of the loop!

Page 8: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 8

Page 9: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 9

Generator Expressions

• Consider: print sum(x**2 for x in range(10))

• Compare:

– total = 0for x in range(10): total += x**2print total

• Factor out summing algorithm for reuse

• Concentrate on providing input without distractions

• Easily switch between different data processors

– "accumulator functions"

– "iterator algebra" a.k.a. pipelining

Page 10: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 10

Why Generator Expressions?

• Notation is immediately understandable

• Avoids building up a list of intermediate results– This is especially important if:

• intermediate results are large; or

• there are many intermediate results; or

• the source is an infinite sequence– e.g. from itertools: count(), cycle(), repeat()

• the consumer doesn't consume all results

• an interactive user is waiting for the initial results

• List comprehensions are a special case:– [f(x) for x ...] is syntactic sugar for list(f(x) for x ...)

• (in Python 2.4 there are some corner cases with different semantics; these will be fixed in 3.0)

• won't go away

Page 11: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 11

The Generator Expression Debate

• Someone noticed an "implementation flaw":– a = []

for f in [math.sin, math.cos, math.tan]: a.append(f(x) for x in range(10))

– for iterator in a: for x in iterator: print x, print

– Prints math.tan(x) series three times! (f is bound late)

• Should we try to fix this? (If so, how?)

• NO! Genexps are for immediate consumption– fix the docs / tutorials / examples

– delayed use would be expert/advanced use anyway• working solutions are quite bearable

Page 12: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 12

Page 13: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 13

Decorators

• Consider (introduced in python 2.2):

– class C: def func(args): ...100 lines of body text... func = staticmethod(func)

• Problem with this syntax:

– programmer may forget to add the staticmethod() call

– reader may miss the staticmethod() call

• Proposed solution:

– class C: ***DECORATOR SYNTAX*** func(args): body

Page 14: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 14

What Is a Decorator?

• A decorator is a meta-function:

– input is a callable or descriptor (implements __get__)

– output is a callable or descriptor

– examples: classmethod, staticmethod, (property)

• Other use cases:

– metadata (e.g. author, version, deprecation)

– processing rules (e.g. SPARK's grammar rules)

– support for external language bindings (ObjC, C#)

– framework annotations (e.g. PIKE)

• Ideally, decorators should be chainable

Page 15: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 15

Decorator Syntax Candidates

• Java 1.5:– @decorator and/or @decorator(key=value, ...)

• C#:– [decorator, decorator, ...]

• Other proposals from Python developers:– [decorator, decorator, ...] in various other positions

– *[decorators]*

– <decorators>

– [as decorators]

– other keywords or symbols

Page 16: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 16

Decorator (Ab)uses

• def funcattrs(**kwds): def helper(func): func.__dict__.update(kwds) return func return helper

• Example with Java 1.5-derived syntax:

– @funcattrs(grammar="blah", author="GvR")def blah(args): body

• Example with C#-derived syntax:

– [funcattrs(grammar="blah", author="GvR")]def blah(args): body

Page 17: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 17

Which Decorator Syntax?

• All styles have their disadvantages:

– @decorator

• looks unpythonic (?)

– [deco, deco, ...] prefix

• ambiguous syntax

• and doesn't work in interactive interpreter

– [deco, deco, ...] after arguments

• hides the decorators too much

• is awkward for long decorators

– Other proposals look arbitrary (even 'as')

• In 2.4a2, we'll implement @decorator

– if everybody hates it, we'll revisit in a3 or b1

Page 18: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 18

Page 19: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 19

What Else is New in 2.4?

• Faster (e.g. tklife.py gains ~20% speed-up)

• New built-in set types: set and frozenset

• Unifying int and long: now always the same results– except repr() still returns an 'L' suffix for longs

• New builtins: sorted(), reversed()

• Keyword arguments to list.sort(): cmp, key, reverse

• eval() takes arbitrary mapping for locals (only)

• None is a constant (assigning to it is a syntax error)

• Decimal floating point data type (module decimal)

• Email parser rewritten from scratch

• CJKCodecs integrated (East-Asian codecs)

• New module cookielib (client-side cookie handling)

• Windows distribution now built using MSVC++ 7.1

Page 20: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 20

Page 21: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 21

Beyond Python 2.4

• Python 2.5.........2.9:

– gradual improvements

– new library modules/packages

– backwards-compatible changes

– implement more existing PEPs

– performance work

– implementation internals work (e.g. AST branch)

– experiment with features proposed for Python 3.0

• There will not be a Python 2.10

– but 2.5 ... 2.9 may be released in parallel with 3.0

Page 22: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 22

Page 23: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 23

Python 3.0 (a.k.a. Python 3000)

• I had a Python 3.0 slide, but it's all day-dreaming

• 3.0 is my excuse for putting off thorny issues

• Has been "about 3 years away" since 2000 :-)

• I need to retire to be able to work on this

• Python 3.0 : 2.x isn't anything like Perl 6.0 : 5.x

• But it will be incompatible

Page 24: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 24

Page 25: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 25

Miscellaneous Remarks

• The sincerest form of flattery is imitation– Python borrows from many other languages

– Now Ruby, Groovy, Prothon borrow from Python

• Python runs on Nokia Series 60 phones– Public release not yet certain

– Would open up Nokia platform to more developers

• Write your secure programs in Python– 1 security defect per 1000 lines across languages

– But in Python it takes fewer lines :-)

• Community issues– Why is there still no Python equivalent of CPAN?

– There are too many projects doing X; how to choose?

Page 26: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 26

Page 27: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 27

Cute Demos

• ElementClass

– Simple way to describe (some) XML documents

– Get attributes and subelements as Python attributes

– Parses string or stream into tree in memory

– Renders to string or stream

– Not (yet) released, developed for Elemental Security

• Conway's Game of Life / Damian's cellular automata

Page 28: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

July 29, 2004 © 2004 Guido van Rossum 28

Page 29: State of the Python Union OSCON Portland, Oregon July 29, 2004 Guido van Rossum Elemental Security, Inc. guido@python.org guido@elementalsecurity.com

Question Time