Teks sumber — English
Terjemahan — Bahasa Indonesia
:pep:`594`: :ref:`Many legacy standard library modules have been deprecated <whatsnew311-pep594>` and will be removed in Python 3.13
On Windows, :func:`os.urandom` now uses ``BCryptGenRandom()``, instead of ``CryptGenRandom()`` which is deprecated. (Contributed by Donghee Na in :issue:`44611`.)
Deprecated
Usang
This section lists Python APIs that have been deprecated in Python 3.11.
Deprecated C APIs are :ref:`listed separately <whatsnew311-c-api-deprecated>`.
Chaining :class:`classmethod` descriptors (introduced in :issue:`19072`) is now deprecated. It can no longer be used to wrap other descriptors such as :class:`property`. The core design of this feature was flawed and caused a number of downstream problems. To "pass-through" a :class:`classmethod`, consider using the :attr:`!__wrapped__` attribute that was added in Python 3.10. (Contributed by Raymond Hettinger in :gh:`89519`.)
The delegation of :func:`int` to :meth:`~object.__trunc__` is now deprecated. Calling ``int(a)`` when ``type(a)`` implements :meth:`!__trunc__` but not :meth:`~object.__int__` or :meth:`~object.__index__` now raises a :exc:`DeprecationWarning`. (Contributed by Zackery Spytz in :issue:`44977`.)
The :mod:`!asynchat`, :mod:`!asyncore` and :mod:`!smtpd` modules have been deprecated since at least Python 3.6. Their documentation and deprecation warnings have now been updated to note they will be removed in Python 3.12. (Contributed by Hugo van Kemenade in :issue:`47022`.)
The :mod:`!lib2to3` package and ``2to3`` tool are now deprecated and may not be able to parse Python 3.10 or newer. See :pep:`617`, introducing the new PEG parser, for details. (Contributed by Victor Stinner in :issue:`40360`.)
Undocumented modules :mod:`!sre_compile`, :mod:`!sre_constants` and :mod:`!sre_parse` are now deprecated. (Contributed by Serhiy Storchaka in :issue:`47152`.)
The following have been deprecated in :mod:`configparser` since Python 3.2. Their deprecation warnings have now been updated to note they will be removed in Python 3.12:
:class:`!configparser.LegacyInterpolation` has been deprecated in the docstring since Python 3.2, and is not listed in the :mod:`configparser` documentation. It now emits a :exc:`DeprecationWarning` and will be removed in Python 3.13. Use :class:`configparser.BasicInterpolation` or :class:`configparser.ExtendedInterpolation` instead. (Contributed by Hugo van Kemenade in :issue:`46607`.)
The older set of :mod:`importlib.resources` functions were deprecated in favor of the replacements added in Python 3.9 and will be removed in a future Python version, due to not supporting resources located within package subdirectories:
The :func:`locale.getdefaultlocale` function is deprecated and will be removed in Python 3.15. Use :func:`locale.setlocale`, :func:`locale.getpreferredencoding(False) <locale.getpreferredencoding>` and :func:`locale.getlocale` functions instead. (Contributed by Victor Stinner in :gh:`90817`.)
The :func:`!locale.resetlocale` function is deprecated and will be removed in Python 3.13. Use ``locale.setlocale(locale.LC_ALL, "")`` instead. (Contributed by Victor Stinner in :gh:`90817`.)
In the :mod:`re` module, the :func:`!re.template` function and the corresponding :const:`!re.TEMPLATE` and :const:`!re.T` flags are deprecated, as they were undocumented and lacked an obvious purpose. They will be removed in Python 3.13. (Contributed by Serhiy Storchaka and Miro Hrončok in :gh:`92728`.)
:func:`!turtle.settiltangle` has been deprecated since Python 3.1; it now emits a deprecation warning and will be removed in Python 3.13. Use :func:`turtle.tiltangle` instead (it was earlier incorrectly marked as deprecated, and its docstring is now corrected). (Contributed by Hugo van Kemenade in :issue:`45837`.)
:class:`typing.Text`, which exists solely to provide compatibility support between Python 2 and Python 3 code, is now deprecated. Its removal is currently unplanned, but users are encouraged to use :class:`str` instead wherever possible. (Contributed by Alex Waygood in :gh:`92332`.)
The keyword argument syntax for constructing :data:`typing.TypedDict` types is now deprecated. Support will be removed in Python 3.13. (Contributed by Jingchen Ye in :gh:`90224`.)
:class:`!webbrowser.MacOSX` is deprecated and will be removed in Python 3.13. It is untested, undocumented, and not used by :mod:`webbrowser` itself. (Contributed by Donghee Na in :issue:`42255`.)
The behavior of returning a value from a :class:`~unittest.TestCase` and :class:`~unittest.IsolatedAsyncioTestCase` test methods (other than the default ``None`` value) is now deprecated.
Deprecated the following not-formally-documented :mod:`unittest` functions, scheduled for removal in Python 3.13:
:meth:`!unittest.TestProgram.usageExit` is marked deprecated, to be removed in 3.13. (Contributed by Carlos Damázio in :gh:`67048`.)
The following Python APIs have been deprecated in earlier Python releases, and will be removed in Python 3.12.
The :ref:`entire distutils package <distutils-deprecated>`
The following deprecated aliases in :mod:`unittest`:
Deprecated alias
Deprecated in
Removed the :func:`!@asyncio.coroutine` :term:`decorator` enabling legacy generator-based coroutines to be compatible with :keyword:`async` / :keyword:`await` code. The function has been deprecated since Python 3.8 and the removal was initially scheduled for Python 3.10. Use :keyword:`async def` instead. (Contributed by Illia Volochii in :issue:`43216`.)
Removed the :mod:`!binhex` module, deprecated in Python 3.9. Also removed the related, similarly-deprecated :mod:`binascii` functions:
Removed the :mod:`!distutils` ``bdist_msi`` command deprecated in Python 3.9. Use ``bdist_wheel`` (wheel packages) instead. (Contributed by Hugo van Kemenade in :issue:`45124`.)
Removed the :meth:`~object.__getitem__` methods of :class:`xml.dom.pulldom.DOMEventStream`, :class:`wsgiref.util.FileWrapper` and :class:`fileinput.FileInput`, deprecated since Python 3.9. (Contributed by Hugo van Kemenade in :issue:`45132`.)
Removed the deprecated :mod:`gettext` functions :func:`!lgettext`, :func:`!ldgettext`, :func:`!lngettext` and :func:`!ldngettext`. Also removed the :func:`!bind_textdomain_codeset` function, the :meth:`!NullTranslations.output_charset` and :meth:`!NullTranslations.set_output_charset` methods, and the *codeset* parameter of :func:`!translation` and :func:`!install`, since they are only used for the :func:`!l*gettext` functions. (Contributed by Donghee Na and Serhiy Storchaka in :issue:`44235`.)
The :func:`!getargspec` function, deprecated since Python 3.0; use :func:`inspect.signature` or :func:`inspect.getfullargspec` instead.
The :func:`!formatargspec` function, deprecated since Python 3.5; use the :func:`inspect.signature` function or the :class:`inspect.Signature` object directly.
The undocumented :meth:`!Signature.from_builtin` and :meth:`!Signature.from_function` methods, deprecated since Python 3.5; use the :meth:`Signature.from_callable() <inspect.Signature.from_callable>` method instead.
Removed the deprecated :meth:`!split` method of :class:`!_tkinter.TkappType`. (Contributed by Erlend E. Aasland in :issue:`38371`.)
:func:`open`, :func:`io.open`, :func:`codecs.open` and :class:`fileinput.FileInput` no longer accept ``'U'`` ("universal newline") in the file mode. In Python 3, "universal newline" mode is used by default whenever a file is opened in text mode, and the ``'U'`` flag has been deprecated since Python 3.3. The :ref:`newline parameter <open-newline-parameter>` to these functions controls how universal newlines work. (Contributed by Victor Stinner in :issue:`37330`.)
In :mod:`re` :ref:`re-syntax`, global inline flags (e.g. ``(?i)``) can now only be used at the start of regular expressions. Using them elsewhere has been deprecated since Python 3.6. (Contributed by Serhiy Storchaka in :issue:`47066`.)
The old trashcan macros (``Py_TRASHCAN_SAFE_BEGIN``/``Py_TRASHCAN_SAFE_END``) are now deprecated. They should be replaced by the new macros ``Py_TRASHCAN_BEGIN`` and ``Py_TRASHCAN_END``.
The following C APIs have been deprecated in earlier Python releases, and will be removed in Python 3.12.
Remove ``Py_UNICODE_COPY()`` and ``Py_UNICODE_FILL()`` macros, deprecated since Python 3.3. Use ``PyUnicode_CopyCharacters()`` or ``memcpy()`` (``wchar_t*`` string), and ``PyUnicode_Fill()`` functions instead. (Contributed by Victor Stinner in :issue:`41123`.)
Remove the :c:type:`Py_UNICODE` encoder APIs, as they have been deprecated since Python 3.3, are little used and are inefficient relative to the recommended alternatives.