Skip to content

Commit 7a75e4d

Browse files
Added missing type argument for Attribute class when used in type stubs. With this change, all exported symbols from the library have well-defined and fully-known types (a "type completeness score" of 100% according to pyright). (#785)
Co-authored-by: Eric Traut <[email protected]>
1 parent 51e6dcf commit 7a75e4d

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/attr/__init__.pyi

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ _OnSetAttrType = Callable[[Any, Attribute[Any], Any], Any]
4949
_OnSetAttrArgType = Union[
5050
_OnSetAttrType, List[_OnSetAttrType], setters._NoOpType
5151
]
52-
_FieldTransformer = Callable[[type, List[Attribute]], List[Attribute]]
52+
_FieldTransformer = Callable[[type, List[Attribute[Any]]], List[Attribute[Any]]]
5353
# FIXME: in reality, if multiple validators are passed they must be in a list
5454
# or tuple, but those are invariant and so would prevent subtypes of
5555
# _ValidatorType from working when passed in a list or tuple.
@@ -103,7 +103,7 @@ class Attribute(Generic[_T]):
103103
kw_only: bool
104104
on_setattr: _OnSetAttrType
105105

106-
def evolve(self, **changes: Any) -> "Attribute": ...
106+
def evolve(self, **changes: Any) -> "Attribute[Any]": ...
107107

108108
# NOTE: We had several choices for the annotation to use for type arg:
109109
# 1) Type[_T]
@@ -386,7 +386,7 @@ def resolve_types(
386386
cls: _C,
387387
globalns: Optional[Dict[str, Any]] = ...,
388388
localns: Optional[Dict[str, Any]] = ...,
389-
attribs: Optional[List[Attribute]] = ...,
389+
attribs: Optional[List[Attribute[Any]]] = ...,
390390
) -> _C: ...
391391

392392
# TODO: add support for returning a proper attrs class from the mypy plugin
@@ -429,7 +429,7 @@ def asdict(
429429
filter: Optional[_FilterType[Any]] = ...,
430430
dict_factory: Type[Mapping[Any, Any]] = ...,
431431
retain_collection_types: bool = ...,
432-
value_serializer: Optional[Callable[[type, Attribute, Any], Any]] = ...,
432+
value_serializer: Optional[Callable[[type, Attribute[Any], Any], Any]] = ...,
433433
) -> Dict[str, Any]: ...
434434

435435
# TODO: add support for returning NamedTuple from the mypy plugin

src/attr/setters.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ from . import Attribute, _OnSetAttrType
66
_T = TypeVar("_T")
77

88
def frozen(
9-
instance: Any, attribute: Attribute, new_value: Any
9+
instance: Any, attribute: Attribute[Any], new_value: Any
1010
) -> NoReturn: ...
1111
def pipe(*setters: _OnSetAttrType) -> _OnSetAttrType: ...
1212
def validate(instance: Any, attribute: Attribute[_T], new_value: _T) -> _T: ...

0 commit comments

Comments
 (0)