summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
diff options
context:
space:
mode:
authorAlex Waygood <Alex.Waygood@Gmail.com>2023-05-12 06:01:31 (GMT)
committerGitHub <noreply@github.com>2023-05-12 06:01:31 (GMT)
commitf0f5bb32043e1223d8c413e763cd93061d4f9fac (patch)
tree217a4dbfc9e85a7e2722b6791062f6a96bdadaab /Lib/typing.py
parenta0a98ddb31591357bead4694b21717cb4034924f (diff)
downloadcpython-f0f5bb32043e1223d8c413e763cd93061d4f9fac.zip
cpython-f0f5bb32043e1223d8c413e763cd93061d4f9fac.tar.gz
cpython-f0f5bb32043e1223d8c413e763cd93061d4f9fac.tar.bz2
gh-91896: Improve visibility of `ByteString` deprecation warnings (#104294)
Diffstat (limited to 'Lib/typing.py')
-rw-r--r--Lib/typing.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index 62c7dd3..bf7bd24 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -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}")