Merge branch 'audit/built-in-classes-enhancement'

This commit is contained in:
Vinta Chen
2026-11-08 20:41:37 +08:00
3 changed files with 12 additions and 4 deletions
+8 -4
View File
@@ -1050,10 +1050,14 @@ _Implementations of Python._
_Libraries for enhancing Python built-in classes._
- [attrs](https://github.com/python-attrs/attrs) - Replacement for `__init__`, `__eq__`, `__repr__`, etc. boilerplate in class definitions.
- [bidict](https://github.com/jab/bidict) - Efficient, Pythonic bidirectional map data structures and related functionality.
- [uuid-utils](https://github.com/aminalaee/uuid-utils) - A fast, Rust-backed drop-in replacement for Python's built-in `uuid` module.
- [python-box](https://github.com/cdgriffith/Box) - Python dictionaries with advanced dot notation access.
- Class Boilerplate
- [dataclasses](https://docs.python.org/3/library/dataclasses.html) - (Python standard library) Adds generated special methods such as `__init__()` and `__repr__()` to your classes.
- [attrs](https://github.com/python-attrs/attrs) - Writes `__init__`, `__eq__`, `__repr__`, and other boilerplate methods for your classes.
- Mappings
- [python-box](https://github.com/cdgriffith/Box) - Python dictionaries with advanced dot-notation access.
- [bidict](https://github.com/jab/bidict) - Efficient, Pythonic bidirectional map data structures.
- UUID
- [uuid-utils](https://github.com/aminalaee/uuid-utils) - A fast, Rust-backed drop-in replacement for Python's built-in `uuid` module.
### Functional Programming
@@ -4,9 +4,12 @@ How to choose:
- Classes with generated dunder methods, validators, and converters: attrs
- Dicts read with dot notation, nested ones included: python-box
- Generated dunder methods with nothing to install: dataclasses
- Looking up a key by its value, with both directions in sync: bidict
- A faster drop-in for the `uuid` module: uuid-utils
The standard library's dataclasses [adds generated special methods](https://docs.python.org/3/library/dataclasses.html) such as `__init__()` and `__repr__()` to your classes. Put `@dataclass` on a class, and every class variable with a type annotation becomes a field. Pass `frozen=True` for [read-only instances](https://docs.python.org/3/library/dataclasses.html#frozen-instances).
attrs [writes the dunder methods](https://www.attrs.org/en/latest/) that implement object protocols, so you don't have to. For new code, its docs [recommend the modern API](https://www.attrs.org/en/latest/names.html#tl-dr): `@define` on the class and `field()` for an attribute, or `@frozen` for immutable instances, with slots on by default. Type annotations stay optional. The standard library's dataclasses [gave up features for simplicity](https://www.attrs.org/en/latest/why.html#data-classes), like validators and converters, so a class that needs them goes to attrs. It [isn't a full serialization library](https://www.attrs.org/en/latest/overview.html#what-attrs-is-not), though: to serialize and validate your attrs classes, its docs point you to its sibling project, cattrs.
python-box installs Box, a [`dict` subclass](https://github.com/cdgriffith/Box) whose keys you can also read as attributes, even ones like `"imdb stars"`. Nested dicts and lists become Box and BoxList objects, so dot access works all the way down: `movie_box.Robin_Hood_Men_in_Tights.imdb_stars`. It [reads and writes JSON, YAML, TOML, and msgpack](https://github.com/cdgriffith/Box/wiki/Converters) with methods like `from_json()` and `to_json()`, and `to_dict()` gives you plain dicts back. Keep Box for data whose keys change: attrs' docs say a dict with a fixed and known set of keys [is an object, not a hash](https://www.attrs.org/en/latest/why.html#dicts), and belongs in a class.
+1
View File
@@ -6,6 +6,7 @@
"concurrent-futures": { "package": null, "reason": "stdlib module" },
"conda": { "package": null, "reason": "installed via Miniforge or Anaconda installers; PyPI conda is a stale 2017 upload" },
"cpython": { "package": null, "reason": "not pip-installable; the cpython PyPI name was squatted" },
"dataclasses": { "package": null, "reason": "stdlib module; PyPI dataclasses is the Python 3.6 backport" },
"devpi": { "package": "devpi-server", "reason": "devpi is a deprecated metapackage; the server package carries real usage" },
"difflib": { "package": null, "reason": "stdlib module" },
"django-ai-plugins": { "package": null, "reason": "GitHub-only so far; young project, remap if it publishes" },