Skip to content

Commit

Permalink
Add type hints / type examples
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Dec 1, 2022
1 parent 17932e8 commit b9587d4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/attr/__init__.pyi
Expand Up @@ -342,6 +342,7 @@ def attrs(
on_setattr: Optional[_OnSetAttrArgType] = ...,
field_transformer: Optional[_FieldTransformer] = ...,
match_args: bool = ...,
unsafe_hash: Optional[bool] = ...,
) -> _C: ...
@overload
@__dataclass_transform__(order_default=True, field_descriptors=(attrib, field))
Expand Down Expand Up @@ -369,6 +370,7 @@ def attrs(
on_setattr: Optional[_OnSetAttrArgType] = ...,
field_transformer: Optional[_FieldTransformer] = ...,
match_args: bool = ...,
unsafe_hash: Optional[bool] = ...,
) -> Callable[[_C], _C]: ...
@overload
@__dataclass_transform__(field_descriptors=(attrib, field))
Expand All @@ -377,6 +379,7 @@ def define(
*,
these: Optional[Dict[str, Any]] = ...,
repr: bool = ...,
unsafe_hash: Optional[bool] = ...,
hash: Optional[bool] = ...,
init: bool = ...,
slots: bool = ...,
Expand All @@ -402,6 +405,7 @@ def define(
*,
these: Optional[Dict[str, Any]] = ...,
repr: bool = ...,
unsafe_hash: Optional[bool] = ...,
hash: Optional[bool] = ...,
init: bool = ...,
slots: bool = ...,
Expand Down
6 changes: 6 additions & 0 deletions tests/dataclass_transform_example.py
Expand Up @@ -55,3 +55,9 @@ class AliasedField:
af = AliasedField(42)

reveal_type(af.__init__) # noqa


# unsafe_hash is accepted
@attrs.define(unsafe_hash=True)
class Hashable:
pass
5 changes: 5 additions & 0 deletions tests/typing_example.py
Expand Up @@ -452,3 +452,8 @@ def accessing_from_attrs() -> None:
foo = object
if attrs.has(foo) or attr.has(foo):
foo.__attrs_attrs__


@attrs.define(unsafe_hash=True)
class Hashable:
pass

0 comments on commit b9587d4

Please sign in to comment.