diff --git a/Doc/c-api/dict.rst b/Doc/c-api/dict.rst
index 7810d05b0ebc2e..8ee351918006e4 100644
--- a/Doc/c-api/dict.rst
+++ b/Doc/c-api/dict.rst
@@ -79,12 +79,9 @@ Dictionary Objects
.. c:function:: int PyDict_SetItemString(PyObject *p, const char *key, PyObject *val)
- .. index:: single: PyUnicode_FromString()
-
- Insert *val* into the dictionary *p* using *key* as a key. *key* should
- be a :c:expr:`const char*` UTF-8 encoded bytes string. The key object is created using
- ``PyUnicode_FromString(key)``. Return ``0`` on success or ``-1`` on
- failure. This function *does not* steal a reference to *val*.
+ This is the same as :c:func:`PyDict_SetItem`, but *key* is
+ specified as a :c:expr:`const char*` UTF-8 encoded bytes string,
+ rather than a :c:expr:`PyObject*`.
.. c:function:: int PyDict_DelItem(PyObject *p, PyObject *key)
@@ -97,10 +94,9 @@ Dictionary Objects
.. c:function:: int PyDict_DelItemString(PyObject *p, const char *key)
- Remove the entry in dictionary *p* which has a key specified by the UTF-8
- encoded bytes string *key*.
- If *key* is not in the dictionary, :exc:`KeyError` is raised.
- Return ``0`` on success or ``-1`` on failure.
+ This is the same as :c:func:`PyDict_DelItem`, but *key* is
+ specified as a :c:expr:`const char*` UTF-8 encoded bytes string,
+ rather than a :c:expr:`PyObject*`.
.. c:function:: int PyDict_GetItemRef(PyObject *p, PyObject *key, PyObject **result)
diff --git a/Doc/c-api/mapping.rst b/Doc/c-api/mapping.rst
index 82011d9d36a524..5b909ef8f5e2ce 100644
--- a/Doc/c-api/mapping.rst
+++ b/Doc/c-api/mapping.rst
@@ -28,9 +28,9 @@ See also :c:func:`PyObject_GetItem`, :c:func:`PyObject_SetItem` and
.. c:function:: PyObject* PyMapping_GetItemString(PyObject *o, const char *key)
- Return element of *o* corresponding to the string *key* or ``NULL`` on failure.
- This is the equivalent of the Python expression ``o[key]``.
- See also :c:func:`PyObject_GetItem`.
+ This is the same as :c:func:`PyObject_GetItem`, but *key* is
+ specified as a :c:expr:`const char*` UTF-8 encoded bytes string,
+ rather than a :c:expr:`PyObject*`.
.. c:function:: int PyMapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **result)
@@ -50,38 +50,30 @@ See also :c:func:`PyObject_GetItem`, :c:func:`PyObject_SetItem` and
.. c:function:: int PyMapping_GetOptionalItemString(PyObject *obj, const char *key, PyObject **result)
- Variant of :c:func:`PyMapping_GetItemString` which doesn't raise
- :exc:`KeyError` if the key is not found.
-
- If the key is found, return ``1`` and set *\*result* to a new
- :term:`strong reference` to the corresponding value.
- If the key is not found, return ``0`` and set *\*result* to ``NULL``;
- the :exc:`KeyError` is silenced.
- If an error other than :exc:`KeyError` is raised, return ``-1`` and
- set *\*result* to ``NULL``.
+ This is the same as :c:func:`PyMapping_GetOptionalItem`, but *key* is
+ specified as a :c:expr:`const char*` UTF-8 encoded bytes string,
+ rather than a :c:expr:`PyObject*`.
.. versionadded:: 3.13
.. c:function:: int PyMapping_SetItemString(PyObject *o, const char *key, PyObject *v)
- Map the string *key* to the value *v* in object *o*. Returns ``-1`` on
- failure. This is the equivalent of the Python statement ``o[key] = v``.
- See also :c:func:`PyObject_SetItem`. This function *does not* steal a
- reference to *v*.
+ This is the same as :c:func:`PyObject_SetItem`, but *key* is
+ specified as a :c:expr:`const char*` UTF-8 encoded bytes string,
+ rather than a :c:expr:`PyObject*`.
.. c:function:: int PyMapping_DelItem(PyObject *o, PyObject *key)
- Remove the mapping for the object *key* from the object *o*. Return ``-1``
- on failure. This is equivalent to the Python statement ``del o[key]``.
This is an alias of :c:func:`PyObject_DelItem`.
.. c:function:: int PyMapping_DelItemString(PyObject *o, const char *key)
- Remove the mapping for the string *key* from the object *o*. Return ``-1``
- on failure. This is equivalent to the Python statement ``del o[key]``.
+ This is the same as :c:func:`PyObject_DelItem`, but *key* is
+ specified as a :c:expr:`const char*` UTF-8 encoded bytes string,
+ rather than a :c:expr:`PyObject*`.
.. c:function:: int PyMapping_HasKey(PyObject *o, PyObject *key)
@@ -90,20 +82,27 @@ See also :c:func:`PyObject_GetItem`, :c:func:`PyObject_SetItem` and
This is equivalent to the Python expression ``key in o``.
This function always succeeds.
- Note that exceptions which occur while calling the :meth:`~object.__getitem__`
- method will get suppressed.
- To get error reporting use :c:func:`PyObject_GetItem()` instead.
+ .. note::
+
+ Exceptions which occur when this calls :meth:`~object.__getitem__`
+ method are silently ignored.
+ For proper error handling, use :c:func:`PyMapping_GetOptionalItem` or
+ :c:func:`PyObject_GetItem()` instead.
.. c:function:: int PyMapping_HasKeyString(PyObject *o, const char *key)
- Return ``1`` if the mapping object has the key *key* and ``0`` otherwise.
- This is equivalent to the Python expression ``key in o``.
- This function always succeeds.
+ This is the same as :c:func:`PyMapping_HasKey`, but *key* is
+ specified as a :c:expr:`const char*` UTF-8 encoded bytes string,
+ rather than a :c:expr:`PyObject*`.
+
+ .. note::
- Note that exceptions which occur while calling the :meth:`~object.__getitem__`
- method and creating a temporary string object will get suppressed.
- To get error reporting use :c:func:`PyMapping_GetItemString()` instead.
+ Exceptions that occur when this calls :meth:`~object.__getitem__`
+ method or while creating the temporary :class:`str`
+ object are silently ignored.
+ For proper error handling, use :c:func:`PyMapping_GetOptionalItemString` or
+ :c:func:`PyMapping_GetItemString` instead.
.. c:function:: PyObject* PyMapping_Keys(PyObject *o)
diff --git a/Doc/c-api/object.rst b/Doc/c-api/object.rst
index 6d9fc7f50604da..2572c087738fe3 100644
--- a/Doc/c-api/object.rst
+++ b/Doc/c-api/object.rst
@@ -43,15 +43,15 @@ Object Protocol
.. c:function:: int PyObject_HasAttrString(PyObject *o, const char *attr_name)
- Returns ``1`` if *o* has the attribute *attr_name*, and ``0`` otherwise. This
- is equivalent to the Python expression ``hasattr(o, attr_name)``. This function
- always succeeds.
+ This is the same as :c:func:`PyObject_HasAttr`, but *attr_name* is
+ specified as a :c:expr:`const char*` UTF-8 encoded bytes string,
+ rather than a :c:expr:`PyObject*`.
.. note::
Exceptions that occur when this calls :meth:`~object.__getattr__` and
- :meth:`~object.__getattribute__` methods or while creating the temporary :class:`str`
- object are silently ignored.
+ :meth:`~object.__getattribute__` methods or while creating the temporary
+ :class:`str` object are silently ignored.
For proper error handling, use :c:func:`PyObject_GetOptionalAttrString`
or :c:func:`PyObject_GetAttrString` instead.
@@ -68,9 +68,9 @@ Object Protocol
.. c:function:: PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name)
- Retrieve an attribute named *attr_name* from object *o*. Returns the attribute
- value on success, or ``NULL`` on failure. This is the equivalent of the Python
- expression ``o.attr_name``.
+ This is the same as :c:func:`PyObject_GetAttr`, but *attr_name* is
+ specified as a :c:expr:`const char*` UTF-8 encoded bytes string,
+ rather than a :c:expr:`PyObject*`.
If the missing attribute should not be treated as a failure, you can use
:c:func:`PyObject_GetOptionalAttrString` instead.
@@ -93,15 +93,9 @@ Object Protocol
.. c:function:: int PyObject_GetOptionalAttrString(PyObject *obj, const char *attr_name, PyObject **result);
- Variant of :c:func:`PyObject_GetAttrString` which doesn't raise
- :exc:`AttributeError` if the attribute is not found.
-
- If the attribute is found, return ``1`` and set *\*result* to a new
- :term:`strong reference` to the attribute.
- If the attribute is not found, return ``0`` and set *\*result* to ``NULL``;
- the :exc:`AttributeError` is silenced.
- If an error other than :exc:`AttributeError` is raised, return ``-1`` and
- set *\*result* to ``NULL``.
+ This is the same as :c:func:`PyObject_GetOptionalAttr`, but *attr_name* is
+ specified as a :c:expr:`const char*` UTF-8 encoded bytes string,
+ rather than a :c:expr:`PyObject*`.
.. versionadded:: 3.13
@@ -129,10 +123,9 @@ Object Protocol
.. c:function:: int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v)
- Set the value of the attribute named *attr_name*, for object *o*, to the value
- *v*. Raise an exception and return ``-1`` on failure;
- return ``0`` on success. This is the equivalent of the Python statement
- ``o.attr_name = v``.
+ This is the same as :c:func:`PyObject_SetAttr`, but *attr_name* is
+ specified as a :c:expr:`const char*` UTF-8 encoded bytes string,
+ rather than a :c:expr:`PyObject*`.
If *v* is ``NULL``, the attribute is deleted, but this feature is
deprecated in favour of using :c:func:`PyObject_DelAttrString`.
@@ -158,8 +151,9 @@ Object Protocol
.. c:function:: int PyObject_DelAttrString(PyObject *o, const char *attr_name)
- Delete attribute named *attr_name*, for object *o*. Returns ``-1`` on failure.
- This is the equivalent of the Python statement ``del o.attr_name``.
+ This is the same as :c:func:`PyObject_DelAttr`, but *attr_name* is
+ specified as a :c:expr:`const char*` UTF-8 encoded bytes string,
+ rather than a :c:expr:`PyObject*`.
.. c:function:: PyObject* PyObject_GenericGetDict(PyObject *o, void *context)
diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst
index 400c369a9bb736..04cc75562937e0 100644
--- a/Doc/library/datetime.rst
+++ b/Doc/library/datetime.rst
@@ -37,6 +37,10 @@ on efficient attribute extraction for output formatting and manipulation.
Package `dateutil `_
Third-party library with expanded time zone and parsing support.
+ Package `DateType `_
+ Third-party library that introduces distinct static types to e.g. allow static type checkers
+ to differentiate between naive and aware datetimes.
+
.. _datetime-naive-aware:
Aware and Naive Objects
diff --git a/Doc/library/doctest.rst b/Doc/library/doctest.rst
index 92da6133f9bf09..54a8e79a0ef941 100644
--- a/Doc/library/doctest.rst
+++ b/Doc/library/doctest.rst
@@ -1409,6 +1409,27 @@ DocTestParser objects
identifying this string, and is only used for error messages.
+TestResults objects
+^^^^^^^^^^^^^^^^^^^
+
+
+.. class:: TestResults(failed, attempted)
+
+ .. attribute:: failed
+
+ Number of failed tests.
+
+ .. attribute:: attempted
+
+ Number of attempted tests.
+
+ .. attribute:: skipped
+
+ Number of skipped tests.
+
+ .. versionadded:: 3.13
+
+
.. _doctest-doctestrunner:
DocTestRunner objects
@@ -1427,7 +1448,7 @@ DocTestRunner objects
passing a subclass of :class:`OutputChecker` to the constructor.
The test runner's display output can be controlled in two ways. First, an output
- function can be passed to :meth:`TestRunner.run`; this function will be called
+ function can be passed to :meth:`run`; this function will be called
with strings that should be displayed. It defaults to ``sys.stdout.write``. If
capturing the output is not sufficient, then the display output can be also
customized by subclassing DocTestRunner, and overriding the methods
@@ -1448,6 +1469,10 @@ DocTestRunner objects
runner compares expected output to actual output, and how it displays failures.
For more information, see section :ref:`doctest-options`.
+ The test runner accumulates statistics. The aggregated number of attempted,
+ failed and skipped examples is also available via the :attr:`tries`,
+ :attr:`failures` and :attr:`skips` attributes. The :meth:`run` and
+ :meth:`summarize` methods return a :class:`TestResults` instance.
:class:`DocTestParser` defines the following methods:
@@ -1500,7 +1525,8 @@ DocTestRunner objects
.. method:: run(test, compileflags=None, out=None, clear_globs=True)
Run the examples in *test* (a :class:`DocTest` object), and display the
- results using the writer function *out*.
+ results using the writer function *out*. Return a :class:`TestResults`
+ instance.
The examples are run in the namespace ``test.globs``. If *clear_globs* is
true (the default), then this namespace will be cleared after the test runs,
@@ -1519,12 +1545,29 @@ DocTestRunner objects
.. method:: summarize(verbose=None)
Print a summary of all the test cases that have been run by this DocTestRunner,
- and return a :term:`named tuple` ``TestResults(failed, attempted)``.
+ and return a :class:`TestResults` instance.
The optional *verbose* argument controls how detailed the summary is. If the
verbosity is not specified, then the :class:`DocTestRunner`'s verbosity is
used.
+ :class:`DocTestParser` has the following attributes:
+
+ .. attribute:: tries
+
+ Number of attempted examples.
+
+ .. attribute:: failures
+
+ Number of failed examples.
+
+ .. attribute:: skips
+
+ Number of skipped examples.
+
+ .. versionadded:: 3.13
+
+
.. _doctest-outputchecker:
OutputChecker objects
diff --git a/Doc/library/unittest.mock-examples.rst b/Doc/library/unittest.mock-examples.rst
index 895b9f9f07671b..744fc9de63cd16 100644
--- a/Doc/library/unittest.mock-examples.rst
+++ b/Doc/library/unittest.mock-examples.rst
@@ -579,14 +579,14 @@ Partial mocking
In some tests I wanted to mock out a call to :meth:`datetime.date.today`
to return a known date, but I didn't want to prevent the code under test from
creating new date objects. Unfortunately :class:`datetime.date` is written in C, and
-so I couldn't just monkey-patch out the static :meth:`date.today` method.
+so I couldn't just monkey-patch out the static :meth:`datetime.date.today` method.
I found a simple way of doing this that involved effectively wrapping the date
class with a mock, but passing through calls to the constructor to the real
class (and returning real instances).
The :func:`patch decorator ` is used here to
-mock out the ``date`` class in the module under test. The :attr:`side_effect`
+mock out the ``date`` class in the module under test. The :attr:`~Mock.side_effect`
attribute on the mock date class is then set to a lambda function that returns
a real date. When the mock date class is called a real date will be
constructed and returned by ``side_effect``. ::
@@ -766,8 +766,8 @@ mock has a nice API for making assertions about how your mock objects are used.
>>> mock.foo_bar.assert_called_with('baz', spam='eggs')
If your mock is only being called once you can use the
-:meth:`assert_called_once_with` method that also asserts that the
-:attr:`call_count` is one.
+:meth:`~Mock.assert_called_once_with` method that also asserts that the
+:attr:`~Mock.call_count` is one.
>>> mock.foo_bar.assert_called_once_with('baz', spam='eggs')
>>> mock.foo_bar()
@@ -835,7 +835,7 @@ One possibility would be for mock to copy the arguments you pass in. This
could then cause problems if you do assertions that rely on object identity
for equality.
-Here's one solution that uses the :attr:`side_effect`
+Here's one solution that uses the :attr:`~Mock.side_effect`
functionality. If you provide a ``side_effect`` function for a mock then
``side_effect`` will be called with the same args as the mock. This gives us an
opportunity to copy the arguments and store them for later assertions. In this
@@ -971,7 +971,8 @@ We can do this with :class:`MagicMock`, which will behave like a dictionary,
and using :data:`~Mock.side_effect` to delegate dictionary access to a real
underlying dictionary that is under our control.
-When the :meth:`__getitem__` and :meth:`__setitem__` methods of our ``MagicMock`` are called
+When the :meth:`~object.__getitem__` and :meth:`~object.__setitem__` methods
+of our ``MagicMock`` are called
(normal dictionary access) then ``side_effect`` is called with the key (and in
the case of ``__setitem__`` the value too). We can also control what is returned.
diff --git a/Doc/library/uuid.rst b/Doc/library/uuid.rst
index 94b9a432372195..adf01770656754 100644
--- a/Doc/library/uuid.rst
+++ b/Doc/library/uuid.rst
@@ -22,7 +22,7 @@ random UUID.
Depending on support from the underlying platform, :func:`uuid1` may or may
not return a "safe" UUID. A safe UUID is one which is generated using
synchronization methods that ensure no two processes can obtain the same
-UUID. All instances of :class:`UUID` have an :attr:`is_safe` attribute
+UUID. All instances of :class:`UUID` have an :attr:`~UUID.is_safe` attribute
which relays any information about the UUID's safety, using this enumeration:
.. class:: SafeUUID
@@ -95,25 +95,34 @@ which relays any information about the UUID's safety, using this enumeration:
A tuple of the six integer fields of the UUID, which are also available as six
individual attributes and two derived attributes:
- +------------------------------+-------------------------------+
- | Field | Meaning |
- +==============================+===============================+
- | :attr:`time_low` | the first 32 bits of the UUID |
- +------------------------------+-------------------------------+
- | :attr:`time_mid` | the next 16 bits of the UUID |
- +------------------------------+-------------------------------+
- | :attr:`time_hi_version` | the next 16 bits of the UUID |
- +------------------------------+-------------------------------+
- | :attr:`clock_seq_hi_variant` | the next 8 bits of the UUID |
- +------------------------------+-------------------------------+
- | :attr:`clock_seq_low` | the next 8 bits of the UUID |
- +------------------------------+-------------------------------+
- | :attr:`node` | the last 48 bits of the UUID |
- +------------------------------+-------------------------------+
- | :attr:`time` | the 60-bit timestamp |
- +------------------------------+-------------------------------+
- | :attr:`clock_seq` | the 14-bit sequence number |
- +------------------------------+-------------------------------+
+.. list-table::
+
+ * - Field
+ - Meaning
+
+ * - .. attribute:: UUID.time_low
+ - The first 32 bits of the UUID.
+
+ * - .. attribute:: UUID.time_mid
+ - The next 16 bits of the UUID.
+
+ * - .. attribute:: UUID.time_hi_version
+ - The next 16 bits of the UUID.
+
+ * - .. attribute:: UUID.clock_seq_hi_variant
+ - The next 8 bits of the UUID.
+
+ * - .. attribute:: UUID.clock_seq_low
+ - The next 8 bits of the UUID.
+
+ * - .. attribute:: UUID.node
+ - The last 48 bits of the UUID.
+
+ * - .. attribute:: UUID.time
+ - The 60-bit timestamp.
+
+ * - .. attribute:: UUID.clock_seq
+ - The 14-bit sequence number.
.. attribute:: UUID.hex
@@ -233,7 +242,7 @@ The :mod:`uuid` module defines the following namespace identifiers for use with
text output format.
The :mod:`uuid` module defines the following constants for the possible values
-of the :attr:`variant` attribute:
+of the :attr:`~UUID.variant` attribute:
.. data:: RESERVED_NCS
diff --git a/Doc/tools/.nitignore b/Doc/tools/.nitignore
index 1d89c9c683a070..a6268048e143db 100644
--- a/Doc/tools/.nitignore
+++ b/Doc/tools/.nitignore
@@ -131,12 +131,10 @@ Doc/library/tkinter.ttk.rst
Doc/library/traceback.rst
Doc/library/tty.rst
Doc/library/turtle.rst
-Doc/library/unittest.mock-examples.rst
Doc/library/unittest.mock.rst
Doc/library/unittest.rst
Doc/library/urllib.parse.rst
Doc/library/urllib.request.rst
-Doc/library/uuid.rst
Doc/library/weakref.rst
Doc/library/wsgiref.rst
Doc/library/xml.dom.minidom.rst
diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst
index d35d20ebb25293..1c91a1dadb899f 100644
--- a/Doc/whatsnew/3.13.rst
+++ b/Doc/whatsnew/3.13.rst
@@ -122,6 +122,14 @@ dbm
from the database.
(Contributed by Dong-hee Na in :gh:`107122`.)
+doctest
+-------
+
+* The :meth:`doctest.DocTestRunner.run` method now counts the number of skipped
+ tests. Add :attr:`doctest.DocTestRunner.skips` and
+ :attr:`doctest.TestResults.skipped` attributes.
+ (Contributed by Victor Stinner in :gh:`108794`.)
+
io
--
@@ -915,6 +923,25 @@ New Features
Porting to Python 3.13
----------------------
+* ``Python.h`` no longer includes the ```` standard header. It was
+ included for the ``finite()`` function which is now provided by the
+ ```` header. It should now be included explicitly if needed. Remove
+ also the ``HAVE_IEEEFP_H`` macro.
+ (Contributed by Victor Stinner in :gh:`108765`.)
+
+* ``Python.h`` no longer includes the ```` standard header file. If
+ needed, it should now be included explicitly. For example, it provides the
+ functions: ``close()``, ``getpagesize()``, ``getpid()`` and ``sysconf()``.
+ (Contributed by Victor Stinner in :gh:`108765`.)
+
+* ``Python.h`` no longer includes these standard header files: ````,
+ ```` and ````. If needed, they should now be
+ included explicitly. For example, ```` provides the ``clock()`` and
+ ``gmtime()`` functions, ```` provides the ``select()``
+ function, and ```` provides the ``futimes()``, ``gettimeofday()``
+ and ``setitimer()`` functions.
+ (Contributed by Victor Stinner in :gh:`108765`.)
+
Deprecated
----------
diff --git a/Include/Python.h b/Include/Python.h
index 07f6c202a7f126..4cc72bb23ce7a3 100644
--- a/Include/Python.h
+++ b/Include/Python.h
@@ -5,42 +5,50 @@
#ifndef Py_PYTHON_H
#define Py_PYTHON_H
-// Since this is a "meta-include" file, no #ifdef __cplusplus / extern "C" {
+// Since this is a "meta-include" file, "#ifdef __cplusplus / extern "C" {"
+// is not needed.
+
// Include Python header files
#include "patchlevel.h"
#include "pyconfig.h"
#include "pymacconfig.h"
-#if defined(__sgi) && !defined(_SGI_MP_SOURCE)
-# define _SGI_MP_SOURCE
+
+// Include standard header files
+#include // assert()
+#include // tolower()
+#include // uintptr_t
+#include // INT_MAX
+#include // HUGE_VAL
+#include // va_list
+#include // wchar_t
+#ifdef HAVE_STDDEF_H
+# include // size_t
+#endif
+#ifdef HAVE_SYS_TYPES_H
+# include // ssize_t
#endif
-// stdlib.h, stdio.h, errno.h and string.h headers are not used by Python
-// headers, but kept for backward compatibility. They are excluded from the
-// limited C API of Python 3.11.
+// errno.h, stdio.h, stdlib.h and string.h headers are no longer used by
+// Python, but kept for backward compatibility (avoid compiler warnings).
+// They are no longer included by limited C API version 3.11 and newer.
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# include
-# include // FILE*
# include // errno
+# include // FILE*
+# include // getenv()
# include // memcpy()
#endif
-#ifndef MS_WINDOWS
-# include
-#endif
-#ifdef HAVE_STDDEF_H
-# include // size_t
-#endif
-#include // assert()
-#include // wchar_t
+// Include Python header files
#include "pyport.h"
#include "pymacro.h"
#include "pymath.h"
#include "pymem.h"
#include "pytypedefs.h"
#include "pybuffer.h"
+#include "pystats.h"
#include "object.h"
#include "objimpl.h"
#include "typeslots.h"
diff --git a/Include/bytesobject.h b/Include/bytesobject.h
index ee448cd02bdab3..c5a24195be6bc3 100644
--- a/Include/bytesobject.h
+++ b/Include/bytesobject.h
@@ -1,5 +1,4 @@
-
-/* Bytes object interface */
+// Bytes object interface
#ifndef Py_BYTESOBJECT_H
#define Py_BYTESOBJECT_H
@@ -7,8 +6,6 @@
extern "C" {
#endif
-#include // va_list
-
/*
Type PyBytesObject represents a byte string. An extra zero byte is
reserved at the end to ensure it is zero-terminated, but a size is
diff --git a/Include/internal/pycore_condvar.h b/Include/internal/pycore_condvar.h
index db8682a4c077aa..489e67d4ec4f9f 100644
--- a/Include/internal/pycore_condvar.h
+++ b/Include/internal/pycore_condvar.h
@@ -5,6 +5,10 @@
# error "this header requires Py_BUILD_CORE define"
#endif
+#ifndef MS_WINDOWS
+# include // _POSIX_THREADS
+#endif
+
#ifndef _POSIX_THREADS
/* This means pthreads are not implemented in libc headers, hence the macro
not present in unistd.h. But they still can be implemented as an external
diff --git a/Include/modsupport.h b/Include/modsupport.h
index 7c15ab50c320e2..6efe9dfaa9089e 100644
--- a/Include/modsupport.h
+++ b/Include/modsupport.h
@@ -1,3 +1,4 @@
+// Module support interface
#ifndef Py_MODSUPPORT_H
#define Py_MODSUPPORT_H
@@ -5,10 +6,6 @@
extern "C" {
#endif
-/* Module support interface */
-
-#include // va_list
-
PyAPI_FUNC(int) PyArg_Parse(PyObject *, const char *, ...);
PyAPI_FUNC(int) PyArg_ParseTuple(PyObject *, const char *, ...);
PyAPI_FUNC(int) PyArg_ParseTupleAndKeywords(PyObject *, PyObject *,
diff --git a/Include/object.h b/Include/object.h
index de2a1ce0f3c4dd..b94b2907e4f163 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -51,8 +51,6 @@ A standard interface exists for objects that contain an array of items
whose size is determined when the object is allocated.
*/
-#include "pystats.h"
-
/* Py_DEBUG implies Py_REF_DEBUG. */
#if defined(Py_DEBUG) && !defined(Py_REF_DEBUG)
# define Py_REF_DEBUG
diff --git a/Include/objimpl.h b/Include/objimpl.h
index ef871c5ea93ebe..967e2776767756 100644
--- a/Include/objimpl.h
+++ b/Include/objimpl.h
@@ -1,12 +1,8 @@
-/* The PyObject_ memory family: high-level object memory interfaces.
- See pymem.h for the low-level PyMem_ family.
-*/
+// The PyObject_ memory family: high-level object memory interfaces.
+// See pymem.h for the low-level PyMem_ family.
#ifndef Py_OBJIMPL_H
#define Py_OBJIMPL_H
-
-#include "pymem.h"
-
#ifdef __cplusplus
extern "C" {
#endif
@@ -231,4 +227,4 @@ PyAPI_FUNC(int) PyObject_GC_IsFinalized(PyObject *);
#ifdef __cplusplus
}
#endif
-#endif /* !Py_OBJIMPL_H */
+#endif // !Py_OBJIMPL_H
diff --git a/Include/pyerrors.h b/Include/pyerrors.h
index d089fa71779330..5d0028c116e2d8 100644
--- a/Include/pyerrors.h
+++ b/Include/pyerrors.h
@@ -1,13 +1,11 @@
+// Error handling definitions
+
#ifndef Py_ERRORS_H
#define Py_ERRORS_H
#ifdef __cplusplus
extern "C" {
#endif
-#include // va_list
-
-/* Error handling definitions */
-
PyAPI_FUNC(void) PyErr_SetNone(PyObject *);
PyAPI_FUNC(void) PyErr_SetObject(PyObject *, PyObject *);
PyAPI_FUNC(void) PyErr_SetString(
diff --git a/Include/pymem.h b/Include/pymem.h
index e882645757bfd3..68e33f90b7b913 100644
--- a/Include/pymem.h
+++ b/Include/pymem.h
@@ -1,12 +1,8 @@
-/* The PyMem_ family: low-level memory allocation interfaces.
- See objimpl.h for the PyObject_ memory family.
-*/
+// The PyMem_ family: low-level memory allocation interfaces.
+// See objimpl.h for the PyObject_ memory family.
#ifndef Py_PYMEM_H
#define Py_PYMEM_H
-
-#include "pyport.h"
-
#ifdef __cplusplus
extern "C" {
#endif
@@ -100,5 +96,4 @@ PyAPI_FUNC(void) PyMem_Free(void *ptr);
#ifdef __cplusplus
}
#endif
-
-#endif /* !Py_PYMEM_H */
+#endif // !Py_PYMEM_H
diff --git a/Include/pyport.h b/Include/pyport.h
index 115b54fd969287..c4168d10f58151 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -1,13 +1,8 @@
#ifndef Py_PYPORT_H
#define Py_PYPORT_H
-#include "pyconfig.h" /* include for defines */
-
-#include
-
-#include
#ifndef UCHAR_MAX
-# error "limits.h must define UCHAR_MAX"
+# error " header must define UCHAR_MAX"
#endif
#if UCHAR_MAX != 255
# error "Python's source code assumes C's unsigned char is an 8-bit type"
@@ -189,31 +184,6 @@ typedef Py_ssize_t Py_ssize_clean_t;
# define Py_MEMCPY memcpy
#endif
-#ifdef HAVE_IEEEFP_H
-#include /* needed for 'finite' declaration on some platforms */
-#endif
-
-#include /* Moved here from the math section, before extern "C" */
-
-/********************************************
- * WRAPPER FOR and/or *
- ********************************************/
-
-#ifdef HAVE_SYS_TIME_H
-#include
-#endif
-#include
-
-/******************************
- * WRAPPER FOR *
- ******************************/
-
-/* NB caller must include */
-
-#ifdef HAVE_SYS_SELECT_H
-#include
-#endif /* !HAVE_SYS_SELECT_H */
-
/*******************************
* stat() and fstat() fiddling *
*******************************/
@@ -422,32 +392,6 @@ extern "C" {
# define Py_NO_INLINE
#endif
-/**************************************************************************
-Prototypes that are missing from the standard include files on some systems
-(and possibly only some versions of such systems.)
-
-Please be conservative with adding new ones, document them and enclose them
-in platform-specific #ifdefs.
-**************************************************************************/
-
-#ifdef SOLARIS
-/* Unchecked */
-extern int gethostname(char *, int);
-#endif
-
-#ifdef HAVE__GETPTY
-#include /* we need to import mode_t */
-extern char * _getpty(int *, int, mode_t, int);
-#endif
-
-/* On QNX 6, struct termio must be declared by including sys/termio.h
- if TCGETA, TCSETA, TCSETAW, or TCSETAF are used. sys/termio.h must
- be included before termios.h or it will generate an error. */
-#if defined(HAVE_SYS_TERMIO_H) && !defined(__hpux)
-#include
-#endif
-
-
/* On 4.4BSD-descendants, ctype functions serves the whole range of
* wchar_t character set rather than single byte code points only.
* This characteristic can break some operations of string object
@@ -771,4 +715,8 @@ extern char * _getpty(int *, int, mode_t, int);
# define ALIGNOF_MAX_ALIGN_T _Alignof(long double)
#endif
+#if defined(__sgi) && !defined(_SGI_MP_SOURCE)
+# define _SGI_MP_SOURCE
+#endif
+
#endif /* Py_PYPORT_H */
diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h
index 5839c747a29275..f00277787122aa 100644
--- a/Include/unicodeobject.h
+++ b/Include/unicodeobject.h
@@ -1,8 +1,6 @@
#ifndef Py_UNICODEOBJECT_H
#define Py_UNICODEOBJECT_H
-#include // va_list
-
/*
Unicode implementation based on original code by Fredrik Lundh,
@@ -55,8 +53,6 @@ Copyright (c) Corporation for National Research Initiatives.
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
* -------------------------------------------------------------------- */
-#include
-
/* === Internal API ======================================================= */
/* --- Internal Unicode Format -------------------------------------------- */
@@ -93,10 +89,6 @@ Copyright (c) Corporation for National Research Initiatives.
# endif
#endif
-#ifdef HAVE_WCHAR_H
-# include
-#endif
-
/* Py_UCS4 and Py_UCS2 are typedefs for the respective
unicode representations. */
typedef uint32_t Py_UCS4;
diff --git a/Lib/_pydatetime.py b/Lib/_pydatetime.py
index f4fc2c58e5e293..549fcda19dccf2 100644
--- a/Lib/_pydatetime.py
+++ b/Lib/_pydatetime.py
@@ -1812,7 +1812,7 @@ def utcfromtimestamp(cls, t):
warnings.warn("datetime.utcfromtimestamp() is deprecated and scheduled "
"for removal in a future version. Use timezone-aware "
"objects to represent datetimes in UTC: "
- "datetime.fromtimestamp(t, datetime.UTC).",
+ "datetime.datetime.fromtimestamp(t, datetime.UTC).",
DeprecationWarning,
stacklevel=2)
return cls._fromtimestamp(t, True, None)
@@ -1830,7 +1830,7 @@ def utcnow(cls):
warnings.warn("datetime.utcnow() is deprecated and scheduled for "
"removal in a future version. Instead, Use timezone-aware "
"objects to represent datetimes in UTC: "
- "datetime.now(datetime.UTC).",
+ "datetime.datetime.now(datetime.UTC).",
DeprecationWarning,
stacklevel=2)
t = _time.time()
diff --git a/Lib/doctest.py b/Lib/doctest.py
index a63df46a112e64..46b4dd6769b063 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -105,7 +105,23 @@ def _test():
from io import StringIO, IncrementalNewlineDecoder
from collections import namedtuple
-TestResults = namedtuple('TestResults', 'failed attempted')
+
+class TestResults(namedtuple('TestResults', 'failed attempted')):
+ def __new__(cls, failed, attempted, *, skipped=0):
+ results = super().__new__(cls, failed, attempted)
+ results.skipped = skipped
+ return results
+
+ def __repr__(self):
+ if self.skipped:
+ return (f'TestResults(failed={self.failed}, '
+ f'attempted={self.attempted}, '
+ f'skipped={self.skipped})')
+ else:
+ # Leave the repr() unchanged for backward compatibility
+ # if skipped is zero
+ return super().__repr__()
+
# There are 4 basic classes:
# - Example: a