Python Evolution


Published on

Python 2.x features: Python versions 2.4, 2.5, 2.6.
Why Python 3k? Distribution as competitive benefit

Published in: Technology, Education
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Python Evolution

  1. 1. Python Evolution 2.4, 2.5, 2.6, 3.0 by Myroslav Opyr, CTO © Quintagroup 2008
  2. 2. Contents <ul><ul><li>Python 2.x features </li></ul></ul><ul><ul><ul><li>2.4 </li></ul></ul></ul><ul><ul><ul><li>2.5 </li></ul></ul></ul><ul><ul><ul><li>2.6 </li></ul></ul></ul><ul><ul><li>Why Python 3k? </li></ul></ul><ul><ul><li>Distribution as competitive benefit </li></ul></ul><ul><ul><li>References </li></ul></ul>
  3. 20. Python 2.4 features <ul><ul><li>built-in sets ( PEP 218 ) </li></ul></ul><ul><ul><li>generator expressions ( PEP 289 ) </li></ul></ul><ul><ul><li>new subprocess module (PEP 324) </li></ul></ul><ul><ul><li>function/method decorators ( PEP 318 ) </li></ul></ul>
  4. 21. Python 2.5 features <ul><ul><li>abstract syntax tree (AST) </li></ul></ul><ul><ul><li>'with' statement ( PEP 343 ) </li></ul></ul><ul><ul><li>absolute/relative imports ( PEP 328 ) </li></ul></ul><ul><ul><li>distutils gained dependency info ( PEP 314 ) </li></ul></ul><ul><ul><li>wsgiref package ( PEP 333 ) </li></ul></ul><ul><ul><li>coroutines ( PEP 342 ) </li></ul></ul><ul><li>Non-features </li></ul><ul><ul><li>PyPI accepts uploads </li></ul></ul><ul><ul><li>Continuous Integration with buildbot </li></ul></ul>
  5. 22. Python 2.6 features <ul><ul><li>no more string exceptions </li></ul></ul><ul><ul><li>The &quot;bytes&quot; Object (PEP 358) </li></ul></ul><ul><ul><li>warnings for features to be removed in P3k </li></ul></ul><ul><ul><li>multiprocessing (PEP 371) </li></ul></ul><ul><ul><li>ast module </li></ul></ul><ul><ul><li>setuptools module </li></ul></ul><ul><ul><li>2to3 </li></ul></ul><ul><li>Non-features </li></ul><ul><ul><li>Python bugtracker moved to roundup </li></ul></ul>
  6. 23. Questions? <ul><li>  </li></ul>
  7. 24. pause...
  8. 25. Python 3k/3000/3.0 <ul><ul><li>Incompatible changes </li></ul></ul><ul><ul><ul><li>What Python 3.0 won't be </li></ul></ul></ul><ul><ul><ul><li>What Python 3.0 will be </li></ul></ul></ul><ul><ul><li>Release Plan </li></ul></ul><ul><ul><li>Migration process </li></ul></ul><ul><ul><ul><li>2to3 </li></ul></ul></ul>
  9. 26. Python 3.0. Evolution philosophy <ul><li>Joel on Software: Things You Should Never Do, Part I: </li></ul><ul><ul><li>Netscape was waiting so long between releases by making the single worst strategic mistake that any software company can make: </li></ul></ul><ul><ul><li>They decided to rewrite the code from scratch. </li></ul></ul><ul><li> </li></ul>
  10. 27. What Python 3.0 won't be <ul><li>PEP-3099 highlights: </li></ul><ul><ul><li>Python 3000 will not be case-insensitive </li></ul></ul><ul><ul><li>Python 3000 will not be a rewrite from scratch </li></ul></ul><ul><ul><li>self will not become implicit </li></ul></ul><ul><ul><li>lambda will not be renamed </li></ul></ul><ul><ul><li>No braces (from __future__ import braces) </li></ul></ul><ul><ul><li>Iterating over a dictionary will continue to yield the keys </li></ul></ul><ul><ul><li>The interpreter prompt (>>>) will not change. It gives Guido warm fuzzy feelings </li></ul></ul>
  11. 28. What Python 3.0 will be <ul><li>PEP-3000 Python 3.0 development guidelines: </li></ul><ul><ul><li>PEP Numbering </li></ul></ul><ul><ul><li>Timeline </li></ul></ul><ul><ul><li>Compatibility and Transition </li></ul></ul><ul><ul><li>Implementation Language </li></ul></ul><ul><li>PEP-3100 Python 3.0 implementation </li></ul><ul><ul><li>&quot;reduce feature duplication by removing old ways of doing things. A general principle of the design will be that one obvious way of doing something is enough.&quot; </li></ul></ul>
  12. 29. Python 3.0. Core language <ul><ul><li>True division becomes default behavior </li></ul></ul><ul><ul><li>exec as a statement is not worth it -- make it a function </li></ul></ul><ul><ul><li>Add optional declarations for static typing (annotations) </li></ul></ul><ul><ul><li>Support only new-style classes; classic classes will be gone </li></ul></ul><ul><ul><li>Replace print by a function </li></ul></ul><ul><ul><li>The softspace attribute of files goes away. </li></ul></ul><ul><ul><li>Use except E1, E2, E3 as err: if you want the error variable. </li></ul></ul><ul><ul><li>None becomes a keyword; also True and False </li></ul></ul><ul><ul><li>as becomes a keyword </li></ul></ul><ul><ul><li>Comparisons other than == and != between disparate types will raise an exception unless explicitly supported by the type </li></ul></ul>
  13. 30. Python 3.0. Core language (cont.) <ul><ul><li>floats will not be acceptable as arguments in place of ints for operations where floats are inadvertantly accepted </li></ul></ul><ul><ul><li>Remove from ... import * at function scope. </li></ul></ul><ul><ul><li>Imports </li></ul></ul><ul><ul><ul><li>Imports will be absolute by default. </li></ul></ul></ul><ul><ul><ul><li>Relative imports must be explicitly specified. </li></ul></ul></ul><ul><ul><li>Some expressions will require parentheses that didn't in 2.x: </li></ul></ul><ul><ul><ul><li>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)] </li></ul></ul></ul><ul><ul><li>Set literals and comprehensions. {x} means set([x]); {x, y} means set([x, y]). </li></ul></ul>
  14. 31. Python 3.0. Core language (cont.) <ul><li>To be removed: </li></ul><ul><ul><li>String exceptions: use instances of an Exception class </li></ul></ul><ul><ul><li>raise Exception, &quot;message&quot;: use raise Exception(&quot;message&quot;) </li></ul></ul><ul><ul><li>`x`: use repr(x) </li></ul></ul><ul><ul><li>The <> operator: use != instead </li></ul></ul><ul><ul><li>Drop unbound methods </li></ul></ul><ul><ul><li>__getslice__, __setslice__, __delslice__; remove slice opcodes and use slice objects. </li></ul></ul><ul><ul><li>__oct__, __hex__: use __index__ in oct() and hex() instead. </li></ul></ul><ul><ul><li>__methods__ and __members__ </li></ul></ul>
  15. 32. Python 3.0. Atomic Types <ul><ul><li>Remove distinction between int and long types; 'long' built-in type and literals with 'L' or 'l' suffix disappear </li></ul></ul><ul><ul><li>Make all strings be Unicode, and have a separate bytes() type. The new string type will be called 'str'. See PEP 3137 . </li></ul></ul><ul><ul><li>Return iterable views instead of lists where appropriate for atomic type methods (e.g. dict.keys(), dict.values(), dict.items(), etc.); iter* methods will be removed. </li></ul></ul><ul><li>To be removed: </li></ul><ul><ul><li>file.xreadlines() method </li></ul></ul><ul><ul><li>dict.has_key() method; use in operator </li></ul></ul><ul><ul><li>list.sort() and builtin.sorted() methods: eliminate cmp parameter </li></ul></ul>
  16. 33. Python 3.0. Built-in Namespace <ul><ul><li>Make built-ins return an iterator where appropriate (e.g. range(), zip(), map(), filter(), etc.) </li></ul></ul><ul><ul><li>Remove input() and rename raw_input() to input(). If you need the old input(), use eval(input()). </li></ul></ul><ul><ul><li>Introduce trunc(), which would call the __trunc__() method on its argument; suggested use is for objects like float where calling __int__() has data loss, but an integral representation is still desired </li></ul></ul><ul><ul><li>Exception hierarchy changes </li></ul></ul><ul><ul><li>Add a bin() function for a binary representation of integers </li></ul></ul>
  17. 34. Python 3.0. Built-in Namespace (cont.) <ul><li>To be removed: </li></ul><ul><ul><li>apply(): use f(*args, **kw) instead </li></ul></ul><ul><ul><li>buffer(): must die (use a bytes() type instead) </li></ul></ul><ul><ul><li>callable(): just use hasattr(x, '__call__') </li></ul></ul><ul><ul><li>compile(): put in sys </li></ul></ul><ul><ul><li>coerce(): no longer needed </li></ul></ul><ul><ul><li>execfile(), reload(): use exec() </li></ul></ul><ul><ul><li>intern(): put in sys </li></ul></ul><ul><ul><li>reduce(): put in functools, a loop is more readable most of the times </li></ul></ul><ul><ul><li>xrange(): use range() </li></ul></ul><ul><ul><li>StandardError: this is a relic from the original exception hierarchy; subclass Exception instead. </li></ul></ul>
  18. 35. Python 3.0. Release Plan <ul><li>PEP-361: Python 2.6 and 3.0 are lock-stepped (the same procedure was used for 1.6 and 2.0): </li></ul><ul><ul><li>Feb 29 2008: Python 2.6a1 and 3.0a3 are released </li></ul></ul><ul><ul><li>Apr 02 2008: Python 2.6a2 and 3.0a4 are released </li></ul></ul><ul><ul><li>May 08 2008: Python 2.6a3 and 3.0a5 are released </li></ul></ul><ul><ul><li>Jun 18 2008: Python 2.6b1 and 3.0b1 are released </li></ul></ul><ul><ul><li>Jul 02 2008: Python 2.6b2 and 3.0b2 planned </li></ul></ul><ul><ul><li>Aug 06 2008: Python 2.6rc1 and 3.0rc1 planned </li></ul></ul><ul><ul><li>Aug 20 2008: Python 2.6rc2 and 3.0rc2 planned </li></ul></ul><ul><ul><li>Sep 03 2008: Python 2.6 and 3.0 final </li></ul></ul>
  19. 36. Python 3.0. Migration <ul><li>Python 3.0 will break backwards compatibility with Python 2.x. </li></ul><ul><li>There is no requirement that Python 2.6 code will run unmodified on Python 3.0. Not even a subset. </li></ul><ul><li>Python 2.6 will support forward compatibility in the following two ways: </li></ul><ul><ul><li>It will support a &quot;Py3k warnings mode&quot; which will warn dynamically (i.e. at runtime) about features that will stop working in Python 3.0, e.g. assuming that range() returns a list. </li></ul></ul><ul><ul><li>It will contain backported versions of many Py3k features, either enabled through __future__ statements or simply by allowing old and new syntax to be used side-by-side (if the new syntax would be a syntax error in 2.x). </li></ul></ul>
  20. 37. Python 3.0. Migration (cont.) <ul><li>The recommended development model for a project that needs to support Python 2.6 and 3.0 simultaneously is as follows: </li></ul><ul><ul><li>You should have excellent unit tests with close to full coverage. </li></ul></ul><ul><ul><li>Port your project to Python 2.6. </li></ul></ul><ul><ul><li>Turn on the Py3k warnings mode. </li></ul></ul><ul><ul><li>Test and edit until no warnings remain. </li></ul></ul><ul><ul><li>Use the 2to3 tool to convert this source code to 3.0 syntax. Do not manually edit the output! </li></ul></ul><ul><ul><li>Test the converted source code under 3.0. </li></ul></ul><ul><ul><li>If problems are found, make corrections to the 2.6 version of the source code and go back to step 3. </li></ul></ul><ul><ul><li>When it's time to release, release separate 2.6 and 3.0 tarballs (or whatever archive form you use for releases). </li></ul></ul><ul><li>It is recommended not to edit the 3.0 source code until you are ready to reduce 2.6 support to pure maintenance (i.e. the moment when you would normally move the 2.6 code to a maintenance branch anyway). </li></ul>
  21. 38. Python 3.0. Questions? <ul><li>  </li></ul>
  22. 39. pause...
  23. 40. Distributing Python code <ul><ul><li>Why distribution is important? </li></ul></ul><ul><ul><li>distutils </li></ul></ul><ul><ul><li>setuptools </li></ul></ul><ul><ul><li>easy_install </li></ul></ul><ul><ul><li>virtualenv </li></ul></ul><ul><ul><li>Private PyPI </li></ul></ul>
  24. 41. Why distribution is important? <ul><ul><li>Simpler installation makes Python software reusable andmore accessible </li></ul></ul><ul><ul><li>More users </li></ul></ul><ul><ul><li>More pressure to package developers </li></ul></ul><ul><ul><li>Better distributions </li></ul></ul><ul><ul><ul><li>more meta-data </li></ul></ul></ul><ul><ul><ul><li>more documentation </li></ul></ul></ul><ul><ul><ul><li>more tests </li></ul></ul></ul><ul><ul><ul><li>more platforms </li></ul></ul></ul><ul><ul><li>&quot;CheeseCake&quot; rating system (better package kwalitee) </li></ul></ul>
  25. 42. distutils <ul><li>For end-users: </li></ul><ul><ul><li>python install </li></ul></ul><ul><li>For developers: </li></ul><ul><ul><li>python sdist </li></ul></ul><ul><li>For packagers: </li></ul><ul><ul><li>python bdist </li></ul></ul><ul><li>Since Python-2.5, you can host your packages directly on PyPI </li></ul><ul><ul><li>python upload </li></ul></ul>
  26. 43. setuptools <ul><ul><li>Automatically find/download/install/upgrade dependencies at build time using the EasyInstall tool , which supports downloading via HTTP, FTP, Subversion, and SourceForge, and automatically scans web pages linked from PyPI to find download links. (It's the closest thing to CPAN currently available for Python.) </li></ul></ul><ul><ul><ul><ul><li>easy_install grockproject </li></ul></ul></ul></ul><ul><ul><li>Create Python Eggs - a single-file importable distribution format </li></ul></ul><ul><ul><ul><ul><li>python bdist_egg </li></ul></ul></ul></ul>
  27. 44. setuptools (cont.) <ul><ul><li>Command aliases - create project-specific, per-user, or site-wide shortcut names for commonly used commands and options </li></ul></ul><ul><ul><li>PyPI upload support - upload your source distributions and eggs to PyPI </li></ul></ul><ul><ul><li>Deploy your project in &quot;development mode&quot;, such that it's available on sys.path, yet can still be edited directly from its source checkout. </li></ul></ul><ul><ul><li>Easily extend the distutils with new commands or setup() arguments, and distribute/reuse your extensions for multiple projects, without copying code. </li></ul></ul><ul><ul><li>Create extensible applications and frameworks that automatically discover extensions, using simple &quot;entry points&quot; declared in a project's setup script. </li></ul></ul>
  28. 45. easy_install <ul><li>easy_install SQLObject easy_install -f SQLObject easy_install easy_install /my_downloads/OtherPackage-3.2.1-py2.3.egg easy_install --upgrade PyProtocols easy_install . easy_install --editable --build-directory ~/projects SQLObject </li></ul>
  29. 46. virtualenv <ul><li>virtualenv is a tool to create isolated Python environments. The basic usage is: </li></ul><ul><ul><li>$ python ENV </li></ul></ul><ul><li>This creates ENV/lib/python2.4/site-packages , where any libraries you install will go. It also creates ENV/bin/python, which is a Python interpreter that uses this environment. Allows bootstrap scripts that prepare environment. Alternatives: </li></ul><ul><ul><li>workingenv </li></ul></ul><ul><ul><li>virtual-python </li></ul></ul><ul><ul><li>zc.buildout </li></ul></ul>
  30. 47. Private PyPI <ul><li>Folder </li></ul><ul><li>...with eggs exposed (and password-protected) via Apache. Works with easy_install, requires &quot;manual&quot; uploading to folder, can be as simple as copy to shared folder </li></ul><ul><li>haufe.eggserver grok-powered solution. Recently upload support added. No dedicated security model (everyone is trusted and allowed to upload packages). </li></ul><ul><li>Plone Software Center 1.5 Plone product. Support upload, categorization, security. Has buildout. </li></ul>
  31. 48. Questions?
  32. 49. References <ul><ul><li> </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li> </li></ul></ul>
  33. 50. Thanks