Skip to content

gh-105578: Deprecate AnyStr in the docs #107116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 31, 2023
14 changes: 14 additions & 0 deletions Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,16 @@ using ``[]``.
def greet_proper(cond: bool) -> str | bytes:
return "hi there!" if cond else b"greetings!"

.. deprecated-removed:: 3.13 3.18
Deprecated in favor of the new :ref:`type parameter syntax <type-params>`.
Use ``class A[T: (str, bytes)]: ...`` instead of importing ``AnyStr``. See
:pep:`695` for more details.

In Python 3.16, ``AnyStr`` will be removed from ``typing.__all__``, and
deprecation warnings will be emitted at runtime when it is accessed or
imported from ``typing``. ``AnyStr`` will be removed from ``typing``
in Python 3.18.

.. data:: LiteralString

Special type that includes only literal strings.
Expand Down Expand Up @@ -3700,3 +3710,7 @@ convenience. This is subject to change, and not all deprecations are listed.
- 3.13
- 3.15
- :gh:`106309`
* - :data:`typing.AnyStr`
- 3.13
- 3.18
- :gh:`105578`
6 changes: 6 additions & 0 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ Deprecated
has yet to be supported by any major type checkers.
(Contributed by Alex Waygood in :gh:`106309`.)

* :data:`typing.AnyStr` is deprecated. In Python 3.16, it will be removed from
``typing.__all__``, and a :exc:`DeprecationWarning` will be emitted when it
is imported or accessed. It will be removed entirely in Python 3.18. Use
the new :ref:`type parameter syntax <type-params>` instead.
(Contributed by Michael The in :gh:`107116`.)

* :mod:`wave`: Deprecate the ``getmark()``, ``setmark()`` and ``getmarkers()``
methods of the :class:`wave.Wave_read` and :class:`wave.Wave_write` classes.
They will be removed in Python 3.15.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Deprecate :class:`typing.AnyStr` in favor of the new Type Parameter syntax.
See PEP 695.