Slide 1

Slide 1 text

Interesting New Features in Python 3.5 Dr. Brett Cannon Microsoft / snarky.ca Vancouver Python Day, Sep 2015

Slide 2

Slide 2 text

Read "What’s New In Python 3.5" for all the details

Slide 3

Slide 3 text

async/await PEP 492

Slide 4

Slide 4 text

"Coroutines … generalize subroutines for nonpreemptive multitasking, by allowing multiple entry points for suspending and resuming execution at certain locations."

Slide 5

Slide 5 text

In the beginning, there were enhanced generators >>> def grep(look_for): ... while True: ... line = (yield) ... if look_for in line: print(line) ... >>> search = grep('Python'); next(search) # Primed >>> search.send('Hi, Ruby?') >>> search.send('Hi, Vancouver Python Day!') Hi, Vancouver Python Day!

Slide 6

Slide 6 text

Then came asyncio @asyncio.coroutine def display_date(loop): end_time = loop.time() + 5.0 while True: print(datetime.datetime.now()) if (loop.time() + 1.0) >= end_time: break yield from asyncio.sleep(1) loop = asyncio.get_event_loop() loop.run_until_complete(display_date(loop)); loop.close()

Slide 7

Slide 7 text

Now we have async/await async def display_date(loop): end_time = loop.time() + 5.0 while True: print(datetime.datetime.now()) if (loop.time() + 1.0) >= end_time: break await asyncio.sleep(1) loop = asyncio.get_event_loop() loop.run_until_complete(display_date(loop)); loop.close()

Slide 8

Slide 8 text

Matrix multiplication PEP 465

Slide 9

Slide 9 text

Operator is not implemented by any of Python's builtin types numpy.dot(a, b) a.dot(b) a @ b

Slide 10

Slide 10 text

Type hints PEP 484

Slide 11

Slide 11 text

Simple example def greeting(name: str) -> str: return 'Hello ' + name

Slide 12

Slide 12 text

Take a deep breath & stay calm ● Does not affect runtime semantics ● Meant to act as documentation and help with tooling ○ Just like Dart ● Does not forbid using function annotations for other purposes ○ Does gives them widely recognized default semantics, though ● In no way required to be used ● Doesn't expect everything to be annotated ○ E.g., don't worry about annotating local variables if you don't want to

Slide 13

Slide 13 text

Example using the typing module and variable annotations from typing import Mapping, Sequence def notify_by_email(employees: Sequence[Employee], overrides: Mapping[str, str]) -> None: ... x = [] # type: List[Employee]

Slide 14

Slide 14 text

Bytes interpolation PEP 461

Slide 15

Slide 15 text

Should help with Python 2/3 compatibility b'you can %s bytes' % (b'interpolate')

Slide 16

Slide 16 text

Compiler independence on Windows Python is no longer tied to a certain version of VC++

Slide 17

Slide 17 text

Preview of Python 3.6 No rest for the wicked

Slide 18

Slide 18 text

Format strings PEP 498

Slide 19

Slide 19 text

Prints "I'm in Vancouver learning about Python!" loc = 'Vancouver' lang = 'Python' print(f"I'm in {loc} learning about {lang}!")

Slide 20

Slide 20 text

Q&A