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

Python Bytes - En podcast af Michael Kennedy and Brian Okken - Tirsdage

Kategorier:

Watch the live stream: Watch on YouTube About the show Special guest: Yael Mintz Sponsored by us: Check out the courses over at Talk Python And Brian’s book too! 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 Instead of running pylint, pycodestyle, mccabe and other separately, prospector allows you to bundle them all together Includes the common Pylint and Pydocstyle / Pep257, but also some other less common goodies, such as Mccabe, Dodgy, Vulture, Bandit, Pyroma and many others Relatively easy configuration that supports profiles, for different cases Built-in support for celery, Flask and Django frameworks https://soshace.com/how-to-use-prospector-for-python-static-code-analysis/ 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: Python Type Hints - How to Upgrade Syntax with pyupgrade 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: I got a couple PRs accepted into pytest. So that’s fun: 9133: Add a deselected parameter to assert_outcomes() 9134: Add a pythonpath setting to allow paths to be added to sys.path I’ve tested, provided feedback, written about, and submitted issues to the project before. I’ve even contributed some test code. But these are the first source code contributions. It was a cool experience. Great team there at pytest. Michael: New htmx course: HTMX + Flask: Modern Python Web Apps, Hold the JavaScript auto-optional: Due to the comments on the show I remembered to add support for Union[X, None] and python 10’s X | None syntax. Coverage 6.0 released Django 3.2.8 released 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

Visit the podcast's native language site