The notebook index
Post archive
11 posts in Python.
- A pickle is a program-shaped input, not just stored data
Python pickle preserves object graphs by describing reconstruction work. That makes its trust boundary different from a data-only format, and changes how caches, uploads and deployment artifacts should be handled.
- Python pattern matching is ordered dispatch, not validation
Python’s match statement selects the first pattern and guard that succeeds. Capture names, partial mapping matches, and observable guard effects make pattern order part of the program’s contract.
- Python 3.16 gives regular-expression character sets set algebra
Python 3.16.0a2 adds nested character sets, set operators and Unicode property escapes to re. They can express character policy more directly, but alpha-stage semantics and compatibility still need explicit tests.
- An asyncio task group defines a failure domain
A TaskGroup gives related asyncio tasks a shared lifetime: leaving the block waits for them, and an unhandled child failure cancels its siblings. That is useful only when the group matches the work that should succeed or fail together.
- Python’s tar filter shows what a security boundary must cover
Python 3.15.2 fixed a path escape in tarfile’s explicit tar filter. The flaw shows why extraction safety depends on the order of archive entries, while the release’s separate TLS fix illustrates a very different kind of trust decision.
- Context variables follow asyncio tasks, not just threads
ContextVar gives asynchronous code task-local state without threading.local() leaking values between coroutines. Task creation, token reset and thread handoffs define where that state begins and ends.
- Descriptors turn attribute access into an interface policy
A descriptor lets a class attribute mediate reads and writes. Understanding its precedence, owner binding and storage name helps decide when the protocol is clearer than a property or ordinary method.
- A process pool is an import and serialization boundary
Python process workers may start from a fresh interpreter, a fork server or a forked parent. Put work in importable functions, guard process creation, and choose a context deliberately.
- Python 3.15 makes deferred imports explicit—and changes when failure happens
Python 3.15 adds opt-in lazy imports that defer module loading until first use. The startup win comes with a changed point of execution: errors and import-time effects move to the path that touches the name.
- Validate CSV headers before building dictionaries
Check CSV header uniqueness, required names and row widths before mapping fields, preserving IDs such as 007 as strings.
- CSV round trips: commas, quotes and embedded newlines
Use Python’s CSV reader and writer to round-trip commas, quotes and newlines while accounting for type loss and spreadsheet formula risks.