Django 6, Typing, and Tooling Drive Python Ecosystem Maturity - Episode Hero Image

Django 6, Typing, and Tooling Drive Python Ecosystem Maturity

Original Title:

TL;DR

  • Django 6 mandates Python 3.12+, accelerating adoption of performance gains like 50% speed improvements and reduced memory usage by pushing developers to newer Python versions.
  • Django 6 introduces built-in Content Security Policy support, mitigating cross-site scripting (XSS) and other vulnerabilities by configuring browser security headers.
  • Django 6's template partials feature simplifies integration with frontend frameworks like HTMX by enabling server-side rendering of specific page fragments, reducing duplication.
  • Django 6 adds a simple background task runner, allowing asynchronous processing of longer operations without requiring external message queues or servers.
  • Advanced Python typing features like assert never and get_args enable more precise static analysis and error prevention, particularly in modern Python versions (3.12+).
  • The no_return typing annotation signifies functions that exit solely via exceptions, useful for signaling control flow in web frameworks like redirects.
  • CodeSpell, a configurable misspelling checker, integrates into development workflows via pre-commit hooks to catch common errors in source code without false positives from acronyms.

Deep Dive

The Python Bytes podcast, in its 460th episode, highlights advancements and overlooked features across the Python ecosystem, with a particular focus on typing, web development, and developer tooling. These updates signal a growing maturity in Python's capabilities, pushing developers towards more robust and modern practices while also introducing new tools to streamline workflows and improve code quality.

The discussion begins with Advent of Code, a popular coding challenge that commenced on December 1st. This year, the event introduces a shorter format and has removed the global leaderboard, shifting focus toward individual participation and community engagement. A new helper tool, "elf," is also introduced, offering a command-line interface to manage Advent of Code puzzles, indicating a trend towards more sophisticated tooling for developer challenges.

Django 6 is poised for release, signaling a significant update for the popular web framework. A key implication of this release is its stringent requirement for Python 3.12 or newer, pushing developers to adopt more recent Python versions to leverage performance and memory improvements. New features include built-in Content Security Policy support to mitigate cross-site scripting vulnerabilities, template partials that enhance integration with front-end frameworks like HTMX, and background task capabilities for asynchronous processing without external dependencies. Email handling also adopts Python's modern email.message API. These changes suggest Django's ongoing commitment to security, developer experience, and performance, encouraging adoption of newer Python standards.

The episode delves into "Advanced Overlooked Python Typing," exploring features beneficial for modern Python development, particularly in Python 3.12 and newer. Notable additions include assert never for ensuring code paths are unreachable, get args for simplifying type definitions with literals, and advancements in type narrowing. The introduction of NoReturn for functions that exit solely via exceptions, rather than returning a value, highlights a nuanced approach to function behavior within static analysis. These typing enhancements signify a push towards more reliable and maintainable codebases by enabling stricter checks and clearer function contracts.

Developer tooling sees updates with codespell, a tool designed to catch common misspellings in source code without flagging valid project-specific terms, which can be integrated via pre-commit hooks. Hatch, a project management tool, now supports dependency groups and workspaces, crucial for monorepo management, and software bill of materials (SBOM) generation, reflecting increased industry focus on supply chain security. The documentation tool mkdocs faces questions about its maintenance status, with zensicle emerging as a potential successor, built from scratch by the original maintainers of mkdocs' Material theme. Similarly, the architecture visualization tool tech has been revived by a new maintainer after its original project was abandoned, underscoring the community-driven nature of open-source development and the importance of toolchain stability.

Finally, a humorous "No as a Service" API is presented, offering random, realistic excuses for declining requests. This lighthearted inclusion, alongside the more technical updates, underscores the ongoing evolution of the Python landscape, balancing practical advancements with developer well-being and a touch of humor. The collective updates across these areas point to a maturing ecosystem that prioritizes performance, security, maintainability, and efficient developer workflows.

Action Items

  • Audit Python typing: Implement assert never and get_args for 3 core modules to improve type safety and reduce runtime errors.
  • Implement Content Security Policy: Configure CSP headers for 5 critical Django endpoints to mitigate XSS and other injection vulnerabilities.
  • Create runbook template: Define 5 required sections (setup, common failures, rollback, monitoring) for new features to prevent knowledge silos.
  • Track 3-5 common misspellings: Integrate codespell as a pre-commit hook to catch and correct common typos in source code.
  • Evaluate background task implementation: For 2-3 high-latency operations, implement Django's built-in background task support to improve request response times.

Key Quotes

"The global leaderboard is has gone away for maintenance reasons so I do appreciate it's one of the things is which I say thanks for people doing cool stuff so advent of code is cool it is sponsored there are some sponsors that that have helped keep this going but one of the things I noticed this year and maybe it's been there and I just haven't noticed is there's a swag page you can go look at their look some of the some cool stuff and you can grab a mug or a shirt or you know something kind of fun."

Brian Okken notes a change in the Advent of Code competition, specifically the removal of the global leaderboard for maintenance. He expresses appreciation for the sponsors that support the event and highlights the availability of a new swag page with merchandise. Okken finds the swag appealing because the items do not have the year printed on them, making them suitable for year-round use.


"Django 6 has some really cool features actually some genuinely useful ones the first thing I want to point out about it is how aggressive they are at saying no to older versions like no old python they only support python 312 and above that's pretty that's pretty hardcore honestly."

Michael Kennedy points out a significant change in Django 6, which is its strict requirement for newer Python versions, specifically Python 3.12 and above. Kennedy describes this as "hardcore" but also sees it as a positive step that encourages users to adopt more modern and efficient Python environments. He suggests that this move aligns with the benefits of using newer Python versions, such as improved speed and reduced memory usage.


"There's a certain never I didn't know this was a thing so let's say you've got a match case match case thing like switches and you've got your catch all at the end and you want to never hit that usually I'll throw an assert there or something just to just in case but there's an assert never that comes from from typing didn't know that was there that you can make sure that this default case is never hit or if you have other cases that should never be hit throw that in there that's cool didn't know that existed."

Brian Okken discusses an advanced typing feature in Python called assert never. Okken expresses surprise at its existence, noting that he previously used assert statements to ensure that a "catch-all" case in a match-case structure would never be reached. He highlights that assert never provides a more explicit and dedicated way to signal that a particular code path should be unreachable.


"So what this says is it looks for like common misspellings like a d n or um t e h or what you know stuff like that anyway there's not a whole lot more to say about it other than it's pretty cool it's configurable you can like put words that are you know learn this spelling equivalents and put other types of config files and whatnot oh this is cool yeah you can even put it into a pi project dot toml its settings if you wish."

Michael Kennedy explains the functionality of codespell, a tool designed to find common misspellings in source code. Kennedy clarifies that codespell focuses on frequently misspelled words rather than identifying unknown words, which can be problematic with acronyms or library names. He notes that codespell is configurable, allowing users to define spelling equivalents and settings, and can even be integrated into pyproject.toml.


"So I present to you no as a service so this is an api that will simply return a random but realistic excuse for saying no so you can turn it down and stop oh nice yeah built by humans excuses and humor this project is sponsored by get ags get ads i don't know what that is but anyway so if you pull it up it's n a a s i think it's n o a s but you know whatever it's that's not the domain they got and you just get a little bit of json reason I'm fighting an invisible dragon at home it's taken longer than expected or not my circus not my monkeys so definitely not my act to perform."

Michael Kennedy introduces "No as a Service" (NAAS), an API that provides random, realistic excuses for declining requests. Kennedy finds the concept humorous and notes that the project is sponsored. He shares examples of the excuses generated by the API, such as "I'm fighting an invisible dragon at home" and "Not my circus, not my monkeys." Kennedy suggests that this API could be integrated into applications for humorous effect.

Resources

External Resources

Books

  • "Talk Python Production" by Michael Kennedy - Mentioned as the reviewer's book, which received a positive review.

Articles & Papers

  • "Advanced Overlooked Python Typing" - Discussed as a source for new features in Python typing, including assert never, get_args, type is, and no_return.
  • "Is MkDocs Still Maintained?" - Referenced as an article discussing the maintenance status of MkDocs.

Tools & Software

  • codespell - Mentioned as a tool that checks for common misspellings in source code.
  • hatch - Discussed as a project with recent updates including dependency groups, workspaces, and support for Software Bill of Materials (SBOM).
  • Python Typing - Referenced as a module that provides advanced features for type hinting in Python.
  • Tech - Mentioned as a tool for creating architectural layered graphs, which is now being maintained again.
  • Elf - Referenced as a Python project that acts as a modern Advent of Code helper, fetching inputs, submitting answers, and tracking progress.

Websites & Online Resources

  • Advent of Code - Discussed as a website offering code puzzles for developers to solve in any language, with mentions of its sponsors, swag page, and global leaderboard changes.
  • No as a Service (NAAS) - Referenced as an API that provides random, realistic excuses for declining requests.
  • Reddit - Mentioned as a platform where a Python project called Elf was discovered.
  • Mastodon - Mentioned as a platform where a listener provided feedback on Zensicle.

Other Resources

  • Django 6 - Discussed as a major new release of the Django web framework, highlighting its support for Python 3.12+, Content Security Policy, template partials, and background tasks.
  • MkDocs - Mentioned as a documentation generator that may not be actively maintained, with Zensicle presented as an alternative.
  • Zensicle - Referenced as a documentation generator that is a replacement for MkDocs and Material Theme, built from scratch.
  • Hatch Backends - Mentioned in relation to updates in Hatch, specifically regarding dependency groups and workspaces.
  • Software Bill of Materials (SBOM) - Mentioned as a feature now supported by Hatch.
  • Type Guard - Referenced as a feature in Python typing that provides type narrowing logic.
  • Type Narrowing - Discussed in the context of Python typing, with type is being a stricter version.
  • Template Partials - Highlighted as a new feature in Django 6 that facilitates returning fragments of a page.
  • Background Tasks - Mentioned as a new feature in Django 6 for processing longer tasks without blocking requests.
  • Content Security Policy (CSP) - Discussed as a feature in Django 6 to help prevent cross-site scripting (XSS) attacks.
  • assert never - Referenced as a feature from the typing module in Python to ensure a default case is never hit.
  • get_args - Discussed as a Python typing feature that creates a set of literals for types within a collection.
  • no_return - Mentioned as an advanced typing feature in Python indicating a function only exits via exceptions.
  • email.message - Referenced as Python's modern API used for email handling in Django 6.
  • htmx - Mentioned as a popular front-end framework that benefits from Django 6's template partials feature.
  • make_docs - Referenced as a documentation generator that may not be actively maintained.
  • mkdocs-material - Mentioned as a theme for MkDocs.
  • pi project.toml - Referenced as a configuration file where codespell settings can be placed.
  • pre-commit hook - Mentioned as a potential integration point for codespell.
  • monorepo - Discussed in relation to Hatch's workspace feature.
  • architectural layered graphs - Mentioned as the output of the Tech tool.
  • Y Combinator - Mentioned as the previous affiliation of the main project for Tech.
  • AI - Mentioned in the context of a startup pivoting to something unrelated based on AI.
  • Platform as a Service (PaaS) - Mentioned as a known service model, contrasted with "No as a Service."
  • Infrastructure as a Service (IaaS) - Mentioned as a known service model, contrasted with "No as a Service."
  • DB as a Service - Mentioned as a known service model, contrasted with "No as a Service."

---
Handpicked links, AI-assisted summaries. Human judgment, machine efficiency.
This content is a personally curated review and synopsis derived from the original podcast episode.