Features worth mentioning in Python 3.5

Yesterday Python 3.5 was released for its first beta. I think it’s a great release version with two important features I have been expected for a long time. They are Type Hinting and Await and Async syntax for coroutine. With these two features, I think programming in Python would be more productive in terms of safty and performance-wise.

Before type hinting was part of the official PEP, I always went to mypy for type hinting. And it turns out the finalized PEP was strongly inspired by mypy. With a few of import you could mark your program like this.

def fib(n: int) -> Iterator[int]: 
  a, b = 0, 1 
  while a < n: 
    yield a 
    a, b = b, a+b

This would provide static checking tool and IDE more information to do the inference, and detect the potential error. But unfortunately, these information is still not accepted for generating more efficient bytecode or getting more performant JIT. Just like Facebook’s Hack language does providing gradual typing for PHP. I hope in the near future it would eventually reflect on runtime performance.

Another is async and await syntax allowing you to mark function as coroutine.

async def read_data(db): 
  data = await db.fetch('SELECT ...') 
  ...

Previously you could achieve the same effect with enhanced generator with yield and yield from. But without a doubt, marking async and await would make the program easier to read.

I am pretty looking forward to Python 3.5 being production ready.