Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/requests/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
)

_T_co = TypeVar("_T_co", covariant=True)
_KT_co = TypeVar("_KT_co", covariant=True)
_VT_co = TypeVar("_VT_co", covariant=True)


@runtime_checkable
Expand All @@ -28,8 +30,8 @@ def read(self, length: int = ..., /) -> _T_co: ...


@runtime_checkable
class SupportsItems(Protocol):
def items(self) -> Iterable[tuple[Any, Any]]: ...
class SupportsItems(Protocol[_KT_co, _VT_co]):
def items(self) -> Iterable[tuple[_KT_co, _VT_co]]: ...


# These are needed at runtime for default_hooks() return type
Expand Down Expand Up @@ -79,15 +81,15 @@ class _ValidatedRequest(PreparedRequest):
str | bytes | int | float | Iterable[str | bytes | int | float] | None
)
ParamsType: TypeAlias = (
Mapping[_ParamsMappingKeyType, _ParamsMappingValueType]
SupportsItems[_ParamsMappingKeyType, _ParamsMappingValueType]
| tuple[tuple[_ParamsMappingKeyType, _ParamsMappingValueType], ...]
| Iterable[tuple[_ParamsMappingKeyType, _ParamsMappingValueType]]
| str
| bytes
| None
)

KVDataType: TypeAlias = Iterable[tuple[Any, Any]] | Mapping[Any, Any]
KVDataType: TypeAlias = Iterable[tuple[Any, Any]] | SupportsItems[Any, Any]

RawDataType: TypeAlias = KVDataType | str | bytes
StreamDataType: TypeAlias = SupportsRead[str | bytes]
Expand Down
6 changes: 3 additions & 3 deletions src/requests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def proxy_bypass(host: str) -> bool: # noqa


def dict_to_sequence(
d: _t.SupportsItems | Iterable[tuple[Any, Any]],
d: _t.SupportsItems[Any, Any] | Iterable[tuple[Any, Any]],
) -> Iterable[tuple[Any, Any]]:
"""Returns an internal sequence dictionary update."""

Expand Down Expand Up @@ -371,10 +371,10 @@ def from_key_val_list(
def to_key_val_list(value: None) -> None: ...
@overload
def to_key_val_list(
value: Mapping[_KT, _VT] | Iterable[tuple[_KT, _VT]],
value: _t.SupportsItems[_KT, _VT] | Iterable[tuple[_KT, _VT]],
) -> list[tuple[_KT, _VT]]: ...
def to_key_val_list(
value: Mapping[_KT, _VT] | Iterable[tuple[_KT, _VT]] | None,
value: _t.SupportsItems[_KT, _VT] | Iterable[tuple[_KT, _VT]] | None,
) -> list[tuple[_KT, _VT]] | None:
"""Take an object and test to see if it can be represented as a
dictionary. If it can be, return a list of tuples, e.g.,
Expand Down
Loading