mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-10 05:51:52 +08:00
Loosen some types to avoid pain in real-life situations (#4870)
In this diff: * Loosen `set.__[i]sub__()` to allow typical use cases (that work at runtime). Namely, allow removing `unicode` from a set of `str`, and allow removing optional values from non-optional sets. * Avoid using union return types in `cryptography` deserialization functions. * Tune `SupportsItems` so that `dict` implements it on Python 2. Co-authored-by: Ivan Levkivskyi <ilevkivskyi@dropbox.com>
This commit is contained in:
@@ -34,7 +34,11 @@ SupportsLessThanT = TypeVar("SupportsLessThanT", bound=SupportsLessThan) # noqa
|
||||
# Mapping-like protocols
|
||||
|
||||
class SupportsItems(Protocol[_KT_co, _VT_co]):
|
||||
def items(self) -> AbstractSet[Tuple[_KT_co, _VT_co]]: ...
|
||||
if sys.version_info >= (3,):
|
||||
def items(self) -> AbstractSet[Tuple[_KT_co, _VT_co]]: ...
|
||||
else:
|
||||
# We want dictionaries to support this on Python 2.
|
||||
def items(self) -> Iterable[Tuple[_KT_co, _VT_co]]: ...
|
||||
|
||||
class SupportsKeysAndGetItem(Protocol[_KT, _VT_co]):
|
||||
def keys(self) -> Iterable[_KT]: ...
|
||||
|
||||
Reference in New Issue
Block a user