Skip to content

Commit

Permalink
Modernize the rest of the stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinche committed Feb 2, 2024
1 parent d1e3a7f commit 4ba45bf
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 38 deletions.
14 changes: 7 additions & 7 deletions src/attr/_cmp.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from typing import Any, Callable, Optional, Type
from typing import Any, Callable

_CompareWithType = Callable[[Any, Any], bool]

def cmp_using(
eq: Optional[_CompareWithType] = ...,
lt: Optional[_CompareWithType] = ...,
le: Optional[_CompareWithType] = ...,
gt: Optional[_CompareWithType] = ...,
ge: Optional[_CompareWithType] = ...,
eq: _CompareWithType | None = ...,
lt: _CompareWithType | None = ...,
le: _CompareWithType | None = ...,
gt: _CompareWithType | None = ...,
ge: _CompareWithType | None = ...,
require_same_type: bool = ...,
class_name: str = ...,
) -> Type: ...
) -> type: ...
2 changes: 1 addition & 1 deletion src/attr/converters.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Callable, TypeVar, overload

from . import _ConverterType
from attrs import _ConverterType

_T = TypeVar("_T")

Expand Down
6 changes: 3 additions & 3 deletions src/attr/filters.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Union
from typing import Any

from . import Attribute, _FilterType

def include(*what: Union[type, str, Attribute[Any]]) -> _FilterType[Any]: ...
def exclude(*what: Union[type, str, Attribute[Any]]) -> _FilterType[Any]: ...
def include(*what: type | str | Attribute[Any]) -> _FilterType[Any]: ...
def exclude(*what: type | str | Attribute[Any]) -> _FilterType[Any]: ...
3 changes: 2 additions & 1 deletion src/attr/setters.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any, NewType, NoReturn, TypeVar

from . import Attribute, _OnSetAttrType
from . import Attribute
from attrs import _OnSetAttrType

_T = TypeVar("_T")

Expand Down
47 changes: 21 additions & 26 deletions src/attr/validators.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@ from typing import (
Container,
ContextManager,
Iterable,
List,
Mapping,
Match,
Optional,
Pattern,
Tuple,
Type,
TypeVar,
Union,
overload,
)

from . import _ValidatorType
from . import _ValidatorArgType
from attrs import _ValidatorType
from attrs import _ValidatorArgType

_T = TypeVar("_T")
_T1 = TypeVar("_T1")
Expand All @@ -36,42 +31,42 @@ def disabled() -> ContextManager[None]: ...
# To be more precise on instance_of use some overloads.
# If there are more than 3 items in the tuple then we fall back to Any
@overload
def instance_of(type: Type[_T]) -> _ValidatorType[_T]: ...
def instance_of(type: type[_T]) -> _ValidatorType[_T]: ...
@overload
def instance_of(type: Tuple[Type[_T]]) -> _ValidatorType[_T]: ...
def instance_of(type: tuple[type[_T]]) -> _ValidatorType[_T]: ...
@overload
def instance_of(
type: Tuple[Type[_T1], Type[_T2]]
) -> _ValidatorType[Union[_T1, _T2]]: ...
type: tuple[type[_T1], type[_T2]]
) -> _ValidatorType[_T1 | _T2]: ...
@overload
def instance_of(
type: Tuple[Type[_T1], Type[_T2], Type[_T3]]
) -> _ValidatorType[Union[_T1, _T2, _T3]]: ...
type: tuple[type[_T1], type[_T2], type[_T3]]
) -> _ValidatorType[_T1 | _T2 | _T3]: ...
@overload
def instance_of(type: Tuple[type, ...]) -> _ValidatorType[Any]: ...
def instance_of(type: tuple[type, ...]) -> _ValidatorType[Any]: ...
def provides(interface: Any) -> _ValidatorType[Any]: ...
def optional(
validator: Union[
_ValidatorType[_T], List[_ValidatorType[_T]], Tuple[_ValidatorType[_T]]
]
) -> _ValidatorType[Optional[_T]]: ...
validator: (
_ValidatorType[_T]
| list[_ValidatorType[_T]]
| tuple[_ValidatorType[_T]]
),
) -> _ValidatorType[_T | None]: ...
def in_(options: Container[_T]) -> _ValidatorType[_T]: ...
def and_(*validators: _ValidatorType[_T]) -> _ValidatorType[_T]: ...
def matches_re(
regex: Union[Pattern[AnyStr], AnyStr],
regex: Pattern[AnyStr] | AnyStr,
flags: int = ...,
func: Optional[
Callable[[AnyStr, AnyStr, int], Optional[Match[AnyStr]]]
] = ...,
func: Callable[[AnyStr, AnyStr, int], Match[AnyStr] | None] | None = ...,
) -> _ValidatorType[AnyStr]: ...
def deep_iterable(
member_validator: _ValidatorArgType[_T],
iterable_validator: Optional[_ValidatorType[_I]] = ...,
iterable_validator: _ValidatorType[_I] | None = ...,
) -> _ValidatorType[_I]: ...
def deep_mapping(
key_validator: _ValidatorType[_K],
value_validator: _ValidatorType[_V],
mapping_validator: Optional[_ValidatorType[_M]] = ...,
mapping_validator: _ValidatorType[_M] | None = ...,
) -> _ValidatorType[_M]: ...
def is_callable() -> _ValidatorType[_T]: ...
def lt(val: _T) -> _ValidatorType[_T]: ...
Expand All @@ -83,6 +78,6 @@ def min_len(length: int) -> _ValidatorType[_T]: ...
def not_(
validator: _ValidatorType[_T],
*,
msg: Optional[str] = None,
exc_types: Union[Type[Exception], Iterable[Type[Exception]]] = ...,
msg: str | None = None,
exc_types: type[Exception] | Iterable[type[Exception]] = ...,
) -> _ValidatorType[_T]: ...

0 comments on commit 4ba45bf

Please sign in to comment.