Skip to content

Archive

Python 3.13

2 articles
Python 09 Sep 2026 9 min read

Update Immutable Records with Python copy.replace()

I like immutable value objects because they make state changes explicit. The awkward part is that Python has historically offered several different ways to create a slightly modified version of one. A dataclass has dataclasses.replace(). A named tuple has _replace(). A custom class usually needs its own helper. The operations are conceptually similar, but generic code has no single interface to target. Python 3.13 adds copy.replace() to close that gap. It creates a new object of the same type while replacing selected fields, and it works with dataclasses, named tuples, and classes that implement __replace__().

Python 09 Sep 2026 9 min read

Shut Down asyncio Worker Queues Cleanly

Asynchronous worker pools often start with a simple pattern: producers put jobs into an asyncio.Queue, consumers loop over get(), and the application waits for join() before exiting. The awkward part is shutdown. Older designs commonly put one sentinel value into the queue for each worker, cancel consumers after join(), or maintain a separate stop event. Each approach can work, but each adds a second protocol beside the queue itself. Python 3.13 added asyncio.Queue.shutdown() and the asyncio.QueueShutDown exception. They let the queue represent its own lifecycle: open for producers, shutting down while existing work drains, and finally closed to consumers.