Topics covered in this episode:
About the show
Sponsored by us! Support our work through:
Connect with the hosts
Join us on YouTube at pythonbytes.fm/live to be part of the audience. Usually Monday at 10am PT. Older video versions available there too.
Finally, if you want an artisanal, hand-crafted digest of every week of the show notes in email form? Add your name and email to our friends of the show list, we'll never share it.
Michael #1: PEP 798: Unpacking in Comprehensions
Examples
[*it for it in its] # list with the concatenation of iterables in 'its'
{*it for it in its} # set with the union of iterables in 'its'
{**d for d in dicts} # dict with the combination of dicts in 'dicts'
(*it for it in its) # generator of the concatenation of iterables in 'its'
Also: The Steering Council is happy to unanimously accept “PEP 810, Explicit lazy imports”
Brian #2: Pandas 3.0.0rc0
df.assign(c = pd.col('a') + pd.col('b'))Michael #3: typos
Like codespell, typos checks for known misspellings instead of only allowing words from a dictionary. But typos has some extra features I really appreciate, like finding spelling mistakes inside snake_case or camelCase words. For example, if you have the line:
*connecton_string="sqlite:///my.db"*
codespell won't find the misspelling, but typos will. It gave me the output:
*error:`connecton`shouldbe`connection`,`connector`
╭▸./main.py:1:1│1│connecton_string="sqlite:///my.db"
╰╴━━━━━━━━━*
But the main advantage for me is that typos has an LSP that supports editor integrations like a VS Code extension. As far as I can tell, codespell doesn't support editor integration. (Note that the popular Code Spell Checker VS Code extension is an unrelated project that uses a traditional dictionary approach.)
For more on the differences between codespell and typos, here's a comparison table I found in the typos repo: https://github.com/crate-ci/typos/blob/master/docs/comparison.md
By the way, though it's not mentioned in the installation instructions, typos is published on PyPI and can be installed with uv tool install typos, for example. That said, I don't bother installing it, I just use the VS Code extension and run it as a pre-commit hook. (By the way, I'm using prek instead of pre-commit now; thanks for the tip on episode #448!) It looks like typos also publishes a GitHub action, though I haven't used it.
Brian #4: A couple testing topics
myproduct has user.py that uses the system builtin open() and we want to patch it:@patch("builtins.open")open() for the whole system@patch("myproduct.user.open")open() for just the user.py file, which is what we wantcoverage.pyExtras
Brian:
Michael:
Joke: tabloid - A minimal programming language inspired by clickbait headlines