Skip to content
Myr

Parameterize SupportsItems to handle Mapping key invariance (#7426)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Nate Prewitt · committed by GitHub · parent b684dcb · Browse files · 2 files+9 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+9 added−7 removed

  • other:+9 added−7 removed

2 files+9 added−7 removed

modified:src/requests/_types.py+6 added-4 removed
18 unmodified lines
19 runtime_checkable,20)2122_T_co = TypeVar("_T_co", covariant=True)23_KT_co = TypeVar("_KT_co", covariant=True)24_VT_co = TypeVar("_VT_co", covariant=True)252627@runtime_checkable28class SupportsRead(Protocol[_T_co]):29 def read(self, length: int = ..., /) -> _T_co: ...303132@runtime_checkable31class SupportsItems(Protocol):32 def items(self) -> Iterable[tuple[Any, Any]]: ...33class SupportsItems(Protocol[_KT_co, _VT_co]):34 def items(self) -> Iterable[tuple[_KT_co, _VT_co]]: ...353637# These are needed at runtime for default_hooks() return type38HookType: TypeAlias = Callable[["Response"], Any]
41 unmodified lines
80 _ParamsMappingValueType: TypeAlias = (81 str | bytes | int | float | Iterable[str | bytes | int | float] | None82 )83 ParamsType: TypeAlias = (82 Mapping[_ParamsMappingKeyType, _ParamsMappingValueType]84 SupportsItems[_ParamsMappingKeyType, _ParamsMappingValueType]85 | tuple[tuple[_ParamsMappingKeyType, _ParamsMappingValueType], ...]86 | Iterable[tuple[_ParamsMappingKeyType, _ParamsMappingValueType]]87 | str88 | bytes89 | None90 )9190 KVDataType: TypeAlias = Iterable[tuple[Any, Any]] | Mapping[Any, Any]92 KVDataType: TypeAlias = Iterable[tuple[Any, Any]] | SupportsItems[Any, Any]9394 RawDataType: TypeAlias = KVDataType | str | bytes95 StreamDataType: TypeAlias = SupportsRead[str | bytes]96 EncodableDataType: TypeAlias = RawDataType | StreamDataType
82 unmodified lines
modified:src/requests/utils.py+3 added-3 removed
145 unmodified lines
146 return proxy_bypass_registry(host)147148149def dict_to_sequence(150 d: _t.SupportsItems | Iterable[tuple[Any, Any]],150 d: _t.SupportsItems[Any, Any] | Iterable[tuple[Any, Any]],151) -> Iterable[tuple[Any, Any]]:152 """Returns an internal sequence dictionary update."""153154 if isinstance(d, _SupportsItems):
215 unmodified lines
370@overload371def to_key_val_list(value: None) -> None: ...372@overload373def to_key_val_list(374 value: Mapping[_KT, _VT] | Iterable[tuple[_KT, _VT]],374 value: _t.SupportsItems[_KT, _VT] | Iterable[tuple[_KT, _VT]],375) -> list[tuple[_KT, _VT]]: ...376def to_key_val_list(377 value: Mapping[_KT, _VT] | Iterable[tuple[_KT, _VT]] | None,377 value: _t.SupportsItems[_KT, _VT] | Iterable[tuple[_KT, _VT]] | None,378) -> list[tuple[_KT, _VT]] | None:379 """Take an object and test to see if it can be represented as a380 dictionary. If it can be, return a list of tuples, e.g.,381
772 unmodified lines