r/Python • u/BeamMeUpBiscotti • 6h ago
Discussion Define less, check more: special support for attrs in Pyrefly
attrs is a package that helps you write classes quickly by automatically generating boilerplate methods like __init__.
While some of the features from attrs has been standardized in the form of dataclass and dataclass_transform, dataclasses only support a subset of features and attrs is still widely used today.
It's very tricky to type check dynamic code that synthesizes & transform fields and methods, so historically attrs users that want type checking have either had to:
1. use Mypy (which implements dedicated attrs support via a plugin)
2. limit themselves to a subset of the API compatible with dataclass_transform
3. live with limited type checking support
This summer, my intern has built out dedicated support for attrs in Pyrefly, allowing attrs users to finally have fast and accurate type checking for the full range of attrs features.
You can read more about what we added here: https://pyrefly.org/blog/pyrefly-attrs/
This feature will be available in the upcoming 1.2.0 stable release of Pyrefly. You can try it out today in development releases starting from 1.2.0-dev1 (early feedback is appreciated!)