-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Recognise new 'attrs' package name in the attrs plugin
- Loading branch information
1 parent
7ac5a19
commit 433544b
Showing
4 changed files
with
181 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
from typing import TypeVar, overload, Callable, Any, Optional, Union, Sequence, Mapping | ||
|
||
_T = TypeVar('_T') | ||
_C = TypeVar('_C', bound=type) | ||
|
||
_ValidatorType = Callable[[Any, Any, _T], Any] | ||
_ConverterType = Callable[[Any], _T] | ||
_ValidatorArgType = Union[_ValidatorType[_T], Sequence[_ValidatorType[_T]]] | ||
|
||
@overload | ||
def define( | ||
maybe_cls: _C, | ||
*, | ||
these: Optional[Mapping[str, Any]] = ..., | ||
repr: bool = ..., | ||
hash: Optional[bool] = ..., | ||
init: bool = ..., | ||
slots: bool = ..., | ||
frozen: bool = ..., | ||
weakref_slot: bool = ..., | ||
str: bool = ..., | ||
auto_attribs: bool = ..., | ||
kw_only: bool = ..., | ||
cache_hash: bool = ..., | ||
auto_exc: bool = ..., | ||
eq: Optional[bool] = ..., | ||
order: Optional[bool] = ..., | ||
auto_detect: bool = ..., | ||
getstate_setstate: Optional[bool] = ..., | ||
on_setattr: Optional[object] = ..., | ||
) -> _C: ... | ||
@overload | ||
def define( | ||
maybe_cls: None = ..., | ||
*, | ||
these: Optional[Mapping[str, Any]] = ..., | ||
repr: bool = ..., | ||
hash: Optional[bool] = ..., | ||
init: bool = ..., | ||
slots: bool = ..., | ||
frozen: bool = ..., | ||
weakref_slot: bool = ..., | ||
str: bool = ..., | ||
auto_attribs: bool = ..., | ||
kw_only: bool = ..., | ||
cache_hash: bool = ..., | ||
auto_exc: bool = ..., | ||
eq: Optional[bool] = ..., | ||
order: Optional[bool] = ..., | ||
auto_detect: bool = ..., | ||
getstate_setstate: Optional[bool] = ..., | ||
on_setattr: Optional[object] = ..., | ||
) -> Callable[[_C], _C]: ... | ||
|
||
mutable = define | ||
frozen = define # they differ only in their defaults | ||
|
||
@overload | ||
def field( | ||
*, | ||
default: None = ..., | ||
validator: None = ..., | ||
repr: object = ..., | ||
hash: Optional[bool] = ..., | ||
init: bool = ..., | ||
metadata: Optional[Mapping[Any, Any]] = ..., | ||
converter: None = ..., | ||
factory: None = ..., | ||
kw_only: bool = ..., | ||
eq: Optional[bool] = ..., | ||
order: Optional[bool] = ..., | ||
on_setattr: Optional[_OnSetAttrArgType] = ..., | ||
) -> Any: ... | ||
|
||
# This form catches an explicit None or no default and infers the type from the | ||
# other arguments. | ||
@overload | ||
def field( | ||
*, | ||
default: None = ..., | ||
validator: Optional[_ValidatorArgType[_T]] = ..., | ||
repr: object = ..., | ||
hash: Optional[bool] = ..., | ||
init: bool = ..., | ||
metadata: Optional[Mapping[Any, Any]] = ..., | ||
converter: Optional[_ConverterType] = ..., | ||
factory: Optional[Callable[[], _T]] = ..., | ||
kw_only: bool = ..., | ||
eq: Optional[bool] = ..., | ||
order: Optional[bool] = ..., | ||
on_setattr: Optional[object] = ..., | ||
) -> _T: ... | ||
|
||
# This form catches an explicit default argument. | ||
@overload | ||
def field( | ||
*, | ||
default: _T, | ||
validator: Optional[_ValidatorArgType[_T]] = ..., | ||
repr: object = ..., | ||
hash: Optional[bool] = ..., | ||
init: bool = ..., | ||
metadata: Optional[Mapping[Any, Any]] = ..., | ||
converter: Optional[_ConverterType] = ..., | ||
factory: Optional[Callable[[], _T]] = ..., | ||
kw_only: bool = ..., | ||
eq: Optional[bool] = ..., | ||
order: Optional[bool] = ..., | ||
on_setattr: Optional[object] = ..., | ||
) -> _T: ... | ||
|
||
# This form covers type=non-Type: e.g. forward references (str), Any | ||
@overload | ||
def field( | ||
*, | ||
default: Optional[_T] = ..., | ||
validator: Optional[_ValidatorArgType[_T]] = ..., | ||
repr: object = ..., | ||
hash: Optional[bool] = ..., | ||
init: bool = ..., | ||
metadata: Optional[Mapping[Any, Any]] = ..., | ||
converter: Optional[_ConverterType] = ..., | ||
factory: Optional[Callable[[], _T]] = ..., | ||
kw_only: bool = ..., | ||
eq: Optional[bool] = ..., | ||
order: Optional[bool] = ..., | ||
on_setattr: Optional[object] = ..., | ||
) -> Any: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from typing import TypeVar, Optional, Callable, overload | ||
from attr import _ConverterType | ||
|
||
_T = TypeVar("_T") | ||
|
||
def optional( | ||
converter: _ConverterType[_T] | ||
) -> _ConverterType[Optional[_T]]: ... | ||
@overload | ||
def default_if_none(default: _T) -> _ConverterType[_T]: ... | ||
@overload | ||
def default_if_none(*, factory: Callable[[], _T]) -> _ConverterType[_T]: ... |