RSSAmplifier

Blog

Adam Johnson

adamj.euRSS feed ↗10 posts

Latest posts

Python: use re.prefixmatch() instead of re.match() from Python 3.15

Take this validation function: import re TRAIN_NUMBER_RE = re . compile ( r "\d {6} " ) # six digits def is_valid_train_number ( value : str ) -> bool : return bool ( TRAIN_NUMBER_RE . match ( value )) It looks reasonable, and it works for the intended cases: >>> is_valid_train_number ( "345071" ) True >>> is_valid_train_number ( "ABC123" ) False But, woah, it also accepts garbage suffixes: >>>…

Python: fix SyntaxWarning: invalid octal escape sequence

Take this code: path = "C: \477 _data" If we run this with Python 3.11+ in development mode (to enable deprecation warnings), we will see: $ python3.11 -X dev example.py /.../example.py:1: DeprecationWarning: invalid octal escape sequence '\477' path = "C:\477_data" On Python 3.12+, we instead get …

Python: fix TypeError: NamedTuple() got an unexpected keyword argument

Take this code, defining a small NamedTuple with a keyword argument per field: from typing import NamedTuple Point = NamedTuple ( "Point" , x = int , y = int ) Run it on Python 3.13 or 3.14, and you’ll see: $ python3.14 example.py /.../example.py:3: DeprecationWarning: Creating NamedTuple classes using keyword …

Python: introducing emojet, a fast emoji lookup library

New package just landed! emojet is an emoji library for Python: it converts between emoji and their names, in both directions, plus the searching and lookup functions that go with that. It covers the core API of the emoji package , a library that been available for this job since 2014 …

Python: tprof 1.3.0: now with less overhead

Back in January, I introduced tprof , a targeting profiler for Python 3.12+ that measures the time spent in specific functions, rather than your whole program. As a reminder, here’s the basic usage, specifying a target function with -t and a script to run: $ tprof -t lib:maths ./example …

Django: introducing django-msgspec

It’s another day, another new package day here. Say hello to django-msgspec , a package of drop-in replacements for Django and Django REST Framework (DRF) components backed by msgspec . msgspec is a C-based serialization library covering JSON, MessagePack, YAML, and TOML, with optional schema validation through typed Struct classes. Its …

Git: my git stash -p optimization in Git 2.55

I got another commit merged in Git 2.55 (2026-06-29), yay! The release note reads: "git stash -p" has been optimized by reusing cached index entries in its temporary index, avoiding unnecessary lstat() calls on unchanged files. Here is the story of this change. Patch mode slowness The -p ( --patch …

Git: list files at a given commit with ls-tree

To list all files in your repository as they were at a given commit, use git ls-tree with its -r and --name-only options: $ git ls-tree --name-only -r <commit> Replace <commit> with any commit reference: a SHA, a branch name, a tag like above, a relative reference like ~ (the commit before …

Zsh: select files with arbitrary code in (e) or + glob qualifiers

Zsh glob qualifiers can select files by many built-in attributes: type, size, modification time, and more. But when no built-in qualifier fits, you can bring in the e or + qualifiers to run arbitrary code, making globs a fully programmable file filter. With great power comes great responsibility! The e syntax …

Git: exclude commits by an author in git log with --perl-regexp

git log has an --author option to limit the output to commits from matching authors: $ git log --author = <pattern> But there’s no option to invert the filter and show commits from all authors except those matching a pattern. Instead, you can build the negation into the pattern itself, using …