mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-06 04:04:25 +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:
@@ -737,8 +737,14 @@ class set(MutableSet[_T], Generic[_T]):
|
||||
def __iand__(self, s: AbstractSet[object]) -> Set[_T]: ...
|
||||
def __or__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ...
|
||||
def __ior__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ...
|
||||
def __sub__(self, s: AbstractSet[_T]) -> Set[_T]: ...
|
||||
def __isub__(self, s: AbstractSet[_T]) -> Set[_T]: ...
|
||||
@overload
|
||||
def __sub__(self: Set[str], s: AbstractSet[Optional[Text]]) -> Set[_T]: ...
|
||||
@overload
|
||||
def __sub__(self, s: AbstractSet[Optional[_T]]) -> Set[_T]: ...
|
||||
@overload # type: ignore
|
||||
def __isub__(self: Set[str], s: AbstractSet[Optional[Text]]) -> Set[_T]: ...
|
||||
@overload
|
||||
def __isub__(self, s: AbstractSet[Optional[_T]]) -> Set[_T]: ...
|
||||
def __xor__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ...
|
||||
def __ixor__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ...
|
||||
def __le__(self, s: AbstractSet[object]) -> bool: ...
|
||||
|
||||
@@ -737,8 +737,14 @@ class set(MutableSet[_T], Generic[_T]):
|
||||
def __iand__(self, s: AbstractSet[object]) -> Set[_T]: ...
|
||||
def __or__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ...
|
||||
def __ior__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ...
|
||||
def __sub__(self, s: AbstractSet[_T]) -> Set[_T]: ...
|
||||
def __isub__(self, s: AbstractSet[_T]) -> Set[_T]: ...
|
||||
@overload
|
||||
def __sub__(self: Set[str], s: AbstractSet[Optional[Text]]) -> Set[_T]: ...
|
||||
@overload
|
||||
def __sub__(self, s: AbstractSet[Optional[_T]]) -> Set[_T]: ...
|
||||
@overload # type: ignore
|
||||
def __isub__(self: Set[str], s: AbstractSet[Optional[Text]]) -> Set[_T]: ...
|
||||
@overload
|
||||
def __isub__(self, s: AbstractSet[Optional[_T]]) -> Set[_T]: ...
|
||||
def __xor__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ...
|
||||
def __ixor__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ...
|
||||
def __le__(self, s: AbstractSet[object]) -> bool: ...
|
||||
|
||||
@@ -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]: ...
|
||||
|
||||
@@ -807,8 +807,8 @@ class set(MutableSet[_T], Generic[_T]):
|
||||
def __iand__(self, s: AbstractSet[object]) -> Set[_T]: ...
|
||||
def __or__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ...
|
||||
def __ior__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ...
|
||||
def __sub__(self, s: AbstractSet[_T]) -> Set[_T]: ...
|
||||
def __isub__(self, s: AbstractSet[_T]) -> Set[_T]: ...
|
||||
def __sub__(self, s: AbstractSet[Optional[_T]]) -> Set[_T]: ...
|
||||
def __isub__(self, s: AbstractSet[Optional[_T]]) -> Set[_T]: ...
|
||||
def __xor__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ...
|
||||
def __ixor__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ...
|
||||
def __le__(self, s: AbstractSet[object]) -> bool: ...
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from abc import ABCMeta
|
||||
from enum import Enum
|
||||
from typing import Optional, Union
|
||||
from typing import Any, Optional, Union
|
||||
|
||||
from cryptography.hazmat.backends.interfaces import (
|
||||
DERSerializationBackend,
|
||||
@@ -17,19 +17,19 @@ from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey, RSAPubl
|
||||
|
||||
def load_pem_private_key(
|
||||
data: bytes, password: Optional[bytes], backend: Optional[PEMSerializationBackend] = ...
|
||||
) -> Union[RSAPrivateKey, DSAPrivateKey, DHPrivateKey, EllipticCurvePrivateKey]: ...
|
||||
) -> Any: ... # actually Union[RSAPrivateKey, DSAPrivateKey, DHPrivateKey, EllipticCurvePrivateKey]
|
||||
def load_pem_public_key(
|
||||
data: bytes, backend: Optional[PEMSerializationBackend] = ...
|
||||
) -> Union[RSAPublicKey, DSAPublicKey, DHPublicKey, EllipticCurvePublicKey]: ...
|
||||
) -> Any: ... # actually Union[RSAPublicKey, DSAPublicKey, DHPublicKey, EllipticCurvePublicKey]
|
||||
def load_der_private_key(
|
||||
data: bytes, password: Optional[bytes], backend: Optional[DERSerializationBackend] = ...
|
||||
) -> Union[RSAPrivateKey, DSAPrivateKey, DHPrivateKey, EllipticCurvePrivateKey]: ...
|
||||
) -> Any: ... # actually Union[RSAPrivateKey, DSAPrivateKey, DHPrivateKey, EllipticCurvePrivateKey]
|
||||
def load_der_public_key(
|
||||
data: bytes, backend: Optional[DERSerializationBackend] = ...
|
||||
) -> Union[RSAPublicKey, DSAPublicKey, DHPublicKey, EllipticCurvePublicKey]: ...
|
||||
) -> Any: ... # actually Union[RSAPublicKey, DSAPublicKey, DHPublicKey, EllipticCurvePublicKey]
|
||||
def load_ssh_public_key(
|
||||
data: bytes, backend: Union[RSABackend, DSABackend, EllipticCurveBackend, None]
|
||||
) -> Union[RSAPublicKey, DSAPublicKey, DHPublicKey, EllipticCurvePublicKey, Ed25519PublicKey]: ...
|
||||
) -> Any: ... # actually Union[RSAPublicKey, DSAPublicKey, DHPublicKey, EllipticCurvePublicKey, Ed25519PublicKey]
|
||||
|
||||
class Encoding(Enum):
|
||||
PEM: str
|
||||
|
||||
Reference in New Issue
Block a user