Brought to you by Michael and Brian - take a Talk Python course or get Brian's pytest book

Episode #253: A new Python for you, and for everyone!

Published Thu, Oct 7, 2021, recorded Wed, Oct 6, 2021.



Watch the live stream:

About the show

Special guest: Yael Mintz

Sponsored by us:

Michael #1: awesome-htmx

  • An awesome list of resources about htmx such as articles, posts, videos, talks and more.
  • Good for all sorts of examples and multiple languages
  • We get a few nice shoutouts, thanks

Brian #2: Python 3.10 is here !!!!

  • As of Monday. Of course I have it installed on Mac and Windows. Running like a charm.
  • You can watch the Release Party recording. It’s like 3 hours. And starts with hats. Pablo’s is my fav.
  • Also a What’s New video which aired before that with Brandt Bucher, Lukasz Llanga ,and Sebastian Ramirez (33 min)
    • Includes a deep dive into structural pattern matching that I highly recommend.
  • Reminder of new features:
    • PEP 623 -- Deprecate and prepare for the removal of the wstr member in PyUnicodeObject.
    • PEP 604 -- Allow writing union types as X | Y
    • PEP 612 -- Parameter Specification Variables
    • PEP 626 -- Precise line numbers for debugging and other tools.
    • PEP 618 -- Add Optional Length-Checking To zip.
    • bpo-12782: Parenthesized context managers are now officially allowed.
    • PEP 632 -- Deprecate distutils module.
    • PEP 613 -- Explicit Type Aliases
    • PEP 634 -- Structural Pattern Matching: Specification
    • PEP 635 -- Structural Pattern Matching: Motivation and Rationale
    • PEP 636 -- Structural Pattern Matching: Tutorial
    • PEP 644 -- Require OpenSSL 1.1.1 or newer
    • PEP 624 -- Remove Py_UNICODE encoder APIs
    • PEP 597 -- Add optional EncodingWarning
  • Takeaway I wasn’t expecting: black doesn’t handle Structural Pattern Matching yet.

Yael #3: Prospector (almost) All Python analysis tools together

Michael #4: Rich Pandas DataFrames

  • via Avi Perl, by Khuyen Tran
  • Create animated and pretty Pandas Dataframe or Pandas Series (in the terminal, using Rich)
  • I just had Will over on Talk Python last week BTW: Terminal magic with Rich and Textual
  • Can limit rows, control the animation speed, show head or tail, go “full screen” with clear, etc.
  • Example:
    from sklearn.datasets import fetch_openml
    from rich_dataframe import prettify

    speed_dating = fetch_openml(name='SpeedDating', version=1)['frame']
    table = prettify(speed_dating)

Brian #5: Union types, baby!

  • From Python 3.10: “PEP 604 -- Allow writing union types as X | Y”
  • Use as possibly not intended, to avoid Optional:
    def foo(x: str | None = None) -> None:
      pass 
  • 3.9 example:
    from typing import Optional
    def foo(x: Optional[str] = None) -> None:
      pass
  • But here’s the issue. I need to support Python 3.9 at least, and probably early, what should I do?
  • For 3.7 and above, you can use from __future__ import annotations.
  • And of course Anthony Sottile worked this into pyupgrade and Adam Johnson wrote about it:
  • This article covers:
    • PEP 585 added generic syntax to builtin types. This allows us to write e.g. list[int] instead of using typing.List[int].
    • PEP 604 added the | operator as union syntax. This allows us to write e.g. int | str instead of typing.Union[int, str], and int | None instead of typing.Optional[int].
    • How to use these. What they look like. And how to use pyupgrade to just convert your code for you if you’ve already written it the old way. Awesome.

Yael #6: Make your code darker - Improving Python code incrementally

  • The idea behind Darker is to reformat code using Black (and optionally isort), but only apply new formatting to regions which have been modified by the developer
  • Instead of having one huge PR, darker allows you to reformat the code gradually, when you're touching the code for other reasons..
  • Every modified line, will be black formatted
  • Once added to Git pre-commit-hook, or added to PyCharm **/ VScode the formatting will happen automatically

Extras

Brian:

Michael:

Yael:

  • data-oriented-programming - an innovative approach to coding without OOP, with an emphasis on code and data separation, which simplifies state management and eases concurrency
  • Help us to make Cornell awesome 🙂 - contributors are warmly welcomed

Joke: Pair CAPTCHAing


Want to go deeper? Check our projects