2 items tagged “trey-hunner”
2024
Python 3.13’s best new features (via) Trey Hunner highlights some Python 3.13 usability improvements I had missed, mainly around the new REPL.
Pasting a block of code like a class or function that includes blank lines no longer breaks in the REPL - particularly useful if you frequently have LLMs write code for you to try out.
Hitting F2 in the REPL toggles "history mode" which gives you your Python code without the REPL's >>>
and ...
prefixes - great for copying code back out again.
Creating a virtual environment with python3.13 -m venv .venv
now adds a .venv/.gitignore
file containing *
so you don't need to explicitly ignore that directory. I just checked and it looks like uv venv
implements the same trick.
And my favourite:
Historically, any line in the Python debugger prompt that started with a PDB command would usually trigger the PDB command, instead of PDB interpreting the line as Python code. [...]
But now, if the command looks like Python code,
pdb
will run it as Python code!
Which means I can finally call list(iterable)
in my pdb
seesions, where previously I've had to use [i for i in iterable]
instead.
(Tip from Trey: !list(iterable)
and [*iterable]
are good alternatives for pre-Python 3.13.)
Trey's post is also available as a YouTube video.
Every dunder method in Python. Trey Hunner: "Python includes 103 'normal' dunder methods, 12 library-specific dunder methods, and at least 52 other dunder attributes of various types."
This cheat sheet doubles as a tour of many of the more obscure corners of the Python language and standard library.
I did not know that Python has over 100 dunder methods now! Quite a few of these were new to me, like __class_getitem__
which can be used to implement type annotations such as list[int]
.