Pelokalan
Python ID
id en
Masuk
Proyek
whatsnew__3-14.po Berkas proyek · python-docs-id-3.14 · Bahasa Indonesia
Modul PO Hanya lihat
Teks sumber — English
Terjemahan — Bahasa Indonesia
Support underscore and comma as thousands separators in the fractional part for floating-point presentation types of the new-style string formatting (with :func:`format` or :ref:`f-strings`). (Contributed by Sergey B Kirpichev in :gh:`87790`.)
The :keyword:`except` and :keyword:`except* <except_star>` expressions now allow brackets to be omitted when there are multiple exception types and the ``as`` clause is not used. For example:
ctypes
ctypes
The layout of :ref:`bit fields <ctypes-bit-fields-in-structures-unions>` in :class:`~ctypes.Structure` and :class:`~ctypes.Union` objects is now a closer match to platform defaults (GCC/Clang or MSVC). In particular, fields no longer overlap. (Contributed by Matthias Görgens in :gh:`97702`.)
The class of :class:`~ctypes.Structure`/:class:`~ctypes.Union` field descriptors is now available as :class:`~ctypes.CField`, and has new attributes to aid debugging and introspection. (Contributed by Petr Viktorin in :gh:`128715`.)
On Windows, the :exc:`~ctypes.COMError` exception is now public. (Contributed by Jun Komoda in :gh:`126686`.)
On Windows, the :func:`~ctypes.CopyComPointer` function is now public. (Contributed by Jun Komoda in :gh:`127275`.)
Add :func:`~ctypes.memoryview_at`, a function to create a :class:`memoryview` object that refers to the supplied pointer and length. This works like :func:`ctypes.string_at` except it avoids a buffer copy, and is typically useful when implementing pure Python callback functions that are passed dynamically-sized buffers. (Contributed by Rian Hunter in :gh:`112018`.)
Complex types, :class:`~ctypes.c_float_complex`, :class:`~ctypes.c_double_complex`, and :class:`~ctypes.c_longdouble_complex`, are now available if both the compiler and the ``libffi`` library support complex C types. (Contributed by Sergey B Kirpichev in :gh:`61103`.)
Add :func:`ctypes.util.dllist` for listing the shared libraries loaded by the current process. (Contributed by Brian Ward in :gh:`119349`.)
Move :func:`ctypes.POINTER` types cache from a global internal cache (``_pointer_type_cache``) to the :attr:`_CData.__pointer_type__ <ctypes._CData.__pointer_type__>` attribute of the corresponding :mod:`!ctypes` types. This will stop the cache from growing without limits in some situations. (Contributed by Sergey Miryanov in :gh:`100926`.)
The :class:`~ctypes.py_object` type now supports subscription, making it a :term:`generic type`. (Contributed by Brian Schubert in :gh:`132168`.)
:mod:`!ctypes` now supports :term:`free-threading builds <free threading>`. (Contributed by Kumar Aditya and Peter Bierma in :gh:`127945`.)
mimetypes
mimetypes
Add a public :ref:`command-line <mimetypes-cli>` for the module, invoked via :program:`python -m mimetypes`. (Contributed by Oleg Iarygin and Hugo van Kemenade in :gh:`93096`.)
Add several new MIME types based on RFCs and common usage:
Microsoft and :rfc:`8081` MIME types for fonts
:rfc:`9559` MIME types for Matroska audiovisual data container structures
`ECMA-376 <https://ecma-international.org/publications-and-standards/standards/ecma-376/>`__: Add ``.docx``, ``.pptx`` and ``.xlsx`` types
`OASIS <https://docs.oasis-open.org/office/v1.2/cs01/OpenDocument-v1.2-cs01-part1.html#Appendix_C>`__: Add OpenDocument ``.odg``, ``.odp``, ``.ods`` and ``.odt`` types
The :ref:`multiprocessing proxy objects <multiprocessing-proxy_objects>` for *list* and *dict* types gain previously overlooked missing methods:
Add the :attr:`~pathlib.Path.info` attribute, which stores an object implementing the new :class:`pathlib.types.PathInfo` protocol. The object supports querying the file type and internally caching :func:`~os.stat` results. Path objects generated by :meth:`~pathlib.Path.iterdir` are initialized with file type information gleaned from scanning the parent directory. (Contributed by Barney Gale in :gh:`125413`.)
Support the :c:expr:`float complex` and :c:expr:`double complex` C types in the :mod:`struct` module (formatting characters ``'F'`` and ``'D'`` respectively). (Contributed by Sergey B Kirpichev in :gh:`121249`.)
types
types
:class:`types.UnionType` is now an alias for :class:`typing.Union`. See :ref:`below <whatsnew314-typing-union>` for more details. (Contributed by Jelle Zijlstra in :gh:`105499`.)
The :class:`types.UnionType` and :class:`typing.Union` types are now aliases for each other, meaning that both old-style unions (created with ``Union[int, str]``) and new-style unions (``int | str``) now create instances of the same runtime type. This unifies the behavior between the two syntaxes, but leads to some differences in behavior that may affect users who introspect types at runtime:
Unions created using the old syntax are no longer cached. Previously, running ``Union[int, str]`` multiple times would return the same object (``Union[int, str] is Union[int, str]`` would be ``True``), but now it will return two different objects. Use ``==`` to compare unions for equality, not ``is``. New-style unions have never been cached this way. This change could increase memory usage for some programs that use a large number of unions created by subscripting ``typing.Union``. However, several factors offset this cost: unions used in annotations are no longer evaluated by default in Python 3.14 because of :pep:`649`; an instance of :class:`types.UnionType` is itself much smaller than the object returned by ``Union[]`` was on prior Python versions; and removing the cache also saves some space. It is therefore unlikely that this change will cause a significant increase in memory usage for most users.
The import time for several standard library modules has been improved, including :mod:`annotationlib`, :mod:`ast`, :mod:`asyncio`, :mod:`base64`, :mod:`cmd`, :mod:`csv`, :mod:`gettext`, :mod:`importlib.util`, :mod:`locale`, :mod:`mimetypes`, :mod:`optparse`, :mod:`pickle`, :mod:`pprint`, :mod:`pstats`, :mod:`shlex`, :mod:`socket`, :mod:`string`, :mod:`subprocess`, :mod:`threading`, :mod:`tomllib`, :mod:`types`, and :mod:`zipfile`.
:mod:`ctypes`:
:mod:`ctypes`:
Calling :func:`ctypes.POINTER` on a string is now deprecated. Use :ref:`incomplete types <ctypes-incomplete-types>` for self-referential structures. Also, the internal ``ctypes._pointer_type_cache`` is deprecated. See :func:`ctypes.POINTER` for updated implementation details. (Contributed by Sergey Myrianov in :gh:`100926`.)
:mod:`mimetypes`: Valid extensions are either empty or must start with '.' for :meth:`mimetypes.MimeTypes.add_type`. Undotted extensions are deprecated and will raise a :exc:`ValueError` in Python 3.16. (Contributed by Hugo van Kemenade in :gh:`75223`.)
The undocumented :func:`!ctypes.SetPointerType` function has been deprecated since Python 3.13.
:mod:`types`:
:class:`types.CodeType`: Accessing :attr:`!codeobject.co_lnotab` was deprecated in :pep:`626` since 3.10 and was planned to be removed in 3.12, but it only got a proper :exc:`DeprecationWarning` in 3.12. May be removed in 3.15. (Contributed by Nikita Sobolev in :gh:`101866`.)
Bitwise inversion on boolean types, ``~True`` or ``~False`` has been deprecated since Python 3.12, as it produces surprising and unintuitive results (``-2`` and ``-1``). Use ``not x`` instead for the logical negation of a Boolean. In the rare case that you need the bitwise inversion of the underlying integer, convert to ``int`` explicitly (``~int(x)``).
:mod:`mimetypes`:
:mod:`mimetypes`:
Valid extensions start with a '.' or are empty for :meth:`mimetypes.MimeTypes.add_type`. Undotted extensions are deprecated and will raise a :exc:`ValueError` in Python 3.16. (Contributed by Hugo van Kemenade in :gh:`75223`.)
Use ``isinstance(obj, collections.abc.Buffer)`` to test if ``obj`` implements the :ref:`buffer protocol <bufferobjects>` at runtime. For use in type annotations, either use :class:`~collections.abc.Buffer` or a union that explicitly specifies the types your code supports (e.g., ``bytes | bytearray | memoryview``).
:class:`!ByteString` was originally intended to be an abstract class that would serve as a supertype of both :class:`bytes` and :class:`bytearray`. However, since the ABC never had any methods, knowing that an object was an instance of :class:`!ByteString` never actually told you anything useful about the object. Other common buffer types such as :class:`memoryview` were also never understood as subtypes of :class:`!ByteString` (either at runtime or by static type checkers).
Implicitly switching to the MSVC-compatible struct layout by setting :attr:`~ctypes.Structure._pack_` but not :attr:`~ctypes.Structure._layout_` on non-Windows platforms.
:mod:`ctypes`
:mod:`!ctypes.macholib`
Creating :c:data:`immutable types <Py_TPFLAGS_IMMUTABLETYPE>` with mutable bases was deprecated in Python 3.12, and now raises a :exc:`TypeError`. (Contributed by Nikita Sobolev in :gh:`119775`.)
:pep:`776`: Emscripten is now an officially supported platform at :pep:`tier 3 <11#tier-3>`. As a part of this effort, more than 25 bugs in `Emscripten libc`__ were fixed. Emscripten now includes support for :mod:`ctypes`, :mod:`termios`, and :mod:`fcntl`, as well as experimental support for the new :ref:`default interactive shell <tut-interactive>`. (Contributed by R. Hood Chatham in :gh:`127146`, :gh:`127683`, and :gh:`136931`.)
:class:`types.UnionType` is now an alias for :class:`typing.Union`, causing changes in some behaviors. See :ref:`above <whatsnew314-typing-union>` for more details. (Contributed by Jelle Zijlstra in :gh:`105499`.)
As part of making the :mod:`mimetypes` CLI public, it now exits with ``1`` on failure instead of ``0`` and ``2`` on incorrect command-line parameters instead of ``1``. Error messages are now printed to stderr.