首页›发现›编程›Brett Cannon

Brett Cannon

每周更新 · 约 0 篇0 人订阅en编程
snarky.ca

最近的文章

订阅后,这些文章和以后的新文章都会出现在你的阅读器里

What's missing to have reproducible builds on PyPI

AI 摘要The article argues that reproducible builds would strengthen Python's secure supply chain by allowing third parties to verify that distributions match their source code and detect tampering, citing SolarWinds as an example. What's missing includes recording the source code location in distribution metadata and support for software bills of materials (SBOMs) in sdists, which—unlike wheels—lack a place to store such data, though build backends could theoretically record build environments automatically without extra effort from distribution producers. The author also proposes that trusted verifiers could report successful reproductions to PyPI so users could see when a distribution was independently verified, framed as a perk rather than a requirement.

My nomination statement for the 2026 Python packaging council

AI 摘要The author announces his self-nomination for the inaugural 2026 Python Packaging Council (PPC), with support from his employer Microsoft but no employer pressure. He cites his qualifications, including over 23 years as a Python core developer, service on the first five Python Steering Councils, co-maintaining the packaging project, and authoring seven packaging PEPs such as PEP 518 and PEP 751. His goals for the PPC include drawing on his steering council experience to establish the new body, improving the developer experience for both package producers and consumers, and strengthening the secure supply chain through reproducible builds and software bills of materials (SBOMs).

How to publish to PyPI using GitHub Actions securely

AI 摘要The article outlines three relatively painless steps for securely publishing to PyPI with GitHub Actions: using the zizmor tool to fix insecure workflow defaults (broad token permissions, persisted credentials, and unpinned actions) both locally and in CI, and adopting Trusted Publishing with a GitHub environment that requires reviewer approval before any publishing workflow runs. The author stresses that the post is not meant to shame maintainers into using GitHub Actions or Trusted Publishing, and recommends keeping build and publish workflows separate. Together, these measures guard against accidental or malicious workflow triggers while letting GitHub's security team handle the PyPI communication concerns.

Why I wrote PEP 832 -- virtual environment discovery

AI 摘要The article explains why the author wrote PEP 832, addressing the problem that tools like VS Code (or any editor or AI agent) cannot easily determine which workflow tool a Python project uses or where its virtual environments are located. It outlines key difficulties—such as discovering environments on first project open, handling environments stored outside the project or shared across projects via tools like conda—and proposes solutions including detecting .venv directories, a .python-envs file listing environment paths, and a [workflow] table in pyproject.toml paired with a workflow server protocol (WSP) for JSON-RPC communication between tools. The author's motivation is to make project setup as easy as possible for users of all experience levels by hiding environment management, while creating a general, editor-agnostic standard rather than the VS Code-specific bespoke integrations that exist today.

Why pylock.toml includes digital attestations

AI 摘要The article explains that a Python project hack involving malicious PyPI uploads could have been detected if the project used trusted publishing with digital attestations, since pylock.toml lock files record publisher details (e.g., the GitHub repo and workflow) for each file. Trusted publishing lets CD systems upload releases without exposing API keys, while attestations verify a file's origin, allowing users to compare the lock file's recorded publisher against PyPI's data to spot discrepancies. The author recommends that maintainers enable trusted publishing and attestations, and that users verify attestations in lock files via code or manual review of diffs to catch suspicious changes or deletions.

State of WASI support for CPython: March 2026

AI 摘要Recent WASI work in CPython has focused on easing maintenance and development, including a WASI dev container, updated devguide instructions, and a CLI app. PEP 816, which defines WASI compatibility handling starting with Python 3.15, was accepted; it locks in supported WASI and WASI SDK versions once a Python version reaches its first beta, giving the community a stable target for building packages. Next steps include implementing a subcommand to bundle WASI builds for distribution, writing a PEP for a wheel platform tag, adding a subcommand to build dependencies, and enabling socket support once WASI 0.3 and threading support are released.

CLI subcommands with lazy imports

AI 摘要The article explains how Python 3.15's newly accepted PEP 810 lazy imports can benefit CLIs by only importing modules needed for the chosen subcommand. It shows why the standard argparse approaches for subcommands—dict-based dispatch or subparser defaults—break lazy imports, since assignment reifies the lazy object and triggers the actual import. Two workarounds are proposed: dispatching via a match statement, or wrapping the lazy import in a lambda to add a layer of indirection.

Should I rewrite the Python Launcher for Unix in Python?

AI 摘要The author reflects on whether to rewrite the Python Launcher for Unix, originally written in Rust, in pure Python. After testing performance (Python was ~11x slower but still fast enough for a developer tool), finding distribution channels viable via PyPI, package managers, and Briefcase, and considering their limited spare time as a parent, they lean toward Python for faster development and broader contributions. The post ends with the author still asking whether they have talked themselves into the rewrite.

The varying strictness of TypedDict

AI 摘要While passing a TypedDict to httpx's params parameter, the author found that type checkers like Pyright reject an open TypedDict when a Mapping[str, str] is expected, because any keys not defined in the TypedDict are assumed to have values of type object. Starting in Python 3.15 (and available in typing-extensions today), PEP 728 adds a second dimension of strictness via the closed=True argument and the extra_items parameter, which let you restrict or type unspecified keys. Using these features, the TypedDict can be treated as a closed mapping whose values are all str, making it compatible with Mapping[str, str].

Why it took 4 years to get a lock files specification

AI 摘要The author recounts the four-plus-year effort to create a standardized Python lock file specification, culminating in PEP 751 and the pylock.toml format being accepted in March 2025. The journey involved early discussions starting in 2019, the rejection of PEP 665 in 2022 due to its wheels-only approach, and multiple drafts of PEP 751 that had to balance the needs and disagreements of tools like uv, Poetry, and PDM across nearly 2,000 forum posts. Despite burnout and setbacks—including scaling back features to reach consensus—the final spec supports multi-use, cross-platform lock files, and tools like PDM, uv, and pip have already begun adopting it.

Unravelling t-strings

AI 摘要The article explains t-strings, a new feature introduced by PEP 750 for Python 3.14, describing them as a syntactic way to access the f-string parser. It walks step-by-step through how a t-string unravels into a Template object containing plain string parts and Interpolation objects that hold each replacement field's value, expression, conversion, and format spec, demonstrated via a function that converts a t-string into its f-string equivalent. The author suggests potential uses such as safely compiling SQL or HTML to prevent injection attacks, and points to PEP 787 as an example of novel applications the community may develop.

Why I won't be attending PyCon US this year

AI 摘要The author announces they will skip PyCon US for the first time since 2003 in protest of the US trade war against Canada, viewing the tariffs as an economic act of war motivated by a desire to weaken and potentially annex Canada rather than by fentanyl concerns. They emphasize they don't blame Americans who voted differently, but plan to avoid US travel for the foreseeable future and attend Python community events outside the country instead. They believe the Canada-US relationship has been damaged for at least a generation, and will only consider returning once all tariffs are completely repealed.

My impressions of Gleam

AI 摘要The author shares their positive impressions of Gleam, a small, typed, functional language they learned in two days and used to build a client-side coding font tournament website with the Lustre framework. They appreciated Gleam's friendly community, tight design, and ability to compile to both Erlang and JavaScript, though they found minor annoyances like curly-brace syntax and having to write record type names twice. Although a similar project called CodingFont already existed, so they didn't launch their site, the author remains happy with Gleam and hopes for future WebAssembly/WASI and Python back-ends.

What the PSF Conduct WG does

AI 摘要The PSF Conduct WG has four main functions: maintaining the PSF Code of Conduct, notifying PSF members who violate it publicly while promoting their membership, recording conduct violations reported by other groups, and providing advice to Python community groups that ask for it. Contrary to common misunderstandings, the WG does not proactively search for violations or misconduct online, and it has no power to compel any group or individual to take action—enforcement and moderation remain entirely with the groups seeking its advice. Its most frequent activity by far is offering guidance, which groups typically (though not mandatorily) choose to follow.

Don't return named tuples in new APIs

AI 摘要The author argues that named tuples should only be used when updating an existing API that already returns a plain tuple, not when designing new APIs. Although named tuples are quick to define, they double the API surface by requiring support and testing for both index-based and attribute-based access, while also exposing unwanted tuple behaviors like slicing and iteration. Instead, alternatives such as dataclasses, TypedDict, or types.SimpleNamespace should be preferred, prioritizing readability and ergonomics over brevity.