You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Feature
Recently, mypy added a plugin for attr.fields that tries to detect whether a type is an attr.s-decorated class, and reports an error if it isn't. However, attrs has a couple ways to check or annotate that a class is an attr.s-decorated class: attr.has and attr.AttrsInstance, neither of which seem to be supported by mypy right now.
attr.AttrsInstance is a protocol defined in the attrs internal stubs (https://github.com/python-attrs/attrs/blob/main/src/attr/__init__.pyi#L74) that represents that an object of an attr.s-decorated class. Right now, the plugin doesn't recognize attr.AttrsInstance, so it will report an error when trying to call e.g. attr.fields on a type[attr.AttrsInstance].
attr.has is a method that checks whether a class is attr.s-decorated. The plugin won't recognize this as a valid way to ensure attrs version 22.2.0 updated the internal stubs for attr.has to be a TypeGuard for type[attr.AttrsInstance]: (https://github.com/python-attrs/attrs/blob/main/src/attr/__init__.pyi#L541), so supporting attr.AttrsInstance may be sufficient when using sufficiently new stubs for attrs.
@hauntsaninja this is the thing that I was having trouble with with the new behavior of the plugin. I think it probably counts as a feature request because we didn't really support these before either, we just wouldn't error on them because we didn't check the types around attr.fields.
Since python-attrs/attrs#890 (≥ 22.1.0)
`attrs.fields` is typed to accept a protocol.
Since python-attrs/attrs#997 (≥ 22.2.0)
`attrs.has` is a type-guard.
Support both by removing the explicit error reporting and letting it
fall through to the type stub.
Fixes#15980.
Feature
Recently, mypy added a plugin for
attr.fields
that tries to detect whether a type is anattr.s
-decorated class, and reports an error if it isn't. However,attrs
has a couple ways to check or annotate that a class is anattr.s
-decorated class:attr.has
andattr.AttrsInstance
, neither of which seem to be supported by mypy right now.attr.AttrsInstance
is a protocol defined in the attrs internal stubs (https://github.com/python-attrs/attrs/blob/main/src/attr/__init__.pyi#L74) that represents that an object of anattr.s
-decorated class. Right now, the plugin doesn't recognizeattr.AttrsInstance
, so it will report an error when trying to call e.g.attr.fields
on atype[attr.AttrsInstance]
.attr.has
is a method that checks whether a class isattr.s
-decorated. The plugin won't recognize this as a valid way to ensureattrs
version 22.2.0 updated the internal stubs forattr.has
to be aTypeGuard
fortype[attr.AttrsInstance]
: (https://github.com/python-attrs/attrs/blob/main/src/attr/__init__.pyi#L541), so supportingattr.AttrsInstance
may be sufficient when using sufficiently new stubs forattrs
.Pitch
A possible use for
attr.has
:A possible use for
attr.AttrsInstance
:The text was updated successfully, but these errors were encountered: