Pelokalan
Python ID
id en
Sign in
Project
whatsnew__3-13.po Project files · python-docs-id-3.14 · Bahasa Indonesia
Module PO View only
Source text — English
Translation — Bahasa Indonesia
The :mod:`copy` module now has a :func:`copy.replace` function, with support for many builtin types and any class defining the :func:`~object.__replace__` method.
The constructors of node types in the :mod:`ast` module are now stricter in the arguments they accept, with more intuitive behavior when arguments are omitted.
These changes do not apply to user-defined subclasses of :class:`ast.AST` unless the class opts in to the new behavior by defining the :attr:`.AST._field_types` mapping.
The new :func:`~copy.replace` function and the :meth:`replace protocol <object.__replace__>` make creating modified copies of objects much simpler. This is especially useful when working with immutable objects. The following types support the :func:`~copy.replace` function and implement the replace protocol:
:class:`types.SimpleNamespace`
ctypes
ctypes
:class:`ctypes.Structure` objects have a new :attr:`~ctypes.Structure._align_` attribute which allows the alignment of the structure being packed to/from memory to be specified explicitly. (Contributed by Matt Sanderson in :gh:`112433`)
mimetypes
mimetypes
Add the :func:`~mimetypes.guess_file_type` function to guess a MIME type from a filesystem path. Using paths with :func:`~mimetypes.guess_type` is now :term:`soft deprecated`. (Contributed by Serhiy Storchaka in :gh:`66543`.)
types
types
:class:`~types.SimpleNamespace` can now take a single positional argument to initialise the namespace's arguments. This argument must either be a mapping or an iterable of key-value pairs. (Contributed by Serhiy Storchaka in :gh:`108191`.)
:pypi:`legacycrypt`: :mod:`ctypes` wrapper to the POSIX crypt library call and associated functionality.
:mod:`!mailcap`: Use the :mod:`mimetypes` module instead.
Remove the keyword-argument method of creating :class:`~typing.TypedDict` types, deprecated in Python 3.11. (Contributed by Tomas Roun in :gh:`104786`.)
Deprecate assignment to a function's :attr:`~function.__code__` attribute, where the new code object's type does not match the function's type. The different types are: plain function, generator, async generator, and coroutine. (Contributed by Irit Katriel in :gh:`81137`.)
:mod:`ctypes`:
:mod:`ctypes`:
:term:`Soft-deprecate <soft deprecated>` the :func:`~ctypes.ARRAY` function in favour of ``type * length`` multiplication. (Contributed by Victor Stinner in :gh:`105733`.)
:mod:`mimetypes`:
:mod:`mimetypes`:
:term:`Soft-deprecate <soft deprecated>` file path arguments to :func:`~mimetypes.guess_type`, use :func:`~mimetypes.guess_file_type` instead. (Contributed by Serhiy Storchaka in :gh:`66543`.)
Deprecate omitting the *fields* parameter when creating a :class:`~typing.NamedTuple` or :class:`typing.TypedDict` class, and deprecate passing ``None`` to the *fields* parameter of both types. Python 3.15 will require a valid sequence for the *fields* parameter. To create a NamedTuple class with zero fields, use ``class NT(NamedTuple): pass`` or ``NT = NamedTuple("NT", ())``. To create a TypedDict class with zero fields, use ``class TD(TypedDict): pass`` or ``TD = TypedDict("TD", {})``. (Contributed by Alex Waygood in :gh:`105566` and :gh:`105570`.)
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)``).
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`
Add the :c:func:`PyLong_AsNativeBytes`, :c:func:`PyLong_FromNativeBytes`, and :c:func:`PyLong_FromUnsignedNativeBytes` functions to simplify converting between native integer types and Python :class:`int` objects. (Contributed by Steve Dower in :gh:`111140`.)
In :c:func:`PyObject_Call`, positional arguments must be a :class:`tuple` and must not be ``NULL``, and keyword arguments must be a :class:`dict` or ``NULL``, whereas the removed functions checked argument types and accepted ``NULL`` positional and keyword arguments. To replace ``PyEval_CallObjectWithKeywords(func, NULL, kwargs)`` with :c:func:`PyObject_Call`, pass an empty tuple as positional arguments using :c:func:`PyTuple_New(0) <PyTuple_New>`.
Deprecate the old ``Py_UNICODE`` and ``PY_UNICODE_TYPE`` types and the :c:macro:`!Py_UNICODE_WIDE` define. Use the :c:type:`wchar_t` type directly instead. Since Python 3.3, ``Py_UNICODE`` and ``PY_UNICODE_TYPE`` are just aliases to :c:type:`!wchar_t`. (Contributed by Victor Stinner in :gh:`105156`.)
Creating :c:data:`immutable types <Py_TPFLAGS_IMMUTABLETYPE>` with mutable bases (:gh:`95388`).
The ``errno``, ``fcntl``, ``grp``, ``md5``, ``pwd``, ``resource``, ``termios``, ``winsound``, ``_ctypes_test``, ``_multiprocessing.posixshmem``, ``_scproxy``, ``_stat``, ``_statistics``, ``_testconsole``, ``_testimportmultiple`` and ``_uuid`` C extensions are now built with the :ref:`limited C API <limited-c-api>`. (Contributed by Victor Stinner in :gh:`85283`.)
On Windows, ``Python.h`` no longer includes the ``<stddef.h>`` standard header file. If needed, it should now be included explicitly. For example, it provides :c:func:`!offsetof` function, and ``size_t`` and ``ptrdiff_t`` types. Including ``<stddef.h>`` explicitly was already needed by all other platforms, the ``HAVE_STDDEF_H`` macro is only defined on Windows. (Contributed by Victor Stinner in :gh:`108765`.)