[Python-checkins] [3.12] [3.13] gh-124969: Fix locale.nl_langinfo(locale.ALT_DIGITS) (GH-124974) (GH-125232) (GH-125284)
https://github.com/python/cpython/commit/171ebcd4df268c77f1ca03339a137ca6a54242e5 commit: 171ebcd4df268c77f1ca03339a137ca6a54242e5 branch: 3.12 author: Miss Islington (bot) <[email protected]> committer: serhiy-storchaka date: 2024-10-11T09:37:55+03:00 summary: [3.12] [3.13] gh-124969: Fix locale.nl_langinfo(locale.ALT_DIGITS) (GH-124974) (GH-125232) (GH-125284) (cherry picked from commit 26a93189e4c3674a9e0acbd7923b1f27ff01419e) Co-authored-by: Serhiy Storchaka Returns a tuple of up to 100 strings for ALT_DIGITS lookup (an empty tuple on most locales). Previously it returned the first item of that tuple or an empty string. (cherry picked from commit 21c04e1a972bd1b6285e0ea41fa107d635bbe43a) Co-authored-by: Serhiy Storchaka files: A Misc/NEWS.d/next/Library/2024-10-08-12-09-09.gh-issue-124969._VBQLq.rst M Doc/library/locale.rst M Lib/test/test__locale.py M Modules/_localemodule.c diff --git a/Doc/library/locale.rst b/Doc/library/locale.rst index 60975bf9177dad..f0553d51fedf14 100644 --- a/Doc/library/locale.rst +++ b/Doc/library/locale.rst @@ -158,7 +158,8 @@ The :mod:`locale` module defines the following exception and functions: .. function:: nl_langinfo(option) - Return some locale-specific information as a string. This function is not + Return some locale-specific information as a string (or a tuple for + ``ALT_DIGITS``). This function is not available on all systems, and the set of possible options might also vary across platforms. The possible argument values are numbers, for which symbolic constants are available in the locale module. @@ -311,8 +312,7 @@ The :mod:`locale` module defines the following exception and functions: .. data:: ALT_DIGITS - Get a representation of up to 100 values used to represent the values - 0 to 99. + Get a tuple of up to 100 strings used to represent the values 0 to 99. .. function:: getdefaultlocale([envvars]) diff --git a/Lib/test/test__locale.py b/Lib/test/test__locale.py index 0947464bb8c04e..5041def7216197 100644 --- a/Lib/test/test__locale.py +++ b/Lib/test/test__locale.py @@ -1,4 +1,4 @@ -from _locale import (setlocale, LC_ALL, LC_CTYPE, LC_NUMERIC, localeconv, Error) +from _locale import (setlocale, LC_ALL, LC_CTYPE, LC_NUMERIC, LC_TIME, localeconv, Error) try: from _locale import (RADIXCHAR, THOUSEP, nl_langinfo) except ImportError: @@ -74,6 +74,17 @@ def accept(loc): 'ps_AF': ('\u066b', '\u066c'), } +known_alt_digits = { +'C': (0, {}), +'en_US': (0, {}), +'fa_IR': (100, {0: '\u06f0\u06f0', 10: '\u06f1\u06f0', 99: '\u06f9\u06f9'}), +'ja_JP': (100, {0: '\u3007', 10: '\u5341', 99: '\u4e5d\u5341\u4e5d'}), +'lzh_TW': (32, {0: '\u3007', 10: '\u5341', 31: '\u5345\u4e00'}), +'my_MM': (100, {0: '\u1040\u1040', 10: '\u1041\u1040', 99: '\u1049\u1049'}), +'or_IN': (100, {0: '\u0b66', 10: '\u0b67\u0b66', 99: '\u0b6f\u0b6f'}), +'shn_MM': (100, {0: '\u1090\u1090', 10: '\u1091\u1090', 99: '\u1099\u1099'}), +} + if sys.platform == 'win32': # ps_AF doesn't work on Windows: see bpo-38324 (msg361830) del known_numerics['ps_AF'] @@ -176,6 +187,35 @@ def test_lc_numeric_basic(self): if not tested: self.skipTest('no suitable locales') [email protected](nl_langinfo, "nl_langinfo is not available") [email protected](hasattr(locale, 'ALT_DIGITS'), "requires locale.ALT_DIGITS") [email protected]( +support.is_emscripten or support.is_wasi, +"musl libc issue on Emscripten, bpo-46390" +) +def test_alt_digits_nl_langinfo(self): +# Test nl_langinfo(ALT_DIGITS) +tested = False +for loc, (count, samples) in known_alt_digits.items(): +with self.subTest(locale=loc): +try: +setlocale(LC_TIME, loc) +setlocale(LC_CTYPE, loc) +except Error: +self.skipTest(f'no locale {loc!r}') +continue +with self.subTest(locale=loc): +alt_digits = nl_langinfo(locale.ALT_DIGITS) +self.assertIsInstance(alt_digits, tuple) +if count and not alt_digits and support.is_apple: +self.skipTest(f'ALT_DIGITS is not set for locale {loc!r} on Apple platforms') +self.assertEqual(len(alt_digits), count) +for i in samples: +self.assertEqual(alt_digits[i], samples[i]) +tested = True +if not tested: +self.skipTest('no suitable locales') + def test_float_parsing(self): # Bug #1391872: Test whether float parsing is okay on European # locales. diff --git a/Misc/NEWS.d/next/Library/2024-10-08-12-09-09.gh-issue-124969._VBQLq.rst b/Misc/NEWS.d/next/Library/2024-10-08-12-09-09.gh-issue-124969._VBQLq.rst new file mode 100644 index 00..
[Python-checkins] [3.13] gh-125296: Fix strange fragment identifier for `name or flags` in argparse docs (GH-125297) (#125299)
https://github.com/python/cpython/commit/1fe27103e01c895d493642818bdaafba4217989a commit: 1fe27103e01c895d493642818bdaafba4217989a branch: 3.13 author: Miss Islington (bot) <[email protected]> committer: sobolevn date: 2024-10-11T06:35:49Z summary: [3.13] gh-125296: Fix strange fragment identifier for `name or flags` in argparse docs (GH-125297) (#125299) gh-125296: Fix strange fragment identifier for `name or flags` in argparse docs (GH-125297) (cherry picked from commit c1913effeed4e4da4d5310a40ab518945001ffba) Co-authored-by: Savannah Ostrowski files: M Doc/library/argparse.rst diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index d2705e485c3358..d06264f72ee081 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -598,7 +598,7 @@ The add_argument() method The following sections describe how each of these are used. -.. _name_or_flags: +.. _`name or flags`: name or flags ^ ___ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
[Python-checkins] [3.12] gh-125296: Fix strange fragment identifier for `name or flags` in argparse docs (GH-125297) (#125300)
https://github.com/python/cpython/commit/ee1257cb9ca913745fd96730b739f538bce60f0a commit: ee1257cb9ca913745fd96730b739f538bce60f0a branch: 3.12 author: Miss Islington (bot) <[email protected]> committer: sobolevn date: 2024-10-11T06:39:54Z summary: [3.12] gh-125296: Fix strange fragment identifier for `name or flags` in argparse docs (GH-125297) (#125300) gh-125296: Fix strange fragment identifier for `name or flags` in argparse docs (GH-125297) (cherry picked from commit c1913effeed4e4da4d5310a40ab518945001ffba) Co-authored-by: Savannah Ostrowski files: M Doc/library/argparse.rst diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 6d8b207cbc03ab..bcbdb0516bba93 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -596,7 +596,7 @@ The add_argument() method The following sections describe how each of these are used. -.. _name_or_flags: +.. _`name or flags`: name or flags ^ ___ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
[Python-checkins] gh-125296: Fix strange fragment identifier for `name or flags` in argparse docs (#125297)
https://github.com/python/cpython/commit/c1913effeed4e4da4d5310a40ab518945001ffba commit: c1913effeed4e4da4d5310a40ab518945001ffba branch: main author: Savannah Ostrowski committer: sobolevn date: 2024-10-11T09:30:27+03:00 summary: gh-125296: Fix strange fragment identifier for `name or flags` in argparse docs (#125297) files: M Doc/library/argparse.rst diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 4eb6fad41f11ef..d337de87ca8f39 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -602,7 +602,7 @@ The add_argument() method The following sections describe how each of these are used. -.. _name_or_flags: +.. _`name or flags`: name or flags ^ ___ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
[Python-checkins] [3.13] gh-124969: Fix locale.nl_langinfo(locale.ALT_DIGITS) (GH-124974) (#125232)
https://github.com/python/cpython/commit/26a93189e4c3674a9e0acbd7923b1f27ff01419e
commit: 26a93189e4c3674a9e0acbd7923b1f27ff01419e
branch: 3.13
author: Serhiy Storchaka
committer: freakboy3742
date: 2024-10-11T05:56:22+08:00
summary:
[3.13] gh-124969: Fix locale.nl_langinfo(locale.ALT_DIGITS) (GH-124974)
(#125232)
Returns a tuple of up to 100 strings for ALT_DIGITS lookup (an empty tuple on
most locales).
Previously it returned the first item of that tuple or an empty string.
(cherry picked from commit 21c04e1a972bd1b6285e0ea41fa107d635bbe43a)
files:
A Misc/NEWS.d/next/Library/2024-10-08-12-09-09.gh-issue-124969._VBQLq.rst
M Doc/library/locale.rst
M Lib/test/test__locale.py
M Modules/_localemodule.c
diff --git a/Doc/library/locale.rst b/Doc/library/locale.rst
index 0246f99157024a..0bd7957c348d00 100644
--- a/Doc/library/locale.rst
+++ b/Doc/library/locale.rst
@@ -158,7 +158,8 @@ The :mod:`locale` module defines the following exception
and functions:
.. function:: nl_langinfo(option)
- Return some locale-specific information as a string. This function is not
+ Return some locale-specific information as a string (or a tuple for
+ ``ALT_DIGITS``). This function is not
available on all systems, and the set of possible options might also vary
across platforms. The possible argument values are numbers, for which
symbolic constants are available in the locale module.
@@ -311,8 +312,7 @@ The :mod:`locale` module defines the following exception
and functions:
.. data:: ALT_DIGITS
- Get a representation of up to 100 values used to represent the values
- 0 to 99.
+ Get a tuple of up to 100 strings used to represent the values 0 to 99.
.. function:: getdefaultlocale([envvars])
diff --git a/Lib/test/test__locale.py b/Lib/test/test__locale.py
index 0947464bb8c04e..5041def7216197 100644
--- a/Lib/test/test__locale.py
+++ b/Lib/test/test__locale.py
@@ -1,4 +1,4 @@
-from _locale import (setlocale, LC_ALL, LC_CTYPE, LC_NUMERIC, localeconv,
Error)
+from _locale import (setlocale, LC_ALL, LC_CTYPE, LC_NUMERIC, LC_TIME,
localeconv, Error)
try:
from _locale import (RADIXCHAR, THOUSEP, nl_langinfo)
except ImportError:
@@ -74,6 +74,17 @@ def accept(loc):
'ps_AF': ('\u066b', '\u066c'),
}
+known_alt_digits = {
+'C': (0, {}),
+'en_US': (0, {}),
+'fa_IR': (100, {0: '\u06f0\u06f0', 10: '\u06f1\u06f0', 99:
'\u06f9\u06f9'}),
+'ja_JP': (100, {0: '\u3007', 10: '\u5341', 99: '\u4e5d\u5341\u4e5d'}),
+'lzh_TW': (32, {0: '\u3007', 10: '\u5341', 31: '\u5345\u4e00'}),
+'my_MM': (100, {0: '\u1040\u1040', 10: '\u1041\u1040', 99:
'\u1049\u1049'}),
+'or_IN': (100, {0: '\u0b66', 10: '\u0b67\u0b66', 99: '\u0b6f\u0b6f'}),
+'shn_MM': (100, {0: '\u1090\u1090', 10: '\u1091\u1090', 99:
'\u1099\u1099'}),
+}
+
if sys.platform == 'win32':
# ps_AF doesn't work on Windows: see bpo-38324 (msg361830)
del known_numerics['ps_AF']
@@ -176,6 +187,35 @@ def test_lc_numeric_basic(self):
if not tested:
self.skipTest('no suitable locales')
[email protected](nl_langinfo, "nl_langinfo is not available")
[email protected](hasattr(locale, 'ALT_DIGITS'), "requires
locale.ALT_DIGITS")
[email protected](
+support.is_emscripten or support.is_wasi,
+"musl libc issue on Emscripten, bpo-46390"
+)
+def test_alt_digits_nl_langinfo(self):
+# Test nl_langinfo(ALT_DIGITS)
+tested = False
+for loc, (count, samples) in known_alt_digits.items():
+with self.subTest(locale=loc):
+try:
+setlocale(LC_TIME, loc)
+setlocale(LC_CTYPE, loc)
+except Error:
+self.skipTest(f'no locale {loc!r}')
+continue
+with self.subTest(locale=loc):
+alt_digits = nl_langinfo(locale.ALT_DIGITS)
+self.assertIsInstance(alt_digits, tuple)
+if count and not alt_digits and support.is_apple:
+self.skipTest(f'ALT_DIGITS is not set for locale
{loc!r} on Apple platforms')
+self.assertEqual(len(alt_digits), count)
+for i in samples:
+self.assertEqual(alt_digits[i], samples[i])
+tested = True
+if not tested:
+self.skipTest('no suitable locales')
+
def test_float_parsing(self):
# Bug #1391872: Test whether float parsing is okay on European
# locales.
diff --git
a/Misc/NEWS.d/next/Library/2024-10-08-12-09-09.gh-issue-124969._VBQLq.rst
b/Misc/NEWS.d/next/Library/2024-10-08-12-09-09.gh-issue-124969._VBQLq.rst
new file mode 100644
index 00..b5082b90721d42
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-10-08-12-09-09.gh-issue-124969._VBQLq.rst
@@ -0,0 +1,3 @@
+Fix ``locale.nl_langinfo(locale.ALT_DIGITS)``. Now it returns a tuple of up
+to 100 strings (a
[Python-checkins] gh-125118: don't copy arbitrary values to _Bool in the struct module (GH-125169)
https://github.com/python/cpython/commit/87d7315ac57250046372b0d9ae4619ba619c8c87
commit: 87d7315ac57250046372b0d9ae4619ba619c8c87
branch: main
author: Sergey B Kirpichev
committer: encukou
date: 2024-10-10T14:42:03+02:00
summary:
gh-125118: don't copy arbitrary values to _Bool in the struct module (GH-125169)
memcopy'ing arbitrary values to _Bool variable triggers undefined
behaviour. Avoid this.
We assume that `false` is represented by all zero bytes.
Credits to Alex Gaynor.
Co-authored-by: Sam Gross
Co-authored-by: Victor Stinner
Co-authored-by: Petr Viktorin
files:
A Misc/NEWS.d/next/Library/2024-10-09-07-09-00.gh-issue-125118.J9rQ1S.rst
M Lib/test/test_struct.py
M Modules/_struct.c
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py
index e3193c7863fbae..04ec3ed0837c82 100644
--- a/Lib/test/test_struct.py
+++ b/Lib/test/test_struct.py
@@ -540,6 +540,9 @@ def __bool__(self):
for c in [b'\x01', b'\x7f', b'\xff', b'\x0f', b'\xf0']:
self.assertTrue(struct.unpack('>?', c)[0])
+self.assertTrue(struct.unpack('https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]
[Python-checkins] gh-125196: Use PyUnicodeWriter for JSON encoder (#125249)
https://github.com/python/cpython/commit/c914212474792312bb125211bae5719650fe2f58
commit: c914212474792312bb125211bae5719650fe2f58
branch: main
author: Victor Stinner
committer: vstinner
date: 2024-10-10T15:33:00+02:00
summary:
gh-125196: Use PyUnicodeWriter for JSON encoder (#125249)
Replace the private _PyUnicodeWriter with the public PyUnicodeWriter.
files:
M Modules/_json.c
diff --git a/Modules/_json.c b/Modules/_json.c
index 9e29de0f22465f..ce0093ab431d05 100644
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -86,11 +86,11 @@ encoder_dealloc(PyObject *self);
static int
encoder_clear(PyEncoderObject *self);
static int
-encoder_listencode_list(PyEncoderObject *s, _PyUnicodeWriter *writer, PyObject
*seq, PyObject *newline_indent);
+encoder_listencode_list(PyEncoderObject *s, PyUnicodeWriter *writer, PyObject
*seq, PyObject *newline_indent);
static int
-encoder_listencode_obj(PyEncoderObject *s, _PyUnicodeWriter *writer, PyObject
*obj, PyObject *newline_indent);
+encoder_listencode_obj(PyEncoderObject *s, PyUnicodeWriter *writer, PyObject
*obj, PyObject *newline_indent);
static int
-encoder_listencode_dict(PyEncoderObject *s, _PyUnicodeWriter *writer, PyObject
*dct, PyObject *newline_indent);
+encoder_listencode_dict(PyEncoderObject *s, PyUnicodeWriter *writer, PyObject
*dct, PyObject *newline_indent);
static PyObject *
_encoded_const(PyObject *obj);
static void
@@ -1268,38 +1268,39 @@ encoder_call(PyEncoderObject *self, PyObject *args,
PyObject *kwds)
{
/* Python callable interface to encode_listencode_obj */
static char *kwlist[] = {"obj", "_current_indent_level", NULL};
-PyObject *obj, *result;
+PyObject *obj;
Py_ssize_t indent_level;
-_PyUnicodeWriter writer;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "On:_iterencode", kwlist,
-&obj, &indent_level))
+ &obj, &indent_level))
return NULL;
-_PyUnicodeWriter_Init(&writer);
-writer.overallocate = 1;
+PyUnicodeWriter *writer = PyUnicodeWriter_Create(0);
+if (writer == NULL) {
+return NULL;
+}
PyObject *newline_indent = NULL;
if (self->indent != Py_None) {
newline_indent = _create_newline_indent(self->indent, indent_level);
if (newline_indent == NULL) {
-_PyUnicodeWriter_Dealloc(&writer);
+PyUnicodeWriter_Discard(writer);
return NULL;
}
}
-if (encoder_listencode_obj(self, &writer, obj, newline_indent)) {
-_PyUnicodeWriter_Dealloc(&writer);
+if (encoder_listencode_obj(self, writer, obj, newline_indent)) {
+PyUnicodeWriter_Discard(writer);
Py_XDECREF(newline_indent);
return NULL;
}
Py_XDECREF(newline_indent);
-result = PyTuple_New(1);
-if (result == NULL ||
-PyTuple_SetItem(result, 0, _PyUnicodeWriter_Finish(&writer)) < 0) {
-Py_XDECREF(result);
+PyObject *str = PyUnicodeWriter_Finish(writer);
+if (str == NULL) {
return NULL;
}
+PyObject *result = PyTuple_Pack(1, str);
+Py_DECREF(str);
return result;
}
@@ -1370,16 +1371,16 @@ encoder_encode_string(PyEncoderObject *s, PyObject *obj)
}
static int
-_steal_accumulate(_PyUnicodeWriter *writer, PyObject *stolen)
+_steal_accumulate(PyUnicodeWriter *writer, PyObject *stolen)
{
/* Append stolen and then decrement its reference count */
-int rval = _PyUnicodeWriter_WriteStr(writer, stolen);
+int rval = PyUnicodeWriter_WriteStr(writer, stolen);
Py_DECREF(stolen);
return rval;
}
static int
-encoder_listencode_obj(PyEncoderObject *s, _PyUnicodeWriter *writer,
+encoder_listencode_obj(PyEncoderObject *s, PyUnicodeWriter *writer,
PyObject *obj, PyObject *newline_indent)
{
/* Encode Python object obj to a JSON term */
@@ -1387,13 +1388,13 @@ encoder_listencode_obj(PyEncoderObject *s,
_PyUnicodeWriter *writer,
int rv;
if (obj == Py_None) {
- return _PyUnicodeWriter_WriteASCIIString(writer, "null", 4);
+ return PyUnicodeWriter_WriteUTF8(writer, "null", 4);
}
else if (obj == Py_True) {
- return _PyUnicodeWriter_WriteASCIIString(writer, "true", 4);
+ return PyUnicodeWriter_WriteUTF8(writer, "true", 4);
}
else if (obj == Py_False) {
- return _PyUnicodeWriter_WriteASCIIString(writer, "false", 5);
+ return PyUnicodeWriter_WriteUTF8(writer, "false", 5);
}
else if (PyUnicode_Check(obj)) {
PyObject *encoded = encoder_encode_string(s, obj);
@@ -1402,6 +1403,10 @@ encoder_listencode_obj(PyEncoderObject *s,
_PyUnicodeWriter *writer,
return _steal_accumulate(writer, encoded);
}
else if (PyLong_Check(obj)) {
+if (PyLong_CheckExact(obj)) {
+// Fast-path for exact integers
+return PyUnicodeWriter_WriteRepr(writer, obj);
+}
PyObject *encoded = PyLong_Type.tp_repr(obj);
if (encoded == NULL)
[Python-checkins] [3.12] GH-121970: Extract ``availability`` into a new extension (GH-125082) (#125238)
https://github.com/python/cpython/commit/caa4924917f2c5e70d9e199a71893a6fc8bc43da commit: caa4924917f2c5e70d9e199a71893a6fc8bc43da branch: 3.12 author: Adam Turner <[email protected]> committer: AA-Turner <[email protected]> date: 2024-10-10T09:16:03Z summary: [3.12] GH-121970: Extract ``availability`` into a new extension (GH-125082) (#125238) (cherry picked from commit cbfd39247983309a9ef0ae6da6c61cc71665b967) files: A Doc/tools/extensions/availability.py M Doc/conf.py M Doc/tools/extensions/pyspecific.py diff --git a/Doc/conf.py b/Doc/conf.py index 95e2e1774479b3..4859063edd24ea 100644 --- a/Doc/conf.py +++ b/Doc/conf.py @@ -21,6 +21,7 @@ extensions = [ 'audit_events', +'availability', 'c_annotations', 'glossary_search', 'lexers', diff --git a/Doc/tools/extensions/availability.py b/Doc/tools/extensions/availability.py new file mode 100644 index 00..897af70a9f4b40 --- /dev/null +++ b/Doc/tools/extensions/availability.py @@ -0,0 +1,123 @@ +"""Support for documenting platform availability""" + +from __future__ import annotations + +from typing import TYPE_CHECKING + +from docutils import nodes +from sphinx import addnodes +from sphinx.util import logging +from sphinx.util.docutils import SphinxDirective + +if TYPE_CHECKING: +from sphinx.application import Sphinx +from sphinx.util.typing import ExtensionMetadata + +logger = logging.getLogger("availability") + +# known platform, libc, and threading implementations +_PLATFORMS = frozenset({ +"AIX", +"Android", +"BSD", +"DragonFlyBSD", +"Emscripten", +"FreeBSD", +"Linux", +"macOS", +"NetBSD", +"OpenBSD", +"POSIX", +"Solaris", +"Unix", +"VxWorks", +"WASI", +"Windows", +}) +_LIBC = frozenset({ +"BSD libc", +"glibc", +"musl", +}) +_THREADING = frozenset({ +# POSIX platforms with pthreads +"pthreads", +}) +KNOWN_PLATFORMS = _PLATFORMS | _LIBC | _THREADING + + +class Availability(SphinxDirective): +has_content = True +required_arguments = 1 +optional_arguments = 0 +final_argument_whitespace = True + +def run(self) -> list[nodes.container]: +title = "Availability" +refnode = addnodes.pending_xref( +title, +nodes.inline(title, title, classes=["xref", "std", "std-ref"]), +refdoc=self.env.docname, +refdomain="std", +refexplicit=True, +reftarget="availability", +reftype="ref", +refwarn=True, +) +sep = nodes.Text(": ") +parsed, msgs = self.state.inline_text(self.arguments[0], self.lineno) +pnode = nodes.paragraph(title, "", refnode, sep, *parsed, *msgs) +self.set_source_info(pnode) +cnode = nodes.container("", pnode, classes=["availability"]) +self.set_source_info(cnode) +if self.content: +self.state.nested_parse(self.content, self.content_offset, cnode) +self.parse_platforms() + +return [cnode] + +def parse_platforms(self) -> dict[str, str | bool]: +"""Parse platform information from arguments + +Arguments is a comma-separated string of platforms. A platform may +be prefixed with "not " to indicate that a feature is not available. + +Example:: + + .. availability:: Windows, Linux >= 4.2, not WASI + +Arguments like "Linux >= 3.17 with glibc >= 2.27" are currently not +parsed into separate tokens. +""" +platforms = {} +for arg in self.arguments[0].rstrip(".").split(","): +arg = arg.strip() +platform, _, version = arg.partition(" >= ") +if platform.startswith("not "): +version = False +platform = platform.removeprefix("not ") +elif not version: +version = True +platforms[platform] = version + +if unknown := set(platforms).difference(KNOWN_PLATFORMS): +logger.warning( +"Unknown platform%s or syntax '%s' in '.. availability:: %s', " +"see %s:KNOWN_PLATFORMS for a set of known platforms.", +"s" if len(platforms) != 1 else "", +" ".join(sorted(unknown)), +self.arguments[0], +__file__, +) + +return platforms + + +def setup(app: Sphinx) -> ExtensionMetadata: +app.add_directive("availability", Availability) + +return { +"version": "1.0", +"parallel_read_safe": True, +"parallel_write_safe": True, +} diff --git a/Doc/tools/extensions/pyspecific.py b/Doc/tools/extensions/pyspecific.py index 96a4f24fad33b7..d3a4835edd58a4 100644 --- a/Doc/tools/extensions/pyspecific.py +++ b/Doc/tools/extensions/pyspecific.py @@ -24,7 +24,6 @@ from sphinx.domains.changeset import VersionChange, versionlabels, versionlabel_classes from
[Python-checkins] gh-125196: Add a free list to PyUnicodeWriter (#125227)
https://github.com/python/cpython/commit/1639d934b9180c278ac9c02be43cbb1beada494a
commit: 1639d934b9180c278ac9c02be43cbb1beada494a
branch: main
author: Victor Stinner
committer: vstinner
date: 2024-10-10T12:11:06+02:00
summary:
gh-125196: Add a free list to PyUnicodeWriter (#125227)
files:
M Include/internal/pycore_freelist_state.h
M Objects/object.c
M Objects/unicodeobject.c
diff --git a/Include/internal/pycore_freelist_state.h
b/Include/internal/pycore_freelist_state.h
index 762c583ce94e9a..4e04cf431e0b31 100644
--- a/Include/internal/pycore_freelist_state.h
+++ b/Include/internal/pycore_freelist_state.h
@@ -20,6 +20,7 @@ extern "C" {
# define Py_async_gen_asends_MAXFREELIST 80
# define Py_futureiters_MAXFREELIST 255
# define Py_object_stack_chunks_MAXFREELIST 4
+# define Py_unicode_writers_MAXFREELIST 1
// A generic freelist of either PyObjects or other data structures.
struct _Py_freelist {
@@ -44,6 +45,7 @@ struct _Py_freelists {
struct _Py_freelist async_gen_asends;
struct _Py_freelist futureiters;
struct _Py_freelist object_stack_chunks;
+struct _Py_freelist unicode_writers;
};
#ifdef __cplusplus
diff --git a/Objects/object.c b/Objects/object.c
index 8d809158a6c1da..a97a900890320d 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -862,6 +862,7 @@ _PyObject_ClearFreeLists(struct _Py_freelists *freelists,
int is_finalization)
// stacks during GC, so emptying the free-list is counterproductive.
clear_freelist(&freelists->object_stack_chunks, 1, PyMem_RawFree);
}
+clear_freelist(&freelists->unicode_writers, is_finalization, PyMem_Free);
}
/*
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 93c1025b6a3cae..b94a74c2c688a9 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -46,6 +46,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
#include "pycore_codecs.h"// _PyCodec_Lookup()
#include "pycore_critical_section.h" // Py_*_CRITICAL_SECTION_SEQUENCE_FAST
#include "pycore_format.h"// F_LJUST
+#include "pycore_freelist.h" // _Py_FREELIST_FREE(), _Py_FREELIST_POP()
#include "pycore_initconfig.h"// _PyStatus_OK()
#include "pycore_interp.h"// PyInterpreterState.fs_codec
#include "pycore_long.h" // _PyLong_FormatWriter()
@@ -13436,9 +13437,13 @@ PyUnicodeWriter_Create(Py_ssize_t length)
}
const size_t size = sizeof(_PyUnicodeWriter);
-PyUnicodeWriter *pub_writer = (PyUnicodeWriter *)PyMem_Malloc(size);
+PyUnicodeWriter *pub_writer;
+pub_writer = _Py_FREELIST_POP_MEM(unicode_writers);
if (pub_writer == NULL) {
-return (PyUnicodeWriter *)PyErr_NoMemory();
+pub_writer = (PyUnicodeWriter *)PyMem_Malloc(size);
+if (pub_writer == NULL) {
+return (PyUnicodeWriter *)PyErr_NoMemory();
+}
}
_PyUnicodeWriter *writer = (_PyUnicodeWriter *)pub_writer;
@@ -13459,7 +13464,7 @@ void PyUnicodeWriter_Discard(PyUnicodeWriter *writer)
return;
}
_PyUnicodeWriter_Dealloc((_PyUnicodeWriter*)writer);
-PyMem_Free(writer);
+_Py_FREELIST_FREE(unicode_writers, writer, PyMem_Free);
}
@@ -13881,7 +13886,7 @@ PyUnicodeWriter_Finish(PyUnicodeWriter *writer)
{
PyObject *str = _PyUnicodeWriter_Finish((_PyUnicodeWriter*)writer);
assert(((_PyUnicodeWriter*)writer)->buffer == NULL);
-PyMem_Free(writer);
+_Py_FREELIST_FREE(unicode_writers, writer, PyMem_Free);
return str;
}
___
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]
[Python-checkins] gh-124471: Set name for unnamed reusable workflow (#124475)
https://github.com/python/cpython/commit/e4cab488d4445e8444932f3bed1c329c0d9e5038 commit: e4cab488d4445e8444932f3bed1c329c0d9e5038 branch: main author: Donghee Na committer: AA-Turner <[email protected]> date: 2024-10-10T12:39:53Z summary: gh-124471: Set name for unnamed reusable workflow (#124475) Co-authored-by: Adam Turner <[email protected]> Co-authored-by: Sviatoslav Sydorenko (Святослав Сидоренко) files: M .github/workflows/reusable-change-detection.yml M .github/workflows/reusable-docs.yml M .github/workflows/reusable-macos.yml M .github/workflows/reusable-tsan.yml M .github/workflows/reusable-ubuntu.yml M .github/workflows/reusable-wasi.yml M .github/workflows/reusable-windows-msi.yml M .github/workflows/reusable-windows.yml diff --git a/.github/workflows/reusable-change-detection.yml b/.github/workflows/reusable-change-detection.yml index 6f599f75547ceb..5cd6fb39f1e12f 100644 --- a/.github/workflows/reusable-change-detection.yml +++ b/.github/workflows/reusable-change-detection.yml @@ -1,6 +1,4 @@ - -name: Change detection +name: Reusable change detection on: # yamllint disable-line rule:truthy workflow_call: diff --git a/.github/workflows/reusable-docs.yml b/.github/workflows/reusable-docs.yml index 7755cb431bd301..3809f24dcc977e 100644 --- a/.github/workflows/reusable-docs.yml +++ b/.github/workflows/reusable-docs.yml @@ -1,4 +1,4 @@ -name: Docs +name: Reusable Docs on: workflow_call: diff --git a/.github/workflows/reusable-macos.yml b/.github/workflows/reusable-macos.yml index b4227545887ad1..b3a160fbbf8053 100644 --- a/.github/workflows/reusable-macos.yml +++ b/.github/workflows/reusable-macos.yml @@ -1,3 +1,5 @@ +name: Reusable macOS + on: workflow_call: inputs: diff --git a/.github/workflows/reusable-tsan.yml b/.github/workflows/reusable-tsan.yml index 27f4eacd86fd95..f4c976ca996410 100644 --- a/.github/workflows/reusable-tsan.yml +++ b/.github/workflows/reusable-tsan.yml @@ -1,3 +1,5 @@ +name: Reusable Thread Sanitizer + on: workflow_call: inputs: diff --git a/.github/workflows/reusable-ubuntu.yml b/.github/workflows/reusable-ubuntu.yml index 769f1210de4d3c..0cf40ba8a9b03b 100644 --- a/.github/workflows/reusable-ubuntu.yml +++ b/.github/workflows/reusable-ubuntu.yml @@ -1,3 +1,5 @@ +name: Reusable Ubuntu + on: workflow_call: inputs: diff --git a/.github/workflows/reusable-wasi.yml b/.github/workflows/reusable-wasi.yml index 1b1a68c0badc76..4c8137c958a312 100644 --- a/.github/workflows/reusable-wasi.yml +++ b/.github/workflows/reusable-wasi.yml @@ -1,3 +1,5 @@ +name: Reusable WASI + on: workflow_call: inputs: diff --git a/.github/workflows/reusable-windows-msi.yml b/.github/workflows/reusable-windows-msi.yml index fc34ab7c3eb1f2..abdb1a1982fef8 100644 --- a/.github/workflows/reusable-windows-msi.yml +++ b/.github/workflows/reusable-windows-msi.yml @@ -1,4 +1,4 @@ -name: TestsMSI +name: Reusable Windows MSI on: workflow_call: diff --git a/.github/workflows/reusable-windows.yml b/.github/workflows/reusable-windows.yml index e9c3c8e05a801c..dcfc62d7f5d145 100644 --- a/.github/workflows/reusable-windows.yml +++ b/.github/workflows/reusable-windows.yml @@ -1,3 +1,5 @@ +name: Reusable Windows + on: workflow_call: inputs: ___ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
[Python-checkins] gh-124153: Simplify PyType_GetBaseByToken (GH-124488)
https://github.com/python/cpython/commit/120b891e4dff692aef0c2b16d887459b88a76a1b commit: 120b891e4dff692aef0c2b16d887459b88a76a1b branch: main author: neonene <[email protected]> committer: encukou date: 2024-10-10T12:57:13Z summary: gh-124153: Simplify PyType_GetBaseByToken (GH-124488) files: M Objects/typeobject.c diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 6484e8921f8122..5380633fa1149e 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -5269,11 +5269,10 @@ PyType_GetModuleByDef(PyTypeObject *type, PyModuleDef *def) static PyTypeObject * -get_base_by_token_recursive(PyTypeObject *type, void *token) +get_base_by_token_recursive(PyObject *bases, void *token) { -assert(PyType_GetSlot(type, Py_tp_token) != token); -PyObject *bases = lookup_tp_bases(type); assert(bases != NULL); +PyTypeObject *res = NULL; Py_ssize_t n = PyTuple_GET_SIZE(bases); for (Py_ssize_t i = 0; i < n; i++) { PyTypeObject *base = _PyType_CAST(PyTuple_GET_ITEM(bases, i)); @@ -5281,112 +5280,76 @@ get_base_by_token_recursive(PyTypeObject *type, void *token) continue; } if (((PyHeapTypeObject*)base)->ht_token == token) { -return base; +res = base; +break; } -base = get_base_by_token_recursive(base, token); +base = get_base_by_token_recursive(lookup_tp_bases(base), token); if (base != NULL) { -return base; +res = base; +break; } } -return NULL; +return res; // Prefer to return recursively from one place } -static inline PyTypeObject * -get_base_by_token_from_mro(PyTypeObject *type, void *token) +int +PyType_GetBaseByToken(PyTypeObject *type, void *token, PyTypeObject **result) { -// Bypass lookup_tp_mro() as PyType_IsSubtype() does -PyObject *mro = type->tp_mro; -assert(mro != NULL); -assert(PyTuple_Check(mro)); -// mro_invoke() ensures that the type MRO cannot be empty. -assert(PyTuple_GET_SIZE(mro) >= 1); -// Also, the first item in the MRO is the type itself, which is supposed -// to be already checked by the caller. We skip it in the loop. -assert(PyTuple_GET_ITEM(mro, 0) == (PyObject *)type); -assert(PyType_GetSlot(type, Py_tp_token) != token); - -Py_ssize_t n = PyTuple_GET_SIZE(mro); -for (Py_ssize_t i = 1; i < n; i++) { -PyTypeObject *base = _PyType_CAST(PyTuple_GET_ITEM(mro, i)); -if (!_PyType_HasFeature(base, Py_TPFLAGS_HEAPTYPE)) { -continue; -} -if (((PyHeapTypeObject*)base)->ht_token == token) { -return base; -} +if (result != NULL) { +*result = NULL; } -return NULL; -} -static int -check_base_by_token(PyTypeObject *type, void *token) { -// Chain the branches, which will be optimized exclusive here if (token == NULL) { PyErr_Format(PyExc_SystemError, "PyType_GetBaseByToken called with token=NULL"); return -1; } -else if (!PyType_Check(type)) { +if (!PyType_Check(type)) { PyErr_Format(PyExc_TypeError, "expected a type, got a '%T' object", type); return -1; } -else if (!_PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE)) { -return 0; -} -else if (((PyHeapTypeObject*)type)->ht_token == token) { -return 1; -} -else if (type->tp_mro != NULL) { -// This will not be inlined -return get_base_by_token_from_mro(type, token) ? 1 : 0; -} -else { -return get_base_by_token_recursive(type, token) ? 1 : 0; -} -} -int -PyType_GetBaseByToken(PyTypeObject *type, void *token, PyTypeObject **result) -{ -if (result == NULL) { -// If the `result` is checked only once here, the subsequent -// branches will become trivial to optimize. -return check_base_by_token(type, token); -} -if (token == NULL || !PyType_Check(type)) { -*result = NULL; -return check_base_by_token(type, token); -} - -// Chain the branches, which will be optimized exclusive here -PyTypeObject *base; if (!_PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE)) { // No static type has a heaptype superclass, // which is ensured by type_ready_mro(). -*result = NULL; return 0; } -else if (((PyHeapTypeObject*)type)->ht_token == token) { -*result = (PyTypeObject *)Py_NewRef(type); +if (((PyHeapTypeObject*)type)->ht_token == token) { +found: +if (result != NULL) { +*result = (PyTypeObject *)Py_NewRef(type); +} return 1; } -else if (type->tp_mro != NULL) { -// Expect this to be inlined -base = get_base_by_token_from_mro(type, token); -} -else { -base = get_base_by_token_recursive(type, token); -} -if (base != NULL) { -
[Python-checkins] [3.12] gh-124471: Set name for unnamed reusable workflow (GH-124475) (gh-125257)
https://github.com/python/cpython/commit/74df3a79d308d036e79b600b1e7850e7828e6b39 commit: 74df3a79d308d036e79b600b1e7850e7828e6b39 branch: 3.12 author: Donghee Na committer: corona10 date: 2024-10-10T13:01:41Z summary: [3.12] gh-124471: Set name for unnamed reusable workflow (GH-124475) (gh-125257) (cherry picked from commit e4cab488d4445e8444932f3bed1c329c0d9e5038) Co-authored-by: Adam Turner <[email protected]> Co-authored-by: Sviatoslav Sydorenko (Святослав Сидоренко) files: M .github/workflows/reusable-change-detection.yml M .github/workflows/reusable-docs.yml M .github/workflows/reusable-macos.yml M .github/workflows/reusable-tsan.yml M .github/workflows/reusable-ubuntu.yml M .github/workflows/reusable-windows-msi.yml M .github/workflows/reusable-windows.yml diff --git a/.github/workflows/reusable-change-detection.yml b/.github/workflows/reusable-change-detection.yml index 6f599f75547ceb..5cd6fb39f1e12f 100644 --- a/.github/workflows/reusable-change-detection.yml +++ b/.github/workflows/reusable-change-detection.yml @@ -1,6 +1,4 @@ - -name: Change detection +name: Reusable change detection on: # yamllint disable-line rule:truthy workflow_call: diff --git a/.github/workflows/reusable-docs.yml b/.github/workflows/reusable-docs.yml index 55c42ff396e05a..4d1dc04e8b638a 100644 --- a/.github/workflows/reusable-docs.yml +++ b/.github/workflows/reusable-docs.yml @@ -1,4 +1,4 @@ -name: Docs +name: Reusable Docs on: workflow_call: diff --git a/.github/workflows/reusable-macos.yml b/.github/workflows/reusable-macos.yml index 47f5ee2fb63888..6df272c8839f16 100644 --- a/.github/workflows/reusable-macos.yml +++ b/.github/workflows/reusable-macos.yml @@ -1,3 +1,5 @@ +name: Reusable macOS + on: workflow_call: inputs: diff --git a/.github/workflows/reusable-tsan.yml b/.github/workflows/reusable-tsan.yml index 96a9c1b0cda3c3..b20ba062d62d63 100644 --- a/.github/workflows/reusable-tsan.yml +++ b/.github/workflows/reusable-tsan.yml @@ -1,3 +1,5 @@ +name: Reusable Thread Sanitizer + on: workflow_call: inputs: diff --git a/.github/workflows/reusable-ubuntu.yml b/.github/workflows/reusable-ubuntu.yml index b2ac6f6127d883..a5abec11555083 100644 --- a/.github/workflows/reusable-ubuntu.yml +++ b/.github/workflows/reusable-ubuntu.yml @@ -1,3 +1,5 @@ +name: Reusable Ubuntu + on: workflow_call: inputs: diff --git a/.github/workflows/reusable-windows-msi.yml b/.github/workflows/reusable-windows-msi.yml index fc34ab7c3eb1f2..abdb1a1982fef8 100644 --- a/.github/workflows/reusable-windows-msi.yml +++ b/.github/workflows/reusable-windows-msi.yml @@ -1,4 +1,4 @@ -name: TestsMSI +name: Reusable Windows MSI on: workflow_call: diff --git a/.github/workflows/reusable-windows.yml b/.github/workflows/reusable-windows.yml index 8b886056fe56b8..9393328fa1458b 100644 --- a/.github/workflows/reusable-windows.yml +++ b/.github/workflows/reusable-windows.yml @@ -1,3 +1,5 @@ +name: Reusable Windows + on: workflow_call: inputs: ___ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
[Python-checkins] [3.13] gh-124471: Set name for unnamed reusable workflow (GH-124475) (gh-125256)
https://github.com/python/cpython/commit/0c43d60e7d0edb2fd8f996091d96ba4e8350e72a commit: 0c43d60e7d0edb2fd8f996091d96ba4e8350e72a branch: 3.13 author: Miss Islington (bot) <[email protected]> committer: corona10 date: 2024-10-10T13:03:45Z summary: [3.13] gh-124471: Set name for unnamed reusable workflow (GH-124475) (gh-125256) gh-124471: Set name for unnamed reusable workflow (GH-124475) (cherry picked from commit e4cab488d4445e8444932f3bed1c329c0d9e5038) Co-authored-by: Donghee Na Co-authored-by: Adam Turner <[email protected]> Co-authored-by: Sviatoslav Sydorenko (Святослав Сидоренко) files: M .github/workflows/reusable-change-detection.yml M .github/workflows/reusable-docs.yml M .github/workflows/reusable-macos.yml M .github/workflows/reusable-tsan.yml M .github/workflows/reusable-ubuntu.yml M .github/workflows/reusable-wasi.yml M .github/workflows/reusable-windows-msi.yml M .github/workflows/reusable-windows.yml diff --git a/.github/workflows/reusable-change-detection.yml b/.github/workflows/reusable-change-detection.yml index 6f599f75547ceb..5cd6fb39f1e12f 100644 --- a/.github/workflows/reusable-change-detection.yml +++ b/.github/workflows/reusable-change-detection.yml @@ -1,6 +1,4 @@ - -name: Change detection +name: Reusable change detection on: # yamllint disable-line rule:truthy workflow_call: diff --git a/.github/workflows/reusable-docs.yml b/.github/workflows/reusable-docs.yml index 7755cb431bd301..3809f24dcc977e 100644 --- a/.github/workflows/reusable-docs.yml +++ b/.github/workflows/reusable-docs.yml @@ -1,4 +1,4 @@ -name: Docs +name: Reusable Docs on: workflow_call: diff --git a/.github/workflows/reusable-macos.yml b/.github/workflows/reusable-macos.yml index eef6be75003e83..577d7496a42dbf 100644 --- a/.github/workflows/reusable-macos.yml +++ b/.github/workflows/reusable-macos.yml @@ -1,3 +1,5 @@ +name: Reusable macOS + on: workflow_call: inputs: diff --git a/.github/workflows/reusable-tsan.yml b/.github/workflows/reusable-tsan.yml index 27f4eacd86fd95..f4c976ca996410 100644 --- a/.github/workflows/reusable-tsan.yml +++ b/.github/workflows/reusable-tsan.yml @@ -1,3 +1,5 @@ +name: Reusable Thread Sanitizer + on: workflow_call: inputs: diff --git a/.github/workflows/reusable-ubuntu.yml b/.github/workflows/reusable-ubuntu.yml index 753d51712f55ea..eadaec9265ba47 100644 --- a/.github/workflows/reusable-ubuntu.yml +++ b/.github/workflows/reusable-ubuntu.yml @@ -1,3 +1,5 @@ +name: Reusable Ubuntu + on: workflow_call: inputs: diff --git a/.github/workflows/reusable-wasi.yml b/.github/workflows/reusable-wasi.yml index ffa143b3457e5a..051d403b9c2595 100644 --- a/.github/workflows/reusable-wasi.yml +++ b/.github/workflows/reusable-wasi.yml @@ -1,3 +1,5 @@ +name: Reusable WASI + on: workflow_call: inputs: diff --git a/.github/workflows/reusable-windows-msi.yml b/.github/workflows/reusable-windows-msi.yml index fc34ab7c3eb1f2..abdb1a1982fef8 100644 --- a/.github/workflows/reusable-windows-msi.yml +++ b/.github/workflows/reusable-windows-msi.yml @@ -1,4 +1,4 @@ -name: TestsMSI +name: Reusable Windows MSI on: workflow_call: diff --git a/.github/workflows/reusable-windows.yml b/.github/workflows/reusable-windows.yml index e9c3c8e05a801c..dcfc62d7f5d145 100644 --- a/.github/workflows/reusable-windows.yml +++ b/.github/workflows/reusable-windows.yml @@ -1,3 +1,5 @@ +name: Reusable Windows + on: workflow_call: inputs: ___ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
[Python-checkins] Add some doctest cleanups for `turtle` and `configparser` (#125288)
https://github.com/python/cpython/commit/a726ce73ca69b3a5ccc2cbe23061070e686b1150 commit: a726ce73ca69b3a5ccc2cbe23061070e686b1150 branch: main author: Alex Waygood committer: AlexWaygood date: 2024-10-10T23:53:45Z summary: Add some doctest cleanups for `turtle` and `configparser` (#125288) Co-authored-by: Adam Turner <[email protected]> files: M Doc/library/configparser.rst M Doc/library/turtle.rst diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst index b5c18bbccffb78..3aad6f7b5d2d20 100644 --- a/Doc/library/configparser.rst +++ b/Doc/library/configparser.rst @@ -54,6 +54,7 @@ can be customized by end users easily. import os os.remove("example.ini") + os.remove("override.ini") Quick Start diff --git a/Doc/library/turtle.rst b/Doc/library/turtle.rst index da801d4dc1f5b3..efa4b6f8f1d3f9 100644 --- a/Doc/library/turtle.rst +++ b/Doc/library/turtle.rst @@ -14,6 +14,11 @@ from turtle import * turtle = Turtle() +.. testcleanup:: + + import os + os.remove("my_drawing.ps") + -- Introduction ___ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
[Python-checkins] gh-124872: Rename blurb file to reference the correct issue (#125285)
https://github.com/python/cpython/commit/2f8301cbfbdd2976d254a4a772b4879069dd4298 commit: 2f8301cbfbdd2976d254a4a772b4879069dd4298 branch: main author: Richard Hansen committer: AA-Turner <[email protected]> date: 2024-10-11T03:39:17+01:00 summary: gh-124872: Rename blurb file to reference the correct issue (#125285) files: A Misc/NEWS.d/next/Documentation/2024-10-10-02-56-24.gh-issue-124872.0mDDOq.rst D Misc/NEWS.d/next/Documentation/2024-09-29-18-14-52.gh-issue-119333.7tinr0.rst diff --git a/Misc/NEWS.d/next/Documentation/2024-09-29-18-14-52.gh-issue-119333.7tinr0.rst b/Misc/NEWS.d/next/Documentation/2024-10-10-02-56-24.gh-issue-124872.0mDDOq.rst similarity index 100% rename from Misc/NEWS.d/next/Documentation/2024-09-29-18-14-52.gh-issue-119333.7tinr0.rst rename to Misc/NEWS.d/next/Documentation/2024-10-10-02-56-24.gh-issue-124872.0mDDOq.rst ___ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
[Python-checkins] gh-71784: [doc] add usage examples for traceback.TracebackException (#125189)
https://github.com/python/cpython/commit/f9ae5d1cee2f8927a71cd4f1f66f10050a4f658a commit: f9ae5d1cee2f8927a71cd4f1f66f10050a4f658a branch: main author: Irit Katriel <[email protected]> committer: AlexWaygood date: 2024-10-10T11:21:12+01:00 summary: gh-71784: [doc] add usage examples for traceback.TracebackException (#125189) Co-authored-by: Alex Waygood files: M Doc/library/traceback.rst diff --git a/Doc/library/traceback.rst b/Doc/library/traceback.rst index 401e12be45f418..100a92b73d5497 100644 --- a/Doc/library/traceback.rst +++ b/Doc/library/traceback.rst @@ -8,11 +8,15 @@ -- -This module provides a standard interface to extract, format and print stack -traces of Python programs. It exactly mimics the behavior of the Python -interpreter when it prints a stack trace. This is useful when you want to print -stack traces under program control, such as in a "wrapper" around the -interpreter. +This module provides a standard interface to extract, format and print +stack traces of Python programs. It is more flexible than the +interpreter's default traceback display, and therefore makes it +possible to configure certain aspects of the output. Finally, +it contains a utility for capturing enough information about an +exception to print it later, without the need to save a reference +to the actual exception. Since exceptions can be the roots of large +objects graph, this utility can significantly improve +memory management. .. index:: pair: object; traceback @@ -29,7 +33,20 @@ which are assigned to the :attr:`~BaseException.__traceback__` field of Module :mod:`pdb` Interactive source code debugger for Python programs. -The module defines the following functions: +The module's API can be divided into two parts: + +* Module-level functions offering basic functionality, which are useful for interactive + inspection of exceptions and tracebacks. + +* :class:`TracebackException` class and its helper classes + :class:`StackSummary` and :class:`FrameSummary`. These offer both more + flexibility in the output generated and the ability to store the information + necessary for later formatting without holding references to actual exception + and traceback objects. + + +Module-Level Functions +-- .. function:: print_tb(tb, limit=None, file=None) @@ -237,7 +254,6 @@ The module defines the following functions: .. versionadded:: 3.5 -The module also defines the following classes: :class:`!TracebackException` Objects @@ -245,12 +261,17 @@ The module also defines the following classes: .. versionadded:: 3.5 :class:`!TracebackException` objects are created from actual exceptions to -capture data for later printing in a lightweight fashion. +capture data for later printing. They offer a more lightweight method of +storing this information by avoiding holding references to +:ref:`traceback` and :ref:`frame` objects +In addition, they expose more options to configure the output compared to +the module-level functions described above. .. class:: TracebackException(exc_type, exc_value, exc_traceback, *, limit=None, lookup_lines=True, capture_locals=False, compact=False, max_group_width=15, max_group_depth=10) - Capture an exception for later rendering. *limit*, *lookup_lines* and - *capture_locals* are as for the :class:`StackSummary` class. + Capture an exception for later rendering. The meaning of *limit*, + *lookup_lines* and *capture_locals* are as for the :class:`StackSummary` + class. If *compact* is true, only data that is required by :class:`!TracebackException`'s :meth:`format` method @@ -509,8 +530,8 @@ in a :ref:`traceback `. .. _traceback-example: -Traceback Examples --- +Examples of Using the Module-Level Functions + This simple example implements a basic read-eval-print loop, similar to (but less useful than) the standard Python interactive interpreter loop. For a more @@ -549,8 +570,7 @@ exception and traceback: try: lumberjack() - except IndexError: - exc = sys.exception() + except IndexError as exc: print("*** print_tb:") traceback.print_tb(exc.__traceback__, limit=1, file=sys.stdout) print("*** print_exception:") @@ -653,5 +673,88 @@ This last example demonstrates the final few formatting functions: [' File "spam.py", line 3, in \nspam.eggs()\n', ' File "eggs.py", line 42, in eggs\nreturn "bacon"\n'] >>> an_error = IndexError('tuple index out of range') - >>> traceback.format_exception_only(type(an_error), an_error) + >>> traceback.format_exception_only(an_error) ['IndexError: tuple index out of range\n'] + + +Examples of Using :class:`TracebackException` +- + +With the helper class, we have more options:: + + >>> import sys + >>> from trac
[Python-checkins] gh-125196: Use PyUnicodeWriter for repr(tuple) (#125242)
https://github.com/python/cpython/commit/82dfdc328779778295075d791ee30a0308fb9af4
commit: 82dfdc328779778295075d791ee30a0308fb9af4
branch: main
author: Victor Stinner
committer: vstinner
date: 2024-10-10T10:20:53Z
summary:
gh-125196: Use PyUnicodeWriter for repr(tuple) (#125242)
files:
M Objects/tupleobject.c
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index 47134697918052..f3132e0933ac30 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -232,56 +232,54 @@ tuple_repr(PyObject *self)
return res > 0 ? PyUnicode_FromString("(...)") : NULL;
}
-_PyUnicodeWriter writer;
-_PyUnicodeWriter_Init(&writer);
-writer.overallocate = 1;
+Py_ssize_t prealloc;
if (n > 1) {
-/* "(" + "1" + ", 2" * (len - 1) + ")" */
-writer.min_length = 1 + 1 + (2 + 1) * (n - 1) + 1;
+// "(" + "1" + ", 2" * (len - 1) + ")"
+prealloc = 1 + 1 + (2 + 1) * (n - 1) + 1;
}
else {
-/* "(1,)" */
-writer.min_length = 4;
+// "(1,)"
+prealloc = 4;
+}
+PyUnicodeWriter *writer = PyUnicodeWriter_Create(prealloc);
+if (writer == NULL) {
+goto error;
}
-if (_PyUnicodeWriter_WriteChar(&writer, '(') < 0)
+if (PyUnicodeWriter_WriteChar(writer, '(') < 0) {
goto error;
+}
/* Do repr() on each element. */
for (Py_ssize_t i = 0; i < n; ++i) {
-PyObject *s;
-
if (i > 0) {
-if (_PyUnicodeWriter_WriteASCIIString(&writer, ", ", 2) < 0)
+if (PyUnicodeWriter_WriteChar(writer, ',') < 0) {
goto error;
+}
+if (PyUnicodeWriter_WriteChar(writer, ' ') < 0) {
+goto error;
+}
}
-s = PyObject_Repr(v->ob_item[i]);
-if (s == NULL)
-goto error;
-
-if (_PyUnicodeWriter_WriteStr(&writer, s) < 0) {
-Py_DECREF(s);
+if (PyUnicodeWriter_WriteRepr(writer, v->ob_item[i]) < 0) {
goto error;
}
-Py_DECREF(s);
}
-writer.overallocate = 0;
-if (n > 1) {
-if (_PyUnicodeWriter_WriteChar(&writer, ')') < 0)
+if (n == 1) {
+if (PyUnicodeWriter_WriteChar(writer, ',') < 0) {
goto error;
+}
}
-else {
-if (_PyUnicodeWriter_WriteASCIIString(&writer, ",)", 2) < 0)
-goto error;
+if (PyUnicodeWriter_WriteChar(writer, ')') < 0) {
+goto error;
}
Py_ReprLeave((PyObject *)v);
-return _PyUnicodeWriter_Finish(&writer);
+return PyUnicodeWriter_Finish(writer);
error:
-_PyUnicodeWriter_Dealloc(&writer);
+PyUnicodeWriter_Discard(writer);
Py_ReprLeave((PyObject *)v);
return NULL;
}
___
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]
[Python-checkins] [3.13] Pin the doctest workflow to Ubuntu 22.04 (GH-125236) (#125240)
https://github.com/python/cpython/commit/288a0692edc50dd7cf66a6b23899a61144ed94ef commit: 288a0692edc50dd7cf66a6b23899a61144ed94ef branch: 3.13 author: Miss Islington (bot) <[email protected]> committer: AA-Turner <[email protected]> date: 2024-10-10T10:27:48Z summary: [3.13] Pin the doctest workflow to Ubuntu 22.04 (GH-125236) (#125240) Co-authored-by: Adam Turner <[email protected]> files: M .github/workflows/build.yml M .github/workflows/reusable-docs.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4462bfa54a16cf..89bf7b1ea585c6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,7 +42,7 @@ jobs: check_abi: name: 'Check if the ABI has changed' -runs-on: ubuntu-latest +runs-on: ubuntu-22.04 needs: check_source if: needs.check_source.outputs.run_tests == 'true' steps: diff --git a/.github/workflows/reusable-docs.yml b/.github/workflows/reusable-docs.yml index 4b021b3dc32f15..7755cb431bd301 100644 --- a/.github/workflows/reusable-docs.yml +++ b/.github/workflows/reusable-docs.yml @@ -95,7 +95,7 @@ jobs: # Run "doctest" on HEAD as new syntax doesn't exist in the latest stable release doctest: name: 'Doctest' -runs-on: ubuntu-latest +runs-on: ubuntu-22.04 timeout-minutes: 60 steps: - uses: actions/checkout@v4 ___ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
[Python-checkins] [3.12] gh-71784: [doc] add usage examples for traceback.TracebackException (GH-125189) (#125248)
https://github.com/python/cpython/commit/01daccff3c2c7b389a2c2ef5a7f80f1b733f5881 commit: 01daccff3c2c7b389a2c2ef5a7f80f1b733f5881 branch: 3.12 author: Miss Islington (bot) <[email protected]> committer: AlexWaygood date: 2024-10-10T10:37:14Z summary: [3.12] gh-71784: [doc] add usage examples for traceback.TracebackException (GH-125189) (#125248) Co-authored-by: Irit Katriel <[email protected]> Co-authored-by: Alex Waygood files: M Doc/library/traceback.rst diff --git a/Doc/library/traceback.rst b/Doc/library/traceback.rst index d3f47b9e4fb596..9d57c354523370 100644 --- a/Doc/library/traceback.rst +++ b/Doc/library/traceback.rst @@ -8,11 +8,15 @@ -- -This module provides a standard interface to extract, format and print stack -traces of Python programs. It exactly mimics the behavior of the Python -interpreter when it prints a stack trace. This is useful when you want to print -stack traces under program control, such as in a "wrapper" around the -interpreter. +This module provides a standard interface to extract, format and print +stack traces of Python programs. It is more flexible than the +interpreter's default traceback display, and therefore makes it +possible to configure certain aspects of the output. Finally, +it contains a utility for capturing enough information about an +exception to print it later, without the need to save a reference +to the actual exception. Since exceptions can be the roots of large +objects graph, this utility can significantly improve +memory management. .. index:: pair: object; traceback @@ -29,7 +33,20 @@ which are assigned to the :attr:`~BaseException.__traceback__` field of Module :mod:`pdb` Interactive source code debugger for Python programs. -The module defines the following functions: +The module's API can be divided into two parts: + +* Module-level functions offering basic functionality, which are useful for interactive + inspection of exceptions and tracebacks. + +* :class:`TracebackException` class and its helper classes + :class:`StackSummary` and :class:`FrameSummary`. These offer both more + flexibility in the output generated and the ability to store the information + necessary for later formatting without holding references to actual exception + and traceback objects. + + +Module-Level Functions +-- .. function:: print_tb(tb, limit=None, file=None) @@ -230,7 +247,6 @@ The module defines the following functions: .. versionadded:: 3.5 -The module also defines the following classes: :class:`!TracebackException` Objects @@ -238,12 +254,17 @@ The module also defines the following classes: .. versionadded:: 3.5 :class:`!TracebackException` objects are created from actual exceptions to -capture data for later printing in a lightweight fashion. +capture data for later printing. They offer a more lightweight method of +storing this information by avoiding holding references to +:ref:`traceback` and :ref:`frame` objects +In addition, they expose more options to configure the output compared to +the module-level functions described above. .. class:: TracebackException(exc_type, exc_value, exc_traceback, *, limit=None, lookup_lines=True, capture_locals=False, compact=False, max_group_width=15, max_group_depth=10) - Capture an exception for later rendering. *limit*, *lookup_lines* and - *capture_locals* are as for the :class:`StackSummary` class. + Capture an exception for later rendering. The meaning of *limit*, + *lookup_lines* and *capture_locals* are as for the :class:`StackSummary` + class. If *compact* is true, only data that is required by :class:`!TracebackException`'s :meth:`format` method @@ -488,8 +509,8 @@ in a :ref:`traceback `. .. _traceback-example: -Traceback Examples --- +Examples of Using the Module-Level Functions + This simple example implements a basic read-eval-print loop, similar to (but less useful than) the standard Python interactive interpreter loop. For a more @@ -528,8 +549,7 @@ exception and traceback: try: lumberjack() - except IndexError: - exc = sys.exception() + except IndexError as exc: print("*** print_tb:") traceback.print_tb(exc.__traceback__, limit=1, file=sys.stdout) print("*** print_exception:") @@ -627,5 +647,88 @@ This last example demonstrates the final few formatting functions: [' File "spam.py", line 3, in \nspam.eggs()\n', ' File "eggs.py", line 42, in eggs\nreturn "bacon"\n'] >>> an_error = IndexError('tuple index out of range') - >>> traceback.format_exception_only(type(an_error), an_error) + >>> traceback.format_exception_only(an_error) ['IndexError: tuple index out of range\n'] + + +Examples of Using :class:`TracebackException` +--
[Python-checkins] [3.12] Pin the doctest workflow to Ubuntu 22.04 (GH-125236) (#125241)
https://github.com/python/cpython/commit/01d9a899978626615d172aa5d832aaf0e4500bc7 commit: 01d9a899978626615d172aa5d832aaf0e4500bc7 branch: 3.12 author: Miss Islington (bot) <[email protected]> committer: AA-Turner <[email protected]> date: 2024-10-10T09:52:54Z summary: [3.12] Pin the doctest workflow to Ubuntu 22.04 (GH-125236) (#125241) Pin the doctest workflow to Ubuntu 22.04 (GH-125236) (cherry picked from commit 7a10cdec359750b5154490fa9e24475c90d05aab) Co-authored-by: Adam Turner <[email protected]> files: M .github/workflows/reusable-docs.yml diff --git a/.github/workflows/reusable-docs.yml b/.github/workflows/reusable-docs.yml index 4b384f4b3fa602..55c42ff396e05a 100644 --- a/.github/workflows/reusable-docs.yml +++ b/.github/workflows/reusable-docs.yml @@ -92,7 +92,7 @@ jobs: # Run "doctest" on HEAD as new syntax doesn't exist in the latest stable release doctest: name: 'Doctest' -runs-on: ubuntu-latest +runs-on: ubuntu-22.04 timeout-minutes: 60 steps: - uses: actions/checkout@v4 ___ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
[Python-checkins] Pin the doctest workflow to Ubuntu 22.04 (#125236)
https://github.com/python/cpython/commit/7a10cdec359750b5154490fa9e24475c90d05aab commit: 7a10cdec359750b5154490fa9e24475c90d05aab branch: main author: Adam Turner <[email protected]> committer: AA-Turner <[email protected]> date: 2024-10-10T10:34:55+01:00 summary: Pin the doctest workflow to Ubuntu 22.04 (#125236) files: M .github/workflows/reusable-docs.yml diff --git a/.github/workflows/reusable-docs.yml b/.github/workflows/reusable-docs.yml index 4b021b3dc32f15..7755cb431bd301 100644 --- a/.github/workflows/reusable-docs.yml +++ b/.github/workflows/reusable-docs.yml @@ -95,7 +95,7 @@ jobs: # Run "doctest" on HEAD as new syntax doesn't exist in the latest stable release doctest: name: 'Doctest' -runs-on: ubuntu-latest +runs-on: ubuntu-22.04 timeout-minutes: 60 steps: - uses: actions/checkout@v4 ___ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
[Python-checkins] [3.13] gh-125140: Remove the current directory from sys.path when using pyrepl (GH-125212) (#125224)
https://github.com/python/cpython/commit/85cf3a9dbe752a04d502f1af815063e6c429e402 commit: 85cf3a9dbe752a04d502f1af815063e6c429e402 branch: 3.13 author: Miss Islington (bot) <[email protected]> committer: pablogsal date: 2024-10-10T10:35:47+01:00 summary: [3.13] gh-125140: Remove the current directory from sys.path when using pyrepl (GH-125212) (#125224) files: A Misc/NEWS.d/next/Security/2024-10-09-20-08-13.gh-issue-125140.YgNWRB.rst M Lib/site.py diff --git a/Lib/site.py b/Lib/site.py index d31bc772334151..34e7d19f376cc6 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -503,9 +503,14 @@ def register_readline(): if PYTHON_BASIC_REPL: CAN_USE_PYREPL = False else: -import _pyrepl.readline -import _pyrepl.unix_console -from _pyrepl.main import CAN_USE_PYREPL +original_path = sys.path +sys.path = [p for p in original_path if p != ''] +try: +import _pyrepl.readline +import _pyrepl.unix_console +from _pyrepl.main import CAN_USE_PYREPL +finally: +sys.path = original_path except ImportError: return diff --git a/Misc/NEWS.d/next/Security/2024-10-09-20-08-13.gh-issue-125140.YgNWRB.rst b/Misc/NEWS.d/next/Security/2024-10-09-20-08-13.gh-issue-125140.YgNWRB.rst new file mode 100644 index 00..f4a49302372647 --- /dev/null +++ b/Misc/NEWS.d/next/Security/2024-10-09-20-08-13.gh-issue-125140.YgNWRB.rst @@ -0,0 +1 @@ +Remove the current directory from ``sys.path`` when using PyREPL. ___ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
[Python-checkins] [3.13] gh-71784: [doc] add usage examples for traceback.TracebackException (GH-125189) (#125247)
https://github.com/python/cpython/commit/47ad32d158e1df2f89b6ec0ed1e8bb09937e04d1 commit: 47ad32d158e1df2f89b6ec0ed1e8bb09937e04d1 branch: 3.13 author: Miss Islington (bot) <[email protected]> committer: AlexWaygood date: 2024-10-10T10:46:31Z summary: [3.13] gh-71784: [doc] add usage examples for traceback.TracebackException (GH-125189) (#125247) Co-authored-by: Irit Katriel <[email protected]> Co-authored-by: Alex Waygood files: M Doc/library/traceback.rst diff --git a/Doc/library/traceback.rst b/Doc/library/traceback.rst index 401e12be45f418..100a92b73d5497 100644 --- a/Doc/library/traceback.rst +++ b/Doc/library/traceback.rst @@ -8,11 +8,15 @@ -- -This module provides a standard interface to extract, format and print stack -traces of Python programs. It exactly mimics the behavior of the Python -interpreter when it prints a stack trace. This is useful when you want to print -stack traces under program control, such as in a "wrapper" around the -interpreter. +This module provides a standard interface to extract, format and print +stack traces of Python programs. It is more flexible than the +interpreter's default traceback display, and therefore makes it +possible to configure certain aspects of the output. Finally, +it contains a utility for capturing enough information about an +exception to print it later, without the need to save a reference +to the actual exception. Since exceptions can be the roots of large +objects graph, this utility can significantly improve +memory management. .. index:: pair: object; traceback @@ -29,7 +33,20 @@ which are assigned to the :attr:`~BaseException.__traceback__` field of Module :mod:`pdb` Interactive source code debugger for Python programs. -The module defines the following functions: +The module's API can be divided into two parts: + +* Module-level functions offering basic functionality, which are useful for interactive + inspection of exceptions and tracebacks. + +* :class:`TracebackException` class and its helper classes + :class:`StackSummary` and :class:`FrameSummary`. These offer both more + flexibility in the output generated and the ability to store the information + necessary for later formatting without holding references to actual exception + and traceback objects. + + +Module-Level Functions +-- .. function:: print_tb(tb, limit=None, file=None) @@ -237,7 +254,6 @@ The module defines the following functions: .. versionadded:: 3.5 -The module also defines the following classes: :class:`!TracebackException` Objects @@ -245,12 +261,17 @@ The module also defines the following classes: .. versionadded:: 3.5 :class:`!TracebackException` objects are created from actual exceptions to -capture data for later printing in a lightweight fashion. +capture data for later printing. They offer a more lightweight method of +storing this information by avoiding holding references to +:ref:`traceback` and :ref:`frame` objects +In addition, they expose more options to configure the output compared to +the module-level functions described above. .. class:: TracebackException(exc_type, exc_value, exc_traceback, *, limit=None, lookup_lines=True, capture_locals=False, compact=False, max_group_width=15, max_group_depth=10) - Capture an exception for later rendering. *limit*, *lookup_lines* and - *capture_locals* are as for the :class:`StackSummary` class. + Capture an exception for later rendering. The meaning of *limit*, + *lookup_lines* and *capture_locals* are as for the :class:`StackSummary` + class. If *compact* is true, only data that is required by :class:`!TracebackException`'s :meth:`format` method @@ -509,8 +530,8 @@ in a :ref:`traceback `. .. _traceback-example: -Traceback Examples --- +Examples of Using the Module-Level Functions + This simple example implements a basic read-eval-print loop, similar to (but less useful than) the standard Python interactive interpreter loop. For a more @@ -549,8 +570,7 @@ exception and traceback: try: lumberjack() - except IndexError: - exc = sys.exception() + except IndexError as exc: print("*** print_tb:") traceback.print_tb(exc.__traceback__, limit=1, file=sys.stdout) print("*** print_exception:") @@ -653,5 +673,88 @@ This last example demonstrates the final few formatting functions: [' File "spam.py", line 3, in \nspam.eggs()\n', ' File "eggs.py", line 42, in eggs\nreturn "bacon"\n'] >>> an_error = IndexError('tuple index out of range') - >>> traceback.format_exception_only(type(an_error), an_error) + >>> traceback.format_exception_only(an_error) ['IndexError: tuple index out of range\n'] + + +Examples of Using :class:`TracebackException` +--
[Python-checkins] [3.13] GH-121970: Extract ``availability`` into a new extension (GH-125082) (#125237)
https://github.com/python/cpython/commit/abb01fd9381ebac5cc441b5712a2fd223413d2c4 commit: abb01fd9381ebac5cc441b5712a2fd223413d2c4 branch: 3.13 author: Adam Turner <[email protected]> committer: AA-Turner <[email protected]> date: 2024-10-10T10:43:43Z summary: [3.13] GH-121970: Extract ``availability`` into a new extension (GH-125082) (#125237) (cherry picked from commit cbfd39247983309a9ef0ae6da6c61cc71665b967) files: A Doc/tools/extensions/availability.py M Doc/conf.py M Doc/tools/extensions/pyspecific.py diff --git a/Doc/conf.py b/Doc/conf.py index 5f22340ac434c9..287e0da46eb11c 100644 --- a/Doc/conf.py +++ b/Doc/conf.py @@ -21,6 +21,7 @@ extensions = [ 'audit_events', +'availability', 'c_annotations', 'glossary_search', 'lexers', diff --git a/Doc/tools/extensions/availability.py b/Doc/tools/extensions/availability.py new file mode 100644 index 00..47833fdcb87590 --- /dev/null +++ b/Doc/tools/extensions/availability.py @@ -0,0 +1,125 @@ +"""Support for documenting platform availability""" + +from __future__ import annotations + +from typing import TYPE_CHECKING + +from docutils import nodes +from sphinx import addnodes +from sphinx.util import logging +from sphinx.util.docutils import SphinxDirective + +if TYPE_CHECKING: +from sphinx.application import Sphinx +from sphinx.util.typing import ExtensionMetadata + +logger = logging.getLogger("availability") + +# known platform, libc, and threading implementations +_PLATFORMS = frozenset({ +"AIX", +"Android", +"BSD", +"DragonFlyBSD", +"Emscripten", +"FreeBSD", +"GNU/kFreeBSD", +"iOS", +"Linux", +"macOS", +"NetBSD", +"OpenBSD", +"POSIX", +"Solaris", +"Unix", +"VxWorks", +"WASI", +"Windows", +}) +_LIBC = frozenset({ +"BSD libc", +"glibc", +"musl", +}) +_THREADING = frozenset({ +# POSIX platforms with pthreads +"pthreads", +}) +KNOWN_PLATFORMS = _PLATFORMS | _LIBC | _THREADING + + +class Availability(SphinxDirective): +has_content = True +required_arguments = 1 +optional_arguments = 0 +final_argument_whitespace = True + +def run(self) -> list[nodes.container]: +title = "Availability" +refnode = addnodes.pending_xref( +title, +nodes.inline(title, title, classes=["xref", "std", "std-ref"]), +refdoc=self.env.docname, +refdomain="std", +refexplicit=True, +reftarget="availability", +reftype="ref", +refwarn=True, +) +sep = nodes.Text(": ") +parsed, msgs = self.state.inline_text(self.arguments[0], self.lineno) +pnode = nodes.paragraph(title, "", refnode, sep, *parsed, *msgs) +self.set_source_info(pnode) +cnode = nodes.container("", pnode, classes=["availability"]) +self.set_source_info(cnode) +if self.content: +self.state.nested_parse(self.content, self.content_offset, cnode) +self.parse_platforms() + +return [cnode] + +def parse_platforms(self) -> dict[str, str | bool]: +"""Parse platform information from arguments + +Arguments is a comma-separated string of platforms. A platform may +be prefixed with "not " to indicate that a feature is not available. + +Example:: + + .. availability:: Windows, Linux >= 4.2, not WASI + +Arguments like "Linux >= 3.17 with glibc >= 2.27" are currently not +parsed into separate tokens. +""" +platforms = {} +for arg in self.arguments[0].rstrip(".").split(","): +arg = arg.strip() +platform, _, version = arg.partition(" >= ") +if platform.startswith("not "): +version = False +platform = platform.removeprefix("not ") +elif not version: +version = True +platforms[platform] = version + +if unknown := set(platforms).difference(KNOWN_PLATFORMS): +logger.warning( +"Unknown platform%s or syntax '%s' in '.. availability:: %s', " +"see %s:KNOWN_PLATFORMS for a set of known platforms.", +"s" if len(platforms) != 1 else "", +" ".join(sorted(unknown)), +self.arguments[0], +__file__, +) + +return platforms + + +def setup(app: Sphinx) -> ExtensionMetadata: +app.add_directive("availability", Availability) + +return { +"version": "1.0", +"parallel_read_safe": True, +"parallel_write_safe": True, +} diff --git a/Doc/tools/extensions/pyspecific.py b/Doc/tools/extensions/pyspecific.py index 5d27c8ff574036..ec46c148a585d1 100644 --- a/Doc/tools/extensions/pyspecific.py +++ b/Doc/tools/extensions/pyspecific.py @@ -24,7 +24,6 @@ from sphinx.domains.changeset import VersionChange, versionla
[Python-checkins] GH-125174: Make immortal objects more robust, following design from PEP 683 (GH-125251)
https://github.com/python/cpython/commit/c9014374c50d6ef64786d3e7d9c7e99053d5c9e2
commit: c9014374c50d6ef64786d3e7d9c7e99053d5c9e2
branch: main
author: Mark Shannon
committer: markshannon
date: 2024-10-10T18:19:08+01:00
summary:
GH-125174: Make immortal objects more robust, following design from PEP 683
(GH-125251)
files:
A
Misc/NEWS.d/next/Core_and_Builtins/2024-10-10-12-04-56.gh-issue-125174._8h6T7.rst
M Include/internal/pycore_global_objects_fini_generated.h
M Include/internal/pycore_object.h
M Include/object.h
M Include/refcount.h
M Lib/test/test_builtin.py
M Modules/_asynciomodule.c
M Objects/bytesobject.c
M Objects/dictobject.c
M Objects/object.c
M Objects/structseq.c
M Objects/typeobject.c
M Python/bytecodes.c
M Python/executor_cases.c.h
M Python/generated_cases.c.h
M Python/import.c
M Tools/cases_generator/analyzer.py
diff --git a/Include/internal/pycore_global_objects_fini_generated.h
b/Include/internal/pycore_global_objects_fini_generated.h
index 3140a75a47c5ee..de68ef93257234 100644
--- a/Include/internal/pycore_global_objects_fini_generated.h
+++ b/Include/internal/pycore_global_objects_fini_generated.h
@@ -11,7 +11,7 @@ extern "C" {
#ifdef Py_DEBUG
static inline void
_PyStaticObject_CheckRefcnt(PyObject *obj) {
-if (Py_REFCNT(obj) < _Py_IMMORTAL_REFCNT) {
+if (!_Py_IsImmortal(obj)) {
fprintf(stderr, "Immortal Object has less refcnt than expected.\n");
_PyObject_Dump(obj);
}
diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h
index 0af13b1bcda20b..8832692d03c29e 100644
--- a/Include/internal/pycore_object.h
+++ b/Include/internal/pycore_object.h
@@ -16,9 +16,6 @@ extern "C" {
#include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_uniqueid.h" // _PyType_IncrefSlow
-
-#define _Py_IMMORTAL_REFCNT_LOOSE ((_Py_IMMORTAL_REFCNT >> 1) + 1)
-
// This value is added to `ob_ref_shared` for objects that use deferred
// reference counting so that they are not immediately deallocated when the
// non-deferred reference count drops to zero.
@@ -27,25 +24,8 @@ extern "C" {
// `ob_ref_shared` are used for flags.
#define _Py_REF_DEFERRED (PY_SSIZE_T_MAX / 8)
-// gh-121528, gh-118997: Similar to _Py_IsImmortal() but be more loose when
-// comparing the reference count to stay compatible with C extensions built
-// with the stable ABI 3.11 or older. Such extensions implement INCREF/DECREF
-// as refcnt++ and refcnt-- without taking in account immortal objects. For
-// example, the reference count of an immortal object can change from
-// _Py_IMMORTAL_REFCNT to _Py_IMMORTAL_REFCNT+1 (INCREF) or
-// _Py_IMMORTAL_REFCNT-1 (DECREF).
-//
-// This function should only be used in assertions. Otherwise, _Py_IsImmortal()
-// must be used instead.
-static inline int _Py_IsImmortalLoose(PyObject *op)
-{
-#if defined(Py_GIL_DISABLED)
-return _Py_IsImmortal(op);
-#else
-return (op->ob_refcnt >= _Py_IMMORTAL_REFCNT_LOOSE);
-#endif
-}
-#define _Py_IsImmortalLoose(op) _Py_IsImmortalLoose(_PyObject_CAST(op))
+/* For backwards compatibility -- Do not use this */
+#define _Py_IsImmortalLoose(op) _Py_IsImmortal
/* Check if an object is consistent. For example, ensure that the reference
@@ -97,7 +77,7 @@ PyAPI_FUNC(int) _PyObject_IsFreed(PyObject *);
#else
#define _PyObject_HEAD_INIT(type) \
{ \
-.ob_refcnt = _Py_IMMORTAL_REFCNT, \
+.ob_refcnt = _Py_IMMORTAL_INITIAL_REFCNT, \
.ob_type = (type) \
}
#endif
@@ -184,7 +164,7 @@ PyAPI_FUNC(void) _Py_SetImmortalUntracked(PyObject *op);
static inline void _Py_SetMortal(PyObject *op, Py_ssize_t refcnt)
{
if (op) {
-assert(_Py_IsImmortalLoose(op));
+assert(_Py_IsImmortal(op));
#ifdef Py_GIL_DISABLED
op->ob_tid = _Py_UNOWNED_TID;
op->ob_ref_local = 0;
@@ -316,7 +296,7 @@ static inline void
_Py_INCREF_TYPE(PyTypeObject *type)
{
if (!_PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE)) {
-assert(_Py_IsImmortalLoose(type));
+assert(_Py_IsImmortal(type));
_Py_INCREF_IMMORTAL_STAT_INC();
return;
}
@@ -357,7 +337,7 @@ static inline void
_Py_DECREF_TYPE(PyTypeObject *type)
{
if (!_PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE)) {
-assert(_Py_IsImmortalLoose(type));
+assert(_Py_IsImmortal(type));
_Py_DECREF_IMMORTAL_STAT_INC();
return;
}
@@ -393,7 +373,7 @@ _PyObject_Init(PyObject *op, PyTypeObject *typeobj)
{
assert(op != NULL);
Py_SET_TYPE(op, typeobj);
-assert(_PyType_HasFeature(typeobj, Py_TPFLAGS_HEAPTYPE) ||
_Py_IsImmortalLoose(typeobj));
+assert(_PyType_HasFeature(typeobj, Py_TPFLAGS_HEAPTYPE) ||
_Py_IsImmortal(typeobj));
_Py_INCREF_TYPE(typeobj);
_Py_NewReference(op);
}
diff --git a/Include/object.h b/Include/object.h
index 418f2196062df7..5be4dedadc20eb 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -81,7 +81,7
[Python-checkins] [3.13] gh-122765: make prompt in activate.csh robust against unbalanced quotes and newlines (GH-123751) (GH-124185)
https://github.com/python/cpython/commit/9aa85f524fd276becc2a4265a9b0c00b4e7b3440 commit: 9aa85f524fd276becc2a4265a9b0c00b4e7b3440 branch: 3.13 author: Miss Islington (bot) <[email protected]> committer: brettcannon date: 2024-10-10T17:39:39Z summary: [3.13] gh-122765: make prompt in activate.csh robust against unbalanced quotes and newlines (GH-123751) (GH-124185) gh-122765: make prompt in activate.csh robust against unbalanced quotes and newlines (GH-123751) (cherry picked from commit a15a584bf3f94ea11ab9363548c8872251364000) Co-authored-by: Jacek Co-authored-by: Brett Cannon files: A Misc/NEWS.d/next/Library/2024-09-06-00-00-43.gh-issue-122765.tx4hsr.rst M Lib/venv/scripts/posix/activate.csh diff --git a/Lib/venv/scripts/posix/activate.csh b/Lib/venv/scripts/posix/activate.csh index c707f1988b0acc..b5db4a0f847e06 100644 --- a/Lib/venv/scripts/posix/activate.csh +++ b/Lib/venv/scripts/posix/activate.csh @@ -19,7 +19,7 @@ setenv VIRTUAL_ENV_PROMPT "__VENV_PROMPT__" set _OLD_VIRTUAL_PROMPT="$prompt" if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then -set prompt = "(__VENV_PROMPT__) $prompt" +set prompt = "(__VENV_PROMPT__) $prompt:q" endif alias pydoc python -m pydoc diff --git a/Misc/NEWS.d/next/Library/2024-09-06-00-00-43.gh-issue-122765.tx4hsr.rst b/Misc/NEWS.d/next/Library/2024-09-06-00-00-43.gh-issue-122765.tx4hsr.rst new file mode 100644 index 00..8a1bc4bce81d76 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-09-06-00-00-43.gh-issue-122765.tx4hsr.rst @@ -0,0 +1 @@ +Fix unbalanced quote errors occurring when activate.csh in :mod:`venv` was sourced with a custom prompt containing unpaired quotes or newlines. ___ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
[Python-checkins] Note argparse exit code in documentation (GH-119568)
https://github.com/python/cpython/commit/3b87fb74c907510402678bf1b7c4a94df0e5e65a commit: 3b87fb74c907510402678bf1b7c4a94df0e5e65a branch: main author: Justin Kunimune committer: serhiy-storchaka date: 2024-10-10T20:56:05+03:00 summary: Note argparse exit code in documentation (GH-119568) Co-authored-by: Savannah Ostrowski files: M Doc/library/argparse.rst diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index e9a08984f77c3a..4eb6fad41f11ef 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -541,7 +541,8 @@ exit_on_error ^ Normally, when you pass an invalid argument list to the :meth:`~ArgumentParser.parse_args` -method of an :class:`ArgumentParser`, it will exit with error info. +method of an :class:`ArgumentParser`, it will print a *message* to :data:`sys.stderr` and exit with a status +code of 2. If the user would like to catch errors manually, the feature can be enabled by setting ``exit_on_error`` to ``False``:: ___ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
[Python-checkins] [3.12] Note argparse exit code in documentation (GH-119568) (GH-125275)
https://github.com/python/cpython/commit/eb320f5ac846faa9ad81fc0c07553cf5b181652d commit: eb320f5ac846faa9ad81fc0c07553cf5b181652d branch: 3.12 author: Miss Islington (bot) <[email protected]> committer: serhiy-storchaka date: 2024-10-10T21:18:01+03:00 summary: [3.12] Note argparse exit code in documentation (GH-119568) (GH-125275) (cherry picked from commit 3b87fb74c907510402678bf1b7c4a94df0e5e65a) Co-authored-by: Justin Kunimune Co-authored-by: Savannah Ostrowski files: M Doc/library/argparse.rst diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index abe20d7d611695..6d8b207cbc03ab 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -537,7 +537,8 @@ exit_on_error ^ Normally, when you pass an invalid argument list to the :meth:`~ArgumentParser.parse_args` -method of an :class:`ArgumentParser`, it will exit with error info. +method of an :class:`ArgumentParser`, it will print a *message* to :data:`sys.stderr` and exit with a status +code of 2. If the user would like to catch errors manually, the feature can be enabled by setting ``exit_on_error`` to ``False``:: ___ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
[Python-checkins] gh-125196: Use PyUnicodeWriter for repr(dict) (#125270)
https://github.com/python/cpython/commit/bb594e801b6a84823badbb85b88f0fc8b221d7bf
commit: bb594e801b6a84823badbb85b88f0fc8b221d7bf
branch: main
author: Victor Stinner
committer: vstinner
date: 2024-10-10T20:41:14+02:00
summary:
gh-125196: Use PyUnicodeWriter for repr(dict) (#125270)
files:
M Objects/dictobject.c
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 12722eca6be5e5..b27599d2815c82 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -3200,16 +3200,12 @@ static PyObject *
dict_repr_lock_held(PyObject *self)
{
PyDictObject *mp = (PyDictObject *)self;
-Py_ssize_t i;
PyObject *key = NULL, *value = NULL;
-_PyUnicodeWriter writer;
-int first;
-
ASSERT_DICT_LOCKED(mp);
-i = Py_ReprEnter((PyObject *)mp);
-if (i != 0) {
-return i > 0 ? PyUnicode_FromString("{...}") : NULL;
+int res = Py_ReprEnter((PyObject *)mp);
+if (res != 0) {
+return (res > 0 ? PyUnicode_FromString("{...}") : NULL);
}
if (mp->ma_used == 0) {
@@ -3217,66 +3213,70 @@ dict_repr_lock_held(PyObject *self)
return PyUnicode_FromString("{}");
}
-_PyUnicodeWriter_Init(&writer);
-writer.overallocate = 1;
-/* "{" + "1: 2" + ", 3: 4" * (len - 1) + "}" */
-writer.min_length = 1 + 4 + (2 + 4) * (mp->ma_used - 1) + 1;
+// "{" + "1: 2" + ", 3: 4" * (len - 1) + "}"
+Py_ssize_t prealloc = 1 + 4 + 6 * (mp->ma_used - 1) + 1;
+PyUnicodeWriter *writer = PyUnicodeWriter_Create(prealloc);
+if (writer == NULL) {
+goto error;
+}
-if (_PyUnicodeWriter_WriteChar(&writer, '{') < 0)
+if (PyUnicodeWriter_WriteChar(writer, '{') < 0) {
goto error;
+}
/* Do repr() on each key+value pair, and insert ": " between them.
Note that repr may mutate the dict. */
-i = 0;
-first = 1;
+Py_ssize_t i = 0;
+int first = 1;
while (_PyDict_Next((PyObject *)mp, &i, &key, &value, NULL)) {
-PyObject *s;
-int res;
-
-/* Prevent repr from deleting key or value during key format. */
+// Prevent repr from deleting key or value during key format.
Py_INCREF(key);
Py_INCREF(value);
if (!first) {
-if (_PyUnicodeWriter_WriteASCIIString(&writer, ", ", 2) < 0)
+// Write ", "
+if (PyUnicodeWriter_WriteChar(writer, ',') < 0) {
+goto error;
+}
+if (PyUnicodeWriter_WriteChar(writer, ' ') < 0) {
goto error;
+}
}
first = 0;
-s = PyObject_Repr(key);
-if (s == NULL)
-goto error;
-res = _PyUnicodeWriter_WriteStr(&writer, s);
-Py_DECREF(s);
-if (res < 0)
+// Write repr(key)
+if (PyUnicodeWriter_WriteRepr(writer, key) < 0) {
goto error;
+}
-if (_PyUnicodeWriter_WriteASCIIString(&writer, ": ", 2) < 0)
+// Write ": "
+if (PyUnicodeWriter_WriteChar(writer, ':') < 0) {
goto error;
-
-s = PyObject_Repr(value);
-if (s == NULL)
+}
+if (PyUnicodeWriter_WriteChar(writer, ' ') < 0) {
goto error;
-res = _PyUnicodeWriter_WriteStr(&writer, s);
-Py_DECREF(s);
-if (res < 0)
+}
+
+// Write repr(value)
+if (PyUnicodeWriter_WriteRepr(writer, value) < 0) {
goto error;
+}
Py_CLEAR(key);
Py_CLEAR(value);
}
-writer.overallocate = 0;
-if (_PyUnicodeWriter_WriteChar(&writer, '}') < 0)
+if (PyUnicodeWriter_WriteChar(writer, '}') < 0) {
goto error;
+}
Py_ReprLeave((PyObject *)mp);
-return _PyUnicodeWriter_Finish(&writer);
+return PyUnicodeWriter_Finish(writer);
error:
Py_ReprLeave((PyObject *)mp);
-_PyUnicodeWriter_Dealloc(&writer);
+PyUnicodeWriter_Discard(writer);
Py_XDECREF(key);
Py_XDECREF(value);
return NULL;
___
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]
[Python-checkins] [3.12] gh-121607: Edited source file import recipe to make it more clear (GH-121519) (GH-124081)
https://github.com/python/cpython/commit/ba292cc3019135fdd3670d72d6e3252a5a99a570 commit: ba292cc3019135fdd3670d72d6e3252a5a99a570 branch: 3.12 author: Miss Islington (bot) <[email protected]> committer: brettcannon date: 2024-10-10T10:31:27-07:00 summary: [3.12] gh-121607: Edited source file import recipe to make it more clear (GH-121519) (GH-124081) gh-121607: Edited source file import recipe to make it more clear (GH-121519) (cherry picked from commit 38809171b8768517824fb62d48abe2cb0aff8429) Co-authored-by: Chris Barker Co-authored-by: Brett Cannon Co-authored-by: Peter Bierma files: M Doc/library/importlib.rst diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst index 1dacbe64b748db..e4e09b096f7c04 100644 --- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -1495,20 +1495,34 @@ Note that if ``name`` is a submodule (contains a dot), Importing a source file directly -To import a Python source file directly, use the following recipe:: +This recipe should be used with caution: it is an approximation of an import +statement where the file path is specified directly, rather than +:data:`sys.path` being searched. Alternatives should first be considered first, +such as modifying :data:`sys.path` when a proper module is required, or using +:func:`runpy.run_path` when the global namespace resulting from running a Python +file is appropriate. - import importlib.util - import sys +To import a Python source file directly from a path, use the following recipe:: + +import importlib.util +import sys - # For illustrative purposes. - import tokenize - file_path = tokenize.__file__ - module_name = tokenize.__name__ - spec = importlib.util.spec_from_file_location(module_name, file_path) - module = importlib.util.module_from_spec(spec) - sys.modules[module_name] = module - spec.loader.exec_module(module) +def import_from_path(module_name, file_path): +spec = importlib.util.spec_from_file_location(module_name, file_path) +module = importlib.util.module_from_spec(spec) +sys.modules[module_name] = module +spec.loader.exec_module(module) +return module + + +# For illustrative purposes only (use of `json` is arbitrary). +import json +file_path = json.__file__ +module_name = json.__name__ + +# Similar outcome as `import json`. +json = import_from_path(module_name, file_path) Implementing lazy imports @@ -1534,7 +1548,6 @@ The example below shows how to implement lazy imports:: False - Setting up an importer '' ___ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
[Python-checkins] [3.13] GH-121634: have `wasi.py` accept the host target triple as an argument (GH-123030) (GH-123042)
https://github.com/python/cpython/commit/cc1892d3cfc72827fceb6ca2e44725265d2407bc commit: cc1892d3cfc72827fceb6ca2e44725265d2407bc branch: 3.13 author: Miss Islington (bot) <[email protected]> committer: brettcannon date: 2024-10-10T17:44:31Z summary: [3.13] GH-121634: have `wasi.py` accept the host target triple as an argument (GH-123030) (GH-123042) GH-121634: have `wasi.py` accept the host target triple as an argument (GH-123030) (cherry picked from commit b15b81ed4f58196b35e3dd13b484f4c7a73e5bb8) Co-authored-by: Brett Cannon files: A Misc/NEWS.d/next/Build/2024-08-14-19-17-34.gh-issue-121634.eOMfHG.rst M Tools/wasm/wasi.py diff --git a/Misc/NEWS.d/next/Build/2024-08-14-19-17-34.gh-issue-121634.eOMfHG.rst b/Misc/NEWS.d/next/Build/2024-08-14-19-17-34.gh-issue-121634.eOMfHG.rst new file mode 100644 index 00..025b6bca809898 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2024-08-14-19-17-34.gh-issue-121634.eOMfHG.rst @@ -0,0 +1 @@ +Allow for specifying the target compile triple for WASI. diff --git a/Tools/wasm/wasi.py b/Tools/wasm/wasi.py index d4394d7dc1d026..8deb1f631df49a 100644 --- a/Tools/wasm/wasi.py +++ b/Tools/wasm/wasi.py @@ -20,8 +20,6 @@ CROSS_BUILD_DIR = CHECKOUT / "cross-build" BUILD_DIR = CROSS_BUILD_DIR / "build" -HOST_TRIPLE = "wasm32-wasi" -HOST_DIR = CROSS_BUILD_DIR / HOST_TRIPLE LOCAL_SETUP = CHECKOUT / "Modules" / "Setup.local" LOCAL_SETUP_MARKER = "# Generated by Tools/wasm/wasi.py\n".encode("utf-8") @@ -63,12 +61,17 @@ def subdir(working_dir, *, clean_ok=False): def decorator(func): @functools.wraps(func) def wrapper(context): +nonlocal working_dir + +if callable(working_dir): +working_dir = working_dir(context) try: tput_output = subprocess.check_output(["tput", "cols"], encoding="utf-8") -terminal_width = int(tput_output.strip()) except subprocess.CalledProcessError: terminal_width = 80 +else: +terminal_width = int(tput_output.strip()) print("⎯" * terminal_width) print("📁", working_dir) if (clean_ok and getattr(context, "clean", False) and @@ -193,7 +196,7 @@ def wasi_sdk_env(context): return env -@subdir(HOST_DIR, clean_ok=True) +@subdir(lambda context: CROSS_BUILD_DIR / context.host_triple, clean_ok=True) def configure_wasi_python(context, working_dir): """Configure the WASI/host build.""" if not context.wasi_sdk_path or not context.wasi_sdk_path.exists(): @@ -238,7 +241,7 @@ def configure_wasi_python(context, working_dir): # to find the stdlib due to Python not recognizing that it's being # executed from within a checkout. configure = [os.path.relpath(CHECKOUT / 'configure', working_dir), -f"--host={HOST_TRIPLE}", +f"--host={context.host_triple}", f"--build={build_platform()}", f"--with-build-python={build_python}"] if pydebug: @@ -258,7 +261,7 @@ def configure_wasi_python(context, working_dir): sys.stdout.flush() -@subdir(HOST_DIR) +@subdir(lambda context: CROSS_BUILD_DIR / context.host_triple) def make_wasi_python(context, working_dir): """Run `make` for the WASI/host build.""" call(["make", "--jobs", str(cpu_count()), "all"], @@ -343,6 +346,9 @@ def main(): help="Command template for running the WASI host " "(default designed for wasmtime 14 or newer: " f"`{default_host_runner}`)") +for subcommand in build, configure_host, make_host: +subcommand.add_argument("--host-triple", action="store", default="wasm32-wasi", +help="The target triple for the WASI host build") context = parser.parse_args() ___ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
[Python-checkins] [3.13] GH-122578: update to WASI SDK 24 (GH-122960) (GH-122961)
https://github.com/python/cpython/commit/2f87976926c393ae683d8414c201759997c23ef8 commit: 2f87976926c393ae683d8414c201759997c23ef8 branch: 3.13 author: Miss Islington (bot) <[email protected]> committer: brettcannon date: 2024-10-10T17:46:01Z summary: [3.13] GH-122578: update to WASI SDK 24 (GH-122960) (GH-122961) GH-122578: update to WASI SDK 24 (GH-122960) (cherry picked from commit 0e207f3e7adc6a0fdbe1482ce01163ff04d5ddcb) Co-authored-by: Brett Cannon files: A Misc/NEWS.d/next/Build/2024-08-12-15-48-49.gh-issue-122578.YJ3xEa.rst M .devcontainer/Dockerfile M .github/workflows/reusable-wasi.yml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index a4ada1b66bf476..ada5fb0fe64dc2 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -2,7 +2,7 @@ FROM docker.io/library/fedora:40 ENV CC=clang -ENV WASI_SDK_VERSION=22 +ENV WASI_SDK_VERSION=24 ENV WASI_SDK_PATH=/opt/wasi-sdk ENV WASMTIME_HOME=/opt/wasmtime @@ -14,7 +14,7 @@ RUN dnf -y --nodocs --setopt=install_weak_deps=False install /usr/bin/{blurb,cla dnf -y clean all RUN mkdir ${WASI_SDK_PATH} && \ -curl --location https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VERSION}/wasi-sdk-${WASI_SDK_VERSION}.0-linux.tar.gz | \ +curl --location https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VERSION}/wasi-sdk-${WASI_SDK_VERSION}.0-x86_64-linux.tar.gz | \ tar --strip-components 1 --directory ${WASI_SDK_PATH} --extract --gunzip RUN mkdir --parents ${WASMTIME_HOME} && \ diff --git a/.github/workflows/reusable-wasi.yml b/.github/workflows/reusable-wasi.yml index 051d403b9c2595..4c8137c958a312 100644 --- a/.github/workflows/reusable-wasi.yml +++ b/.github/workflows/reusable-wasi.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-22.04 env: WASMTIME_VERSION: 22.0.0 - WASI_SDK_VERSION: 22 + WASI_SDK_VERSION: 24 WASI_SDK_PATH: /opt/wasi-sdk CROSS_BUILD_PYTHON: cross-build/build CROSS_BUILD_WASI: cross-build/wasm32-wasi @@ -35,7 +35,7 @@ jobs: if: steps.cache-wasi-sdk.outputs.cache-hit != 'true' run: | mkdir ${{ env.WASI_SDK_PATH }} && \ -curl -s -S --location https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${{ env.WASI_SDK_VERSION }}/wasi-sdk-${{ env.WASI_SDK_VERSION }}.0-linux.tar.gz | \ +curl -s -S --location https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${{ env.WASI_SDK_VERSION }}/wasi-sdk-${{ env.WASI_SDK_VERSION }}.0-x86_64-linux.tar.gz | \ tar --strip-components 1 --directory ${{ env.WASI_SDK_PATH }} --extract --gunzip - name: "Configure ccache action" uses: hendrikmuhs/[email protected] diff --git a/Misc/NEWS.d/next/Build/2024-08-12-15-48-49.gh-issue-122578.YJ3xEa.rst b/Misc/NEWS.d/next/Build/2024-08-12-15-48-49.gh-issue-122578.YJ3xEa.rst new file mode 100644 index 00..5c1b9079909ff4 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2024-08-12-15-48-49.gh-issue-122578.YJ3xEa.rst @@ -0,0 +1 @@ +Use WASI SDK 24 for testing. ___ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
[Python-checkins] [3.13] Note argparse exit code in documentation (GH-119568) (GH-125274)
https://github.com/python/cpython/commit/319305c0bf1212d46c8695310af63e3da79ee4be commit: 319305c0bf1212d46c8695310af63e3da79ee4be branch: 3.13 author: Miss Islington (bot) <[email protected]> committer: serhiy-storchaka date: 2024-10-10T21:18:17+03:00 summary: [3.13] Note argparse exit code in documentation (GH-119568) (GH-125274) (cherry picked from commit 3b87fb74c907510402678bf1b7c4a94df0e5e65a) Co-authored-by: Justin Kunimune Co-authored-by: Savannah Ostrowski files: M Doc/library/argparse.rst diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 0014947d019261..d2705e485c3358 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -537,7 +537,8 @@ exit_on_error ^ Normally, when you pass an invalid argument list to the :meth:`~ArgumentParser.parse_args` -method of an :class:`ArgumentParser`, it will exit with error info. +method of an :class:`ArgumentParser`, it will print a *message* to :data:`sys.stderr` and exit with a status +code of 2. If the user would like to catch errors manually, the feature can be enabled by setting ``exit_on_error`` to ``False``:: ___ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
[Python-checkins] gh-124570: ctypes: Run some Structure tests on Union as well (GH-124976)
https://github.com/python/cpython/commit/01fc3b34cc6994bc83b6540da3a8573e79dfbb56
commit: 01fc3b34cc6994bc83b6540da3a8573e79dfbb56
branch: main
author: Petr Viktorin
committer: encukou
date: 2024-10-10T16:27:52+02:00
summary:
gh-124570: ctypes: Run some Structure tests on Union as well (GH-124976)
- Move some Structure tests to test_structunion; use a common base
test class + two subclasses to run them on Union too
- Remove test_union for now as it's redundant
Note: `test_simple_structs` & `test_simple_unions` are in the common
file because they share `formats`.
files:
A Lib/test/test_ctypes/test_structunion.py
D Lib/test/test_ctypes/test_unions.py
M Lib/test/test_ctypes/test_structures.py
diff --git a/Lib/test/test_ctypes/test_structunion.py
b/Lib/test/test_ctypes/test_structunion.py
new file mode 100644
index 00..973ac3b2f1919d
--- /dev/null
+++ b/Lib/test/test_ctypes/test_structunion.py
@@ -0,0 +1,353 @@
+"""Common tests for ctypes.Structure and ctypes.Union"""
+
+import unittest
+from ctypes import (Structure, Union, POINTER, sizeof, alignment,
+c_char, c_byte, c_ubyte,
+c_short, c_ushort, c_int, c_uint,
+c_long, c_ulong, c_longlong, c_ulonglong, c_float,
c_double)
+from ._support import (_CData, PyCStructType, UnionType,
+ Py_TPFLAGS_DISALLOW_INSTANTIATION,
+ Py_TPFLAGS_IMMUTABLETYPE)
+from struct import calcsize
+
+
+class StructUnionTestBase:
+formats = {"c": c_char,
+ "b": c_byte,
+ "B": c_ubyte,
+ "h": c_short,
+ "H": c_ushort,
+ "i": c_int,
+ "I": c_uint,
+ "l": c_long,
+ "L": c_ulong,
+ "q": c_longlong,
+ "Q": c_ulonglong,
+ "f": c_float,
+ "d": c_double,
+ }
+
+def test_subclass(self):
+class X(self.cls):
+_fields_ = [("a", c_int)]
+
+class Y(X):
+_fields_ = [("b", c_int)]
+
+class Z(X):
+pass
+
+self.assertEqual(sizeof(X), sizeof(c_int))
+self.check_sizeof(Y,
+ struct_size=sizeof(c_int)*2,
+ union_size=sizeof(c_int))
+self.assertEqual(sizeof(Z), sizeof(c_int))
+self.assertEqual(X._fields_, [("a", c_int)])
+self.assertEqual(Y._fields_, [("b", c_int)])
+self.assertEqual(Z._fields_, [("a", c_int)])
+
+def test_subclass_delayed(self):
+class X(self.cls):
+pass
+self.assertEqual(sizeof(X), 0)
+X._fields_ = [("a", c_int)]
+
+class Y(X):
+pass
+self.assertEqual(sizeof(Y), sizeof(X))
+Y._fields_ = [("b", c_int)]
+
+class Z(X):
+pass
+
+self.assertEqual(sizeof(X), sizeof(c_int))
+self.check_sizeof(Y,
+ struct_size=sizeof(c_int)*2,
+ union_size=sizeof(c_int))
+self.assertEqual(sizeof(Z), sizeof(c_int))
+self.assertEqual(X._fields_, [("a", c_int)])
+self.assertEqual(Y._fields_, [("b", c_int)])
+self.assertEqual(Z._fields_, [("a", c_int)])
+
+def test_inheritance_hierarchy(self):
+self.assertEqual(self.cls.mro(), [self.cls, _CData, object])
+self.assertEqual(type(self.metacls), type)
+
+def test_type_flags(self):
+for cls in self.cls, self.metacls:
+with self.subTest(cls=cls):
+self.assertTrue(cls.__flags__ & Py_TPFLAGS_IMMUTABLETYPE)
+self.assertFalse(cls.__flags__ &
Py_TPFLAGS_DISALLOW_INSTANTIATION)
+
+def test_metaclass_details(self):
+# Abstract classes (whose metaclass __init__ was not called) can't be
+# instantiated directly
+NewClass = self.metacls.__new__(self.metacls, 'NewClass',
+(self.cls,), {})
+for cls in self.cls, NewClass:
+with self.subTest(cls=cls):
+with self.assertRaisesRegex(TypeError, "abstract class"):
+obj = cls()
+
+# Cannot call the metaclass __init__ more than once
+class T(self.cls):
+_fields_ = [("x", c_char),
+("y", c_char)]
+with self.assertRaisesRegex(SystemError, "already initialized"):
+self.metacls.__init__(T, 'ptr', (), {})
+
+def test_alignment(self):
+class X(self.cls):
+_fields_ = [("x", c_char * 3)]
+self.assertEqual(alignment(X), calcsize("s"))
+self.assertEqual(sizeof(X), calcsize("3s"))
+
+class Y(self.cls):
+_fields_ = [("x", c_char * 3),
+("y", c_int)]
+self.assertEqual(alignment(Y), alignment(c_int))
+self.check_sizeof(Y,
+ struct_size=calcsize("3s i"),
+ union_size=max(calcsize("3s"), ca
[Python-checkins] [3.13] gh-125118: don't copy arbitrary values to _Bool in the struct module (GH-125169) (#125263)
https://github.com/python/cpython/commit/c2cb1a89b75f000842bf9626928155172b9ab069
commit: c2cb1a89b75f000842bf9626928155172b9ab069
branch: 3.13
author: Sergey B Kirpichev
committer: vstinner
date: 2024-10-10T14:58:57Z
summary:
[3.13] gh-125118: don't copy arbitrary values to _Bool in the struct module
(GH-125169) (#125263)
memcopy'ing arbitrary values to _Bool variable triggers undefined
behaviour. Avoid this.
We assume that `false` is represented by all zero bytes.
Credits to Alex Gaynor.
(cherry picked from commit 87d7315ac57250046372b0d9ae4619ba619c8c87)
Co-authored-by: Sam Gross
Co-authored-by: Victor Stinner
Co-authored-by: Petr Viktorin
files:
A Misc/NEWS.d/next/Library/2024-10-09-07-09-00.gh-issue-125118.J9rQ1S.rst
M Lib/test/test_struct.py
M Modules/_struct.c
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py
index bdbf8800cfd8f6..e3ddaa090316ff 100644
--- a/Lib/test/test_struct.py
+++ b/Lib/test/test_struct.py
@@ -529,6 +529,9 @@ def __bool__(self):
for c in [b'\x01', b'\x7f', b'\xff', b'\x0f', b'\xf0']:
self.assertTrue(struct.unpack('>?', c)[0])
+self.assertTrue(struct.unpack('https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]
[Python-checkins] [3.12] gh-125118: don't copy arbitrary values to _Bool in the struct module (GH-125169) (#125265)
https://github.com/python/cpython/commit/67f8302b9c94079f73dba23eaa47443fcb6008ad
commit: 67f8302b9c94079f73dba23eaa47443fcb6008ad
branch: 3.12
author: Sergey B Kirpichev
committer: vstinner
date: 2024-10-10T14:56:49Z
summary:
[3.12] gh-125118: don't copy arbitrary values to _Bool in the struct module
(GH-125169) (#125265)
memcopy'ing arbitrary values to _Bool variable triggers undefined
behaviour. Avoid this.
We assume that `false` is represented by all zero bytes.
Credits to Alex Gaynor.
(cherry picked from commit 87d7315ac57250046372b0d9ae4619ba619c8c87)
Co-authored-by: Sam Gross
Co-authored-by: Victor Stinner
Co-authored-by: Petr Viktorin
files:
A Misc/NEWS.d/next/Library/2024-10-09-07-09-00.gh-issue-125118.J9rQ1S.rst
M Lib/test/test_struct.py
M Modules/_struct.c
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py
index 39ca78cece1fb0..c683e5dd6c47c6 100644
--- a/Lib/test/test_struct.py
+++ b/Lib/test/test_struct.py
@@ -529,6 +529,9 @@ def __bool__(self):
for c in [b'\x01', b'\x7f', b'\xff', b'\x0f', b'\xf0']:
self.assertTrue(struct.unpack('>?', c)[0])
+self.assertTrue(struct.unpack('https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]
[Python-checkins] gh-125268: Use static string for "1e309" in AST (#125272)
https://github.com/python/cpython/commit/427dcf24de4e06d239745d74d08c4b2e541dca5a
commit: 427dcf24de4e06d239745d74d08c4b2e541dca5a
branch: main
author: Sam Gross
committer: colesbury
date: 2024-10-10T16:21:29-04:00
summary:
gh-125268: Use static string for "1e309" in AST (#125272)
When formatting the AST as a string, infinite values are replaced by
1e309, which evaluates to infinity. The initialization of this string
replacement was not thread-safe in the free threading build.
files:
M Include/internal/pycore_global_objects.h
M Include/internal/pycore_global_objects_fini_generated.h
M Include/internal/pycore_global_strings.h
M Include/internal/pycore_runtime_init_generated.h
M Include/internal/pycore_unicodeobject_generated.h
M Parser/asdl_c.py
M Python/Python-ast.c
M Python/ast_unparse.c
diff --git a/Include/internal/pycore_global_objects.h
b/Include/internal/pycore_global_objects.h
index 913dce6f1ec0fe..e3f7ac707f0c37 100644
--- a/Include/internal/pycore_global_objects.h
+++ b/Include/internal/pycore_global_objects.h
@@ -66,9 +66,6 @@ struct _Py_static_objects {
struct _Py_interp_cached_objects {
PyObject *interned_strings;
-/* AST */
-PyObject *str_replace_inf;
-
/* object.__reduce__ */
PyObject *objreduce;
PyObject *type_slots_pname;
diff --git a/Include/internal/pycore_global_objects_fini_generated.h
b/Include/internal/pycore_global_objects_fini_generated.h
index de68ef93257234..2fd7d5d13a98b2 100644
--- a/Include/internal/pycore_global_objects_fini_generated.h
+++ b/Include/internal/pycore_global_objects_fini_generated.h
@@ -562,6 +562,7 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) {
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(json_decoder));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(kwdefaults));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(list_err));
+_PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(str_replace_inf));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(type_params));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(utf_8));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(CANCELLED));
diff --git a/Include/internal/pycore_global_strings.h
b/Include/internal/pycore_global_strings.h
index 1591cb0a3f114f..fc3871570cc49d 100644
--- a/Include/internal/pycore_global_strings.h
+++ b/Include/internal/pycore_global_strings.h
@@ -48,6 +48,7 @@ struct _Py_global_strings {
STRUCT_FOR_STR(json_decoder, "json.decoder")
STRUCT_FOR_STR(kwdefaults, ".kwdefaults")
STRUCT_FOR_STR(list_err, "list index out of range")
+STRUCT_FOR_STR(str_replace_inf, "1e309")
STRUCT_FOR_STR(type_params, ".type_params")
STRUCT_FOR_STR(utf_8, "utf-8")
} literals;
diff --git a/Include/internal/pycore_runtime_init_generated.h
b/Include/internal/pycore_runtime_init_generated.h
index c9d20d0b5aacdb..3b80e265b0ca50 100644
--- a/Include/internal/pycore_runtime_init_generated.h
+++ b/Include/internal/pycore_runtime_init_generated.h
@@ -557,6 +557,7 @@ extern "C" {
INIT_STR(json_decoder, "json.decoder"), \
INIT_STR(kwdefaults, ".kwdefaults"), \
INIT_STR(list_err, "list index out of range"), \
+INIT_STR(str_replace_inf, "1e309"), \
INIT_STR(type_params, ".type_params"), \
INIT_STR(utf_8, "utf-8"), \
}
diff --git a/Include/internal/pycore_unicodeobject_generated.h
b/Include/internal/pycore_unicodeobject_generated.h
index d335373e88ee74..eb2eca06ec4d4f 100644
--- a/Include/internal/pycore_unicodeobject_generated.h
+++ b/Include/internal/pycore_unicodeobject_generated.h
@@ -2936,6 +2936,10 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp)
{
_PyUnicode_InternStatic(interp, &string);
assert(_PyUnicode_CheckConsistency(string, 1));
assert(PyUnicode_GET_LENGTH(string) != 1);
+string = &_Py_STR(str_replace_inf);
+_PyUnicode_InternStatic(interp, &string);
+assert(_PyUnicode_CheckConsistency(string, 1));
+assert(PyUnicode_GET_LENGTH(string) != 1);
string = &_Py_STR(anon_null);
_PyUnicode_InternStatic(interp, &string);
assert(_PyUnicode_CheckConsistency(string, 1));
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
index f50c28afcfe205..32eac3afafa5d5 100755
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -2242,8 +2242,6 @@ def generate_ast_fini(module_state, f):
for s in module_state:
f.write("Py_CLEAR(state->" + s + ');\n')
f.write(textwrap.dedent("""
-Py_CLEAR(_Py_INTERP_CACHED_OBJECT(interp, str_replace_inf));
-
state->finalized = 1;
state->once = (_PyOnceFlag){0};
}
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index 89c52b9dc73cac..38d74b48d232f8 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -281,8 +281,6 @@ void _PyAST_Fini(PyInterpreterState *interp)
Py_CLEAR(state->vararg);
Py_CLEAR(state->withitem_type);
-Py_CLEAR(_Py_INTERP_CACHED_OBJECT(interp, str_replace_inf)
[Python-checkins] Doc: Upgrade Sphinx to 8.1 (#125276)
https://github.com/python/cpython/commit/dd0ee201da34d1d4a631d77b420728f9233f53f9 commit: dd0ee201da34d1d4a631d77b420728f9233f53f9 branch: main author: Adam Turner <[email protected]> committer: AA-Turner <[email protected]> date: 2024-10-10T21:26:01+01:00 summary: Doc: Upgrade Sphinx to 8.1 (#125276) files: M Doc/conf.py M Doc/requirements.txt diff --git a/Doc/conf.py b/Doc/conf.py index 287e0da46eb11c..d7197b17865854 100644 --- a/Doc/conf.py +++ b/Doc/conf.py @@ -11,6 +11,8 @@ import sys import time +import sphinx + sys.path.append(os.path.abspath('tools/extensions')) sys.path.append(os.path.abspath('includes')) @@ -62,7 +64,10 @@ # General substitutions. project = 'Python' -copyright = f"2001-{time.strftime('%Y')}, Python Software Foundation" +if sphinx.version_info[:2] >= (8, 1): +copyright = "2001-%Y, Python Software Foundation" +else: +copyright = f"2001-{time.strftime('%Y')}, Python Software Foundation" # We look for the Include/patchlevel.h file in the current Python source tree # and replace the values accordingly. @@ -361,10 +366,14 @@ } # This 'Last updated on:' timestamp is inserted at the bottom of every page. -html_time = int(os.environ.get('SOURCE_DATE_EPOCH', time.time())) -html_last_updated_fmt = time.strftime( -'%b %d, %Y (%H:%M UTC)', time.gmtime(html_time) -) +html_last_updated_fmt = '%b %d, %Y (%H:%M UTC)' +if sphinx.version_info[:2] >= (8, 1): +html_last_updated_use_utc = True +else: +html_time = int(os.environ.get('SOURCE_DATE_EPOCH', time.time())) +html_last_updated_fmt = time.strftime( +html_last_updated_fmt, time.gmtime(html_time) +) # Path to find HTML templates. templates_path = ['tools/templates'] @@ -596,13 +605,21 @@ # mapping unique short aliases to a base URL and a prefix. # https://www.sphinx-doc.org/en/master/usage/extensions/extlinks.html extlinks = { -"cve": ("https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-%s";, "CVE-%s"), -"cwe": ("https://cwe.mitre.org/data/definitions/%s.html";, "CWE-%s"), "pypi": ("https://pypi.org/project/%s/";, "%s"), "source": (SOURCE_URI, "%s"), } extlinks_detect_hardcoded_links = True +if sphinx.version_info[:2] < (8, 1): +# Sphinx 8.1 has in-built CVE and CWE roles. +extlinks |= { +"cve": ( +"https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-%s";, +"CVE-%s", +), +"cwe": ("https://cwe.mitre.org/data/definitions/%s.html";, "CWE-%s"), +} + # Options for c_annotations # - diff --git a/Doc/requirements.txt b/Doc/requirements.txt index bf1028020b7af7..5105786ccf283c 100644 --- a/Doc/requirements.txt +++ b/Doc/requirements.txt @@ -6,7 +6,7 @@ # Sphinx version is pinned so that new versions that introduce new warnings # won't suddenly cause build failures. Updating the version is fine as long # as no warnings are raised by doing so. -sphinx~=8.0.0 +sphinx~=8.1.0 blurb ___ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
[Python-checkins] [3.12] Doc: Upgrade Sphinx to 8.1 (GH-125276) (#125279)
https://github.com/python/cpython/commit/91c7a2cb890856dde865cbc98b70c7421550f49e commit: 91c7a2cb890856dde865cbc98b70c7421550f49e branch: 3.12 author: Miss Islington (bot) <[email protected]> committer: AA-Turner <[email protected]> date: 2024-10-10T20:32:40Z summary: [3.12] Doc: Upgrade Sphinx to 8.1 (GH-125276) (#125279) Doc: Upgrade Sphinx to 8.1 (GH-125276) (cherry picked from commit dd0ee201da34d1d4a631d77b420728f9233f53f9) Co-authored-by: Adam Turner <[email protected]> files: M Doc/conf.py M Doc/requirements.txt diff --git a/Doc/conf.py b/Doc/conf.py index 4859063edd24ea..36f6243969c8b2 100644 --- a/Doc/conf.py +++ b/Doc/conf.py @@ -11,6 +11,8 @@ import sys import time +import sphinx + sys.path.append(os.path.abspath('tools/extensions')) sys.path.append(os.path.abspath('includes')) @@ -56,7 +58,10 @@ # General substitutions. project = 'Python' -copyright = f"2001-{time.strftime('%Y')}, Python Software Foundation" +if sphinx.version_info[:2] >= (8, 1): +copyright = "2001-%Y, Python Software Foundation" +else: +copyright = f"2001-{time.strftime('%Y')}, Python Software Foundation" # We look for the Include/patchlevel.h file in the current Python source tree # and replace the values accordingly. @@ -339,10 +344,14 @@ } # This 'Last updated on:' timestamp is inserted at the bottom of every page. -html_time = int(os.environ.get('SOURCE_DATE_EPOCH', time.time())) -html_last_updated_fmt = time.strftime( -'%b %d, %Y (%H:%M UTC)', time.gmtime(html_time) -) +html_last_updated_fmt = '%b %d, %Y (%H:%M UTC)' +if sphinx.version_info[:2] >= (8, 1): +html_last_updated_use_utc = True +else: +html_time = int(os.environ.get('SOURCE_DATE_EPOCH', time.time())) +html_last_updated_fmt = time.strftime( +html_last_updated_fmt, time.gmtime(html_time) +) # Path to find HTML templates. templates_path = ['tools/templates'] @@ -575,13 +584,21 @@ # mapping unique short aliases to a base URL and a prefix. # https://www.sphinx-doc.org/en/master/usage/extensions/extlinks.html extlinks = { -"cve": ("https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-%s";, "CVE-%s"), -"cwe": ("https://cwe.mitre.org/data/definitions/%s.html";, "CWE-%s"), "pypi": ("https://pypi.org/project/%s/";, "%s"), "source": (SOURCE_URI, "%s"), } extlinks_detect_hardcoded_links = True +if sphinx.version_info[:2] < (8, 1): +# Sphinx 8.1 has in-built CVE and CWE roles. +extlinks |= { +"cve": ( +"https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-%s";, +"CVE-%s", +), +"cwe": ("https://cwe.mitre.org/data/definitions/%s.html";, "CWE-%s"), +} + # Options for c_annotations # - diff --git a/Doc/requirements.txt b/Doc/requirements.txt index bf1028020b7af7..5105786ccf283c 100644 --- a/Doc/requirements.txt +++ b/Doc/requirements.txt @@ -6,7 +6,7 @@ # Sphinx version is pinned so that new versions that introduce new warnings # won't suddenly cause build failures. Updating the version is fine as long # as no warnings are raised by doing so. -sphinx~=8.0.0 +sphinx~=8.1.0 blurb ___ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
[Python-checkins] [3.13] Doc: Upgrade Sphinx to 8.1 (GH-125276) (#125278)
https://github.com/python/cpython/commit/2019362d95fcf53151db09c6c6fa45c7bba660e5 commit: 2019362d95fcf53151db09c6c6fa45c7bba660e5 branch: 3.13 author: Miss Islington (bot) <[email protected]> committer: AA-Turner <[email protected]> date: 2024-10-10T20:31:40Z summary: [3.13] Doc: Upgrade Sphinx to 8.1 (GH-125276) (#125278) Doc: Upgrade Sphinx to 8.1 (GH-125276) (cherry picked from commit dd0ee201da34d1d4a631d77b420728f9233f53f9) Co-authored-by: Adam Turner <[email protected]> files: M Doc/conf.py M Doc/requirements.txt diff --git a/Doc/conf.py b/Doc/conf.py index 287e0da46eb11c..d7197b17865854 100644 --- a/Doc/conf.py +++ b/Doc/conf.py @@ -11,6 +11,8 @@ import sys import time +import sphinx + sys.path.append(os.path.abspath('tools/extensions')) sys.path.append(os.path.abspath('includes')) @@ -62,7 +64,10 @@ # General substitutions. project = 'Python' -copyright = f"2001-{time.strftime('%Y')}, Python Software Foundation" +if sphinx.version_info[:2] >= (8, 1): +copyright = "2001-%Y, Python Software Foundation" +else: +copyright = f"2001-{time.strftime('%Y')}, Python Software Foundation" # We look for the Include/patchlevel.h file in the current Python source tree # and replace the values accordingly. @@ -361,10 +366,14 @@ } # This 'Last updated on:' timestamp is inserted at the bottom of every page. -html_time = int(os.environ.get('SOURCE_DATE_EPOCH', time.time())) -html_last_updated_fmt = time.strftime( -'%b %d, %Y (%H:%M UTC)', time.gmtime(html_time) -) +html_last_updated_fmt = '%b %d, %Y (%H:%M UTC)' +if sphinx.version_info[:2] >= (8, 1): +html_last_updated_use_utc = True +else: +html_time = int(os.environ.get('SOURCE_DATE_EPOCH', time.time())) +html_last_updated_fmt = time.strftime( +html_last_updated_fmt, time.gmtime(html_time) +) # Path to find HTML templates. templates_path = ['tools/templates'] @@ -596,13 +605,21 @@ # mapping unique short aliases to a base URL and a prefix. # https://www.sphinx-doc.org/en/master/usage/extensions/extlinks.html extlinks = { -"cve": ("https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-%s";, "CVE-%s"), -"cwe": ("https://cwe.mitre.org/data/definitions/%s.html";, "CWE-%s"), "pypi": ("https://pypi.org/project/%s/";, "%s"), "source": (SOURCE_URI, "%s"), } extlinks_detect_hardcoded_links = True +if sphinx.version_info[:2] < (8, 1): +# Sphinx 8.1 has in-built CVE and CWE roles. +extlinks |= { +"cve": ( +"https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-%s";, +"CVE-%s", +), +"cwe": ("https://cwe.mitre.org/data/definitions/%s.html";, "CWE-%s"), +} + # Options for c_annotations # - diff --git a/Doc/requirements.txt b/Doc/requirements.txt index bf1028020b7af7..5105786ccf283c 100644 --- a/Doc/requirements.txt +++ b/Doc/requirements.txt @@ -6,7 +6,7 @@ # Sphinx version is pinned so that new versions that introduce new warnings # won't suddenly cause build failures. Updating the version is fine as long # as no warnings are raised by doing so. -sphinx~=8.0.0 +sphinx~=8.1.0 blurb ___ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
