mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-05-04 20:45:49 +08:00
[assertpy] Replace or explain Anys (#15144)
This commit is contained in:
@@ -1,12 +1,7 @@
|
||||
# Python 2 compatibility cruft:
|
||||
assertpy.collection.Iterable
|
||||
assertpy\..+\.Iterable(\.__class_getitem__)?
|
||||
assertpy.contains.str_types
|
||||
assertpy.contains.xrange
|
||||
assertpy.dynamic.Iterable
|
||||
assertpy.exception.Iterable
|
||||
assertpy.extracting.Iterable
|
||||
assertpy.extracting.str_types
|
||||
assertpy.file.str_types
|
||||
assertpy.helpers.Iterable
|
||||
assertpy.string.Iterable
|
||||
assertpy.string.str_types
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import logging
|
||||
from collections.abc import Callable, Generator
|
||||
from typing import Any
|
||||
from typing import Any, TypeVar
|
||||
from typing_extensions import Self
|
||||
|
||||
from .base import BaseMixin
|
||||
@@ -17,11 +17,14 @@ from .numeric import NumericMixin
|
||||
from .snapshot import SnapshotMixin
|
||||
from .string import StringMixin
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_V = TypeVar("_V", default=Any)
|
||||
|
||||
__version__: str
|
||||
__tracebackhide__: bool
|
||||
|
||||
class WarningLoggingAdapter(logging.LoggerAdapter[logging.Logger]):
|
||||
def process(self, msg: str, kwargs: Any) -> tuple[str, Any]: ...
|
||||
def process(self, msg: str, kwargs: _T) -> tuple[str, _T]: ...
|
||||
|
||||
class AssertionBuilder(
|
||||
StringMixin,
|
||||
@@ -34,18 +37,18 @@ class AssertionBuilder(
|
||||
DynamicMixin,
|
||||
DictMixin,
|
||||
DateMixin,
|
||||
ContainsMixin,
|
||||
CollectionMixin,
|
||||
ContainsMixin[_V],
|
||||
CollectionMixin[_V],
|
||||
BaseMixin,
|
||||
):
|
||||
val: Any
|
||||
val: _V
|
||||
description: str
|
||||
kind: str | None
|
||||
expected: BaseException | None
|
||||
logger: logging.Logger
|
||||
def __init__(
|
||||
self,
|
||||
val: Any,
|
||||
val: _V,
|
||||
description: str = "",
|
||||
kind: str | None = None,
|
||||
expected: BaseException | None = None,
|
||||
@@ -53,7 +56,7 @@ class AssertionBuilder(
|
||||
) -> None: ...
|
||||
def builder(
|
||||
self,
|
||||
val: Any,
|
||||
val: _V,
|
||||
description: str = "",
|
||||
kind: str | None = None,
|
||||
expected: BaseException | None = None,
|
||||
@@ -61,9 +64,9 @@ class AssertionBuilder(
|
||||
) -> Self: ...
|
||||
def error(self, msg: str) -> Self: ...
|
||||
|
||||
def soft_assertions() -> Generator[None, None, None]: ...
|
||||
def assert_that(val: Any, description: str = "") -> AssertionBuilder: ...
|
||||
def assert_warn(val: Any, description: str = "", logger: logging.Logger | None = None) -> AssertionBuilder: ...
|
||||
def soft_assertions() -> Generator[None]: ...
|
||||
def assert_that(val: _V, description: str = "") -> AssertionBuilder[_V]: ...
|
||||
def assert_warn(val: _V, description: str = "", logger: logging.Logger | None = None) -> AssertionBuilder: ...
|
||||
def fail(msg: str = "") -> None: ...
|
||||
def soft_fail(msg: str = "") -> None: ...
|
||||
def add_extension(func: Callable[[AssertionBuilder], AssertionBuilder]) -> None: ...
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from typing import Any
|
||||
from typing_extensions import Self, TypeAlias
|
||||
|
||||
__tracebackhide__: bool
|
||||
@@ -8,10 +7,10 @@ _IncludeIgnore: TypeAlias = str | list[str] | list[tuple[str, ...]] | None
|
||||
class BaseMixin:
|
||||
description: str
|
||||
def described_as(self, description: str) -> Self: ...
|
||||
def is_equal_to(self, other: Any, *, include: _IncludeIgnore = None, ignore: _IncludeIgnore = None) -> Self: ...
|
||||
def is_not_equal_to(self, other: Any) -> Self: ...
|
||||
def is_same_as(self, other: Any) -> Self: ...
|
||||
def is_not_same_as(self, other: Any) -> Self: ...
|
||||
def is_equal_to(self, other: object, *, include: _IncludeIgnore = None, ignore: _IncludeIgnore = None) -> Self: ...
|
||||
def is_not_equal_to(self, other: object) -> Self: ...
|
||||
def is_same_as(self, other: object) -> Self: ...
|
||||
def is_not_same_as(self, other: object) -> Self: ...
|
||||
def is_true(self) -> Self: ...
|
||||
def is_false(self) -> Self: ...
|
||||
def is_none(self) -> Self: ...
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
from _typeshed import SupportsRichComparison
|
||||
from collections.abc import Callable
|
||||
from typing import Any
|
||||
from typing import Any, Generic, Literal, TypeVar, overload
|
||||
from typing_extensions import Self
|
||||
|
||||
__tracebackhide__: bool
|
||||
|
||||
class CollectionMixin:
|
||||
_V = TypeVar("_V", default=Any)
|
||||
|
||||
class CollectionMixin(Generic[_V]):
|
||||
def is_iterable(self) -> Self: ...
|
||||
def is_not_iterable(self) -> Self: ...
|
||||
def is_subset_of(self, *supersets: Any) -> Self: ...
|
||||
def is_sorted(self, key: Callable[[Any], Any] = ..., reverse: bool = False) -> Self: ...
|
||||
def is_subset_of(self, *supersets: _V) -> Self: ...
|
||||
@overload
|
||||
def is_sorted(self, key: Callable[[_V], SupportsRichComparison] = ..., reverse: Literal[False] = False) -> Self: ...
|
||||
@overload
|
||||
def is_sorted(self, *, reverse: Literal[True]) -> Self: ...
|
||||
@overload
|
||||
def is_sorted(self, key: Callable[[_V], SupportsRichComparison], reverse: Literal[True]) -> Self: ...
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
from typing import Any
|
||||
from typing import Any, Generic, TypeVar
|
||||
from typing_extensions import Self
|
||||
|
||||
__tracebackhide__: bool
|
||||
|
||||
class ContainsMixin:
|
||||
def contains(self, *items: Any) -> Self: ...
|
||||
def does_not_contain(self, *items: Any) -> Self: ...
|
||||
def contains_only(self, *items: Any) -> Self: ...
|
||||
def contains_sequence(self, *items: Any) -> Self: ...
|
||||
_V = TypeVar("_V", default=Any)
|
||||
|
||||
class ContainsMixin(Generic[_V]):
|
||||
def contains(self, *items: object) -> Self: ...
|
||||
def does_not_contain(self, *items: object) -> Self: ...
|
||||
def contains_only(self, *items: object) -> Self: ...
|
||||
def contains_sequence(self, *items: object) -> Self: ...
|
||||
def contains_duplicates(self) -> Self: ...
|
||||
def does_not_contain_duplicates(self) -> Self: ...
|
||||
def is_empty(self) -> Self: ...
|
||||
def is_not_empty(self) -> Self: ...
|
||||
def is_in(self, *items: Any) -> Self: ...
|
||||
def is_not_in(self, *items: Any) -> Self: ...
|
||||
def is_in(self, *items: _V) -> Self: ...
|
||||
def is_not_in(self, *items: _V) -> Self: ...
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
from collections.abc import Iterable
|
||||
from typing import Any
|
||||
from typing_extensions import Self
|
||||
|
||||
__tracebackhide__: bool
|
||||
|
||||
class DictMixin:
|
||||
def contains_key(self, *keys: Any) -> Self: ...
|
||||
def does_not_contain_key(self, *keys: Any) -> Self: ...
|
||||
def contains_value(self, *values: Any) -> Self: ...
|
||||
def does_not_contain_value(self, *values: Any) -> Self: ...
|
||||
def contains_entry(self, *args: Any, **kwargs: dict[str, Any]) -> Self: ...
|
||||
def does_not_contain_entry(self, *args: Any, **kwargs: dict[str, Any]) -> Self: ...
|
||||
def contains_key(self, *keys: object) -> Self: ...
|
||||
def does_not_contain_key(self, *keys: object) -> Self: ...
|
||||
def contains_value(self, *values: object) -> Self: ...
|
||||
def does_not_contain_value(self, *values: object) -> Self: ...
|
||||
# The dicts can contain arbitrary keys and values
|
||||
def contains_entry(self, *args: Iterable[dict[Any, Any]], **kwargs: Any) -> Self: ...
|
||||
def does_not_contain_entry(self, *args: Iterable[dict[Any, Any]], **kwargs: Any) -> Self: ...
|
||||
|
||||
@@ -4,4 +4,4 @@ from typing_extensions import Self
|
||||
__tracebackhide__: bool
|
||||
|
||||
class DynamicMixin:
|
||||
def __getattr__(self, attr: str) -> Callable[..., Self]: ...
|
||||
def __getattr__(self, attr: str) -> Callable[[object], Self]: ...
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from collections.abc import Callable, Iterable as _Iterable, Mapping
|
||||
from _typeshed import SupportsRichComparison
|
||||
from collections.abc import Callable, Iterable, Mapping
|
||||
from typing import Any
|
||||
from typing_extensions import Self
|
||||
|
||||
@@ -8,6 +9,7 @@ class ExtractingMixin:
|
||||
def extracting(
|
||||
self,
|
||||
*names: str,
|
||||
# The callable must accept the type of the items in the self.val collection.
|
||||
filter: str | Mapping[str, Any] | Callable[[Any], bool] = ...,
|
||||
sort: str | _Iterable[str] | Callable[[Any], Any] = ...,
|
||||
sort: str | Iterable[str] | Callable[[Any], SupportsRichComparison] = ...,
|
||||
) -> Self: ...
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
from _typeshed import StrPath
|
||||
from typing import IO, AnyStr
|
||||
from _typeshed import StrPath, SupportsRead
|
||||
from typing_extensions import Self
|
||||
|
||||
__tracebackhide__: bool
|
||||
|
||||
def contents_of(file: IO[AnyStr] | StrPath, encoding: str = "utf-8") -> str: ...
|
||||
def contents_of(file: SupportsRead[str] | StrPath, encoding: str = "utf-8") -> str: ...
|
||||
|
||||
class FileMixin:
|
||||
def exists(self) -> Self: ...
|
||||
|
||||
Reference in New Issue
Block a user