enhancements FullPython2.5

larsmans edited this page Aug 28, 2013 · 6 revisions
Clone this wiki locally

## page was renamed from enhancements/FullPython2.5 Python2.5 ## page was renamed from enchancements/FullPython2.5 Python2.5

DRAFT - Python 2.5 Features

This document describes the tasks of the project, the work and the expected estimation

  • Create a comprehensive testsuite for the actual behavior of the current project A comprehensive set of valid cython files must be created to cover all the current supported features of the tool, will help a lot during the transition process to the new parser enhancements/AutoGenParser Parser
  • AST Example, how to transform it

Python 2.5 missing features

Note by robertwb: Looking at the "new features" of Python 2.5 is not an accurate way to get a missing feature list. Pyrex/Cython is a subset of the 2.3 language, with extra features (type declarations, and 2.4/2/5 stuff) added on.

Importance High:

--(PEP 308: Conditional Expressions)-- Implemented
x = true_value if condition else false_value

--(PEP 341: Unified try/except/finally)-- Implemented {{{ try:

block-1 ...
except Exception1:

handler-1 ... except Exception2:

handler-2 ... else:

else-block finally:


}}} PEP 342: New Generator Features

def counter (maximum):

i = 0 while i < maximum:

yield i i += 1
PEP 343 With Statement
Support for contextManager ?

—(PEP 353: Using ssize_t as the index type )-- Implemented I think this affect Cython in some way

--(PEP 357: The '__index__' method)-- Implemented. Could be optimized.
Is this supported? can be optimized?

Importance Low:

PEP 328: Absolute and Relative Imports
from __future__ import absolute_import

PEP 352: Exceptions as New-Style Classes

Python C Api Code:

from http://docs.python.org/whatsnew/ports.html support for: Call PySet_New() and PyFrozenSet_New() to create a new set, PySet_Add() and PySet_Discard() to add and remove elements, and PySet_Contains and PySet_Size to examine the set's state.

Two new macros can be used to indicate C functions that are local to the current file so that a faster calling convention can be used. Py_LOCAL(type) declares the function as returning a value of the specified type and uses a fast-calling qualifier. Py_LOCAL_INLINE(type) does the same thing and also requests the function be inlined. If PY_LOCAL_AGGRESSIVE is defined before python.h is included, a set of more aggressive optimizations are enabled for the module; you should benchmark the results to find out if these optimizations actually make the code faster.

TODO: is PyRange_New() used by cython ?

Python Modules:

__missing__(key) ?

The list of base classes in a class definition can now be empty class C():



PEP 309: Partial Function Application

import functools

def log (message, subsystem): "Write the contents of 'message' to the specified subsystem." print '%s: %s' % (subsystem, message)


server_log = functools.partial(log, subsystem='server') server_log('Unable to open socket')

these works but could be optimized to create the real partial function: steps: to be done: NOT YET DEFINED

  • with
  • from import *
Backup: Profiling & Optimization: In the luckily event that all the above will be implement in time

I will do a complete profiling of the Cython and of the Generated Source.

some ideas are: use gprof perfect hash for fixed dictionaries?

Features to support in python 3k: