mirror of
https://github.com/python/cpython.git
synced 2025-10-07 07:31:46 +00:00
gh-91896: Improve visibility of ByteString
deprecation warnings (#104294)
This commit is contained in:
parent
a0a98ddb31
commit
f0f5bb3204
5 changed files with 85 additions and 12 deletions
|
@ -1599,6 +1599,22 @@ class _SpecialGenericAlias(_NotIterable, _BaseGenericAlias, _root=True):
|
|||
def __ror__(self, left):
|
||||
return Union[left, self]
|
||||
|
||||
|
||||
class _DeprecatedGenericAlias(_SpecialGenericAlias, _root=True):
|
||||
def __init__(
|
||||
self, origin, nparams, *, removal_version, inst=True, name=None
|
||||
):
|
||||
super().__init__(origin, nparams, inst=inst, name=name)
|
||||
self._removal_version = removal_version
|
||||
|
||||
def __instancecheck__(self, inst):
|
||||
import warnings
|
||||
warnings._deprecated(
|
||||
f"{self.__module__}.{self._name}", remove=self._removal_version
|
||||
)
|
||||
return super().__instancecheck__(inst)
|
||||
|
||||
|
||||
class _CallableGenericAlias(_NotIterable, _GenericAlias, _root=True):
|
||||
def __repr__(self):
|
||||
assert self._name == 'Callable'
|
||||
|
@ -2756,7 +2772,6 @@ Mapping = _alias(collections.abc.Mapping, 2)
|
|||
MutableMapping = _alias(collections.abc.MutableMapping, 2)
|
||||
Sequence = _alias(collections.abc.Sequence, 1)
|
||||
MutableSequence = _alias(collections.abc.MutableSequence, 1)
|
||||
ByteString = _alias(collections.abc.ByteString, 0) # Not generic
|
||||
# Tuple accepts variable number of parameters.
|
||||
Tuple = _TupleType(tuple, -1, inst=False, name='Tuple')
|
||||
Tuple.__doc__ = \
|
||||
|
@ -3556,3 +3571,18 @@ def override(method: F, /) -> F:
|
|||
# read-only property, TypeError if it's a builtin class.
|
||||
pass
|
||||
return method
|
||||
|
||||
|
||||
def __getattr__(attr):
|
||||
if attr == "ByteString":
|
||||
import warnings
|
||||
warnings._deprecated("typing.ByteString", remove=(3, 14))
|
||||
with warnings.catch_warnings(
|
||||
action="ignore", category=DeprecationWarning
|
||||
):
|
||||
# Not generic
|
||||
ByteString = globals()["ByteString"] = _DeprecatedGenericAlias(
|
||||
collections.abc.ByteString, 0, removal_version=(3, 14)
|
||||
)
|
||||
return ByteString
|
||||
raise AttributeError(f"module 'typing' has no attribute {attr!r}")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue