ruff
1d6d45f2 - [ty] attrs: Support `__attrs_attrs__` and the `AttrsInstance` protocol (#30958)

Commit
1 day ago
[ty] attrs: Support `__attrs_attrs__` and the `AttrsInstance` protocol (#30958) ## Summary attrs stores field metadata in a class variable called `__attrs_attrs__`. ty now synthesizes this attribute on attrs classes and recognizes it as a required member of the `AttrsInstance` protocol. ```py import attrs @attrs.define class User: name: str User.__attrs_attrs__[0].name # str def inspect(cls: type) -> None: if attrs.has(cls): cls.__attrs_attrs__ # ty previously reported a missing attribute here attrs.asdict(User("Ada")) # ok attrs.asdict(object()) # ty now reports an invalid argument ``` [The attrs stubs](https://github.com/python-attrs/attrs/blob/4a8098356659f37a5832be17aa1d8a40be7d7cec/src/attr/_typing_compat.pyi#L6-L15) only declare `__attrs_attrs__: ClassVar[Any]` on the protocol for mypy. ty supplies that declaration when it's missing. This lets the existing `TypeGuard[type[AttrsInstance]]` on `attrs.has` work without any changes to attrs. Addresses [the `attrs.has` example in astral-sh/ty#2404](https://github.com/astral-sh/ty/issues/2404#issuecomment-7190831706). ## Ecosystem Those diagnostics look like improvements.
Author
Parents
Loading