Interesting new features in Python 3.5

E8600d16ba667cc8d7f00ddc9f254340?s=47 Brett Cannon
September 13, 2015

Interesting new features in Python 3.5

Vancouver Python Day presentation on what Python 3.5 introduces.

E8600d16ba667cc8d7f00ddc9f254340?s=128

Brett Cannon

September 13, 2015
Tweet

Transcript

  1. Interesting New Features in Python 3.5 Dr. Brett Cannon Microsoft

    / snarky.ca Vancouver Python Day, Sep 2015
  2. Read "What’s New In Python 3.5" for all the details

  3. async/await PEP 492

  4. "Coroutines … generalize subroutines for nonpreemptive multitasking, by allowing multiple

    entry points for suspending and resuming execution at certain locations."
  5. 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!
  6. 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()
  7. 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()
  8. Matrix multiplication PEP 465

  9. Operator is not implemented by any of Python's builtin types

    numpy.dot(a, b) a.dot(b) a @ b
  10. Type hints PEP 484

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

    + name
  12. 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
  13. 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]
  14. Bytes interpolation PEP 461

  15. Should help with Python 2/3 compatibility b'you can %s bytes'

    % (b'interpolate')
  16. Compiler independence on Windows Python is no longer tied to

    a certain version of VC++
  17. Preview of Python 3.6 No rest for the wicked

  18. Format strings PEP 498

  19. Prints "I'm in Vancouver learning about Python!" loc = 'Vancouver'

    lang = 'Python' print(f"I'm in {loc} learning about {lang}!")
  20. Q&A