[Python-checkins] gh-114115: Update documentation of array.array (GH-114117)

2024-01-22 Thread serhiy-storchaka
https://github.com/python/cpython/commit/650f9e4c94711ff49ea4e13bf800945a6147b7e0
commit: 650f9e4c94711ff49ea4e13bf800945a6147b7e0
branch: main
author: Serhiy Storchaka 
committer: serhiy-storchaka 
date: 2024-01-22T08:42:50Z
summary:

gh-114115: Update documentation of array.array (GH-114117)

Co-authored-by: Hugo van Kemenade <[email protected]>

files:
M Doc/library/array.rst

diff --git a/Doc/library/array.rst b/Doc/library/array.rst
index ad622627724217..a0e8bb20a098fd 100644
--- a/Doc/library/array.rst
+++ b/Doc/library/array.rst
@@ -79,14 +79,16 @@ The module defines the following type:
 .. class:: array(typecode[, initializer])
 
A new array whose items are restricted by *typecode*, and initialized
-   from the optional *initializer* value, which must be a list, a
-   :term:`bytes-like object`, or iterable over elements of the
-   appropriate type.
+   from the optional *initializer* value, which must be a :class:`bytes`
+   or :class:`bytearray` object, a Unicode string, or iterable over elements
+   of the appropriate type.
 
-   If given a list or string, the initializer is passed to the new array's
-   :meth:`fromlist`, :meth:`frombytes`, or :meth:`fromunicode` method (see 
below)
-   to add initial items to the array.  Otherwise, the iterable initializer is
-   passed to the :meth:`extend` method.
+   If given a :class:`bytes` or :class:`bytearray` object, the initializer
+   is passed to the new array's :meth:`frombytes` method;
+   if given a Unicode string, the initializer is passed to the
+   :meth:`fromunicode` method;
+   otherwise, the initializer's iterator is passed to the :meth:`extend` method
+   to add initial items to the array.
 
Array objects support the ordinary sequence operations of indexing, slicing,
concatenation, and multiplication.  When using slice assignment, the 
assigned
@@ -152,10 +154,11 @@ The module defines the following type:
   must be the right type to be appended to the array.
 
 
-   .. method:: frombytes(s)
+   .. method:: frombytes(buffer)
 
-  Appends items from the string, interpreting the string as an array of 
machine
-  values (as if it had been read from a file using the :meth:`fromfile` 
method).
+  Appends items from the :term:`bytes-like object`, interpreting
+  its content as an array of machine values (as if it had been read
+  from a file using the :meth:`fromfile` method).
 
   .. versionadded:: 3.2
  :meth:`!fromstring` is renamed to :meth:`frombytes` for clarity.
@@ -177,7 +180,7 @@ The module defines the following type:
 
.. method:: fromunicode(s)
 
-  Extends this array with data from the given unicode string.
+  Extends this array with data from the given Unicode string.
   The array must have type code ``'u'`` or ``'w'``; otherwise a 
:exc:`ValueError` is raised.
   Use ``array.frombytes(unicodestring.encode(enc))`` to append Unicode 
data to an
   array of some other type.
@@ -239,24 +242,27 @@ The module defines the following type:
 
.. method:: tounicode()
 
-  Convert the array to a unicode string.  The array must have a type 
``'u'`` or ``'w'``;
+  Convert the array to a Unicode string.  The array must have a type 
``'u'`` or ``'w'``;
   otherwise a :exc:`ValueError` is raised. Use 
``array.tobytes().decode(enc)`` to
-  obtain a unicode string from an array of some other type.
+  obtain a Unicode string from an array of some other type.
 
 
-When an array object is printed or converted to a string, it is represented as
-``array(typecode, initializer)``.  The *initializer* is omitted if the array is
-empty, otherwise it is a string if the *typecode* is ``'u'`` or ``'w'``,
-otherwise it is a list of numbers.
-The string is guaranteed to be able to be converted back to an
+The string representation of array objects has the form
+``array(typecode, initializer)``.
+The *initializer* is omitted if the array is empty, otherwise it is
+a Unicode string if the *typecode* is ``'u'`` or ``'w'``, otherwise it is
+a list of numbers.
+The string representation is guaranteed to be able to be converted back to an
 array with the same type and value using :func:`eval`, so long as the
 :class:`~array.array` class has been imported using ``from array import 
array``.
+Variables ``inf`` and ``nan`` must also be defined if it contains
+corresponding floating point values.
 Examples::
 
array('l')
array('w', 'hello \u2641')
array('l', [1, 2, 3, 4, 5])
-   array('d', [1.0, 2.0, 3.14])
+   array('d', [1.0, 2.0, 3.14, -inf, nan])
 
 
 .. seealso::

___
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-114414: Assert PyType_GetModuleByDef result in _threadmodule (#114415)

2024-01-22 Thread erlend-aasland
https://github.com/python/cpython/commit/d1b031cc58516e1aba823fd613528417a996f50d
commit: d1b031cc58516e1aba823fd613528417a996f50d
branch: main
author: Nikita Sobolev 
committer: erlend-aasland 
date: 2024-01-22T10:19:25+01:00
summary:

gh-114414: Assert PyType_GetModuleByDef result in _threadmodule (#114415)

files:
M Modules/_threadmodule.c

diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index afcf646e3bc19e..99f97eb6d0adcc 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -901,6 +901,7 @@ local_new(PyTypeObject *type, PyObject *args, PyObject *kw)
 }
 
 PyObject *module = PyType_GetModuleByDef(type, &thread_module);
+assert(module != NULL);
 thread_module_state *state = get_thread_state(module);
 
 localobject *self = (localobject *)type->tp_alloc(type, 0);
@@ -1042,6 +1043,7 @@ static int
 local_setattro(localobject *self, PyObject *name, PyObject *v)
 {
 PyObject *module = PyType_GetModuleByDef(Py_TYPE(self), &thread_module);
+assert(module != NULL);
 thread_module_state *state = get_thread_state(module);
 
 PyObject *ldict = _ldict(self, state);
@@ -1094,6 +1096,7 @@ static PyObject *
 local_getattro(localobject *self, PyObject *name)
 {
 PyObject *module = PyType_GetModuleByDef(Py_TYPE(self), &thread_module);
+assert(module != NULL);
 thread_module_state *state = get_thread_state(module);
 
 PyObject *ldict = _ldict(self, state);

___
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.11] gh-114115: Update documentation of array.array (GH-114117) (GH-114418)

2024-01-22 Thread serhiy-storchaka
https://github.com/python/cpython/commit/459726f6cde7867ee33a31f9fab250dc9d421367
commit: 459726f6cde7867ee33a31f9fab250dc9d421367
branch: 3.11
author: Serhiy Storchaka 
committer: serhiy-storchaka 
date: 2024-01-22T09:37:09Z
summary:

[3.11] gh-114115: Update documentation of array.array (GH-114117) (GH-114418)

(cherry picked from commit 650f9e4c94711ff49ea4e13bf800945a6147b7e0)

Co-authored-by: Hugo van Kemenade <[email protected]>

files:
M Doc/library/array.rst

diff --git a/Doc/library/array.rst b/Doc/library/array.rst
index d6cb8c623adbf1..788dd763ffb915 100644
--- a/Doc/library/array.rst
+++ b/Doc/library/array.rst
@@ -76,14 +76,16 @@ The module defines the following type:
 .. class:: array(typecode[, initializer])
 
A new array whose items are restricted by *typecode*, and initialized
-   from the optional *initializer* value, which must be a list, a
-   :term:`bytes-like object`, or iterable over elements of the
-   appropriate type.
+   from the optional *initializer* value, which must be a :class:`bytes`
+   or :class:`bytearray` object, a Unicode string, or iterable over elements
+   of the appropriate type.
 
-   If given a list or string, the initializer is passed to the new array's
-   :meth:`fromlist`, :meth:`frombytes`, or :meth:`fromunicode` method (see 
below)
-   to add initial items to the array.  Otherwise, the iterable initializer is
-   passed to the :meth:`extend` method.
+   If given a :class:`bytes` or :class:`bytearray` object, the initializer
+   is passed to the new array's :meth:`frombytes` method;
+   if given a Unicode string, the initializer is passed to the
+   :meth:`fromunicode` method;
+   otherwise, the initializer's iterator is passed to the :meth:`extend` method
+   to add initial items to the array.
 
Array objects support the ordinary sequence operations of indexing, slicing,
concatenation, and multiplication.  When using slice assignment, the 
assigned
@@ -149,10 +151,11 @@ The module defines the following type:
   must be the right type to be appended to the array.
 
 
-   .. method:: frombytes(s)
+   .. method:: frombytes(buffer)
 
-  Appends items from the string, interpreting the string as an array of 
machine
-  values (as if it had been read from a file using the :meth:`fromfile` 
method).
+  Appends items from the :term:`bytes-like object`, interpreting
+  its content as an array of machine values (as if it had been read
+  from a file using the :meth:`fromfile` method).
 
   .. versionadded:: 3.2
  :meth:`!fromstring` is renamed to :meth:`frombytes` for clarity.
@@ -174,9 +177,9 @@ The module defines the following type:
 
.. method:: fromunicode(s)
 
-  Extends this array with data from the given unicode string.  The array 
must
-  be a type ``'u'`` array; otherwise a :exc:`ValueError` is raised.  Use
-  ``array.frombytes(unicodestring.encode(enc))`` to append Unicode data to 
an
+  Extends this array with data from the given Unicode string.
+  The array must have type code ``'u'``; otherwise a :exc:`ValueError` is 
raised.
+  Use ``array.frombytes(unicodestring.encode(enc))`` to append Unicode 
data to an
   array of some other type.
 
 
@@ -236,23 +239,27 @@ The module defines the following type:
 
.. method:: tounicode()
 
-  Convert the array to a unicode string.  The array must be a type ``'u'`` 
array;
+  Convert the array to a Unicode string.  The array must have a type 
``'u'``;
   otherwise a :exc:`ValueError` is raised. Use 
``array.tobytes().decode(enc)`` to
-  obtain a unicode string from an array of some other type.
+  obtain a Unicode string from an array of some other type.
 
 
-When an array object is printed or converted to a string, it is represented as
-``array(typecode, initializer)``.  The *initializer* is omitted if the array is
-empty, otherwise it is a string if the *typecode* is ``'u'``, otherwise it is a
-list of numbers.  The string is guaranteed to be able to be converted back to 
an
+The string representation of array objects has the form
+``array(typecode, initializer)``.
+The *initializer* is omitted if the array is empty, otherwise it is
+a Unicode string if the *typecode* is ``'u'``, otherwise it is
+a list of numbers.
+The string representation is guaranteed to be able to be converted back to an
 array with the same type and value using :func:`eval`, so long as the
 :class:`~array.array` class has been imported using ``from array import 
array``.
+Variables ``inf`` and ``nan`` must also be defined if it contains
+corresponding floating point values.
 Examples::
 
array('l')
array('u', 'hello \u2641')
array('l', [1, 2, 3, 4, 5])
-   array('d', [1.0, 2.0, 3.14])
+   array('d', [1.0, 2.0, 3.14, -inf, nan])
 
 
 .. seealso::

___
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to python-checkins-le...@pytho

[Python-checkins] [3.12] gh-114115: Update documentation of array.array (GH-114117) (GH-114417)

2024-01-22 Thread serhiy-storchaka
https://github.com/python/cpython/commit/7da1750225807b40f951a1484d8f5feed3be0c71
commit: 7da1750225807b40f951a1484d8f5feed3be0c71
branch: 3.12
author: Serhiy Storchaka 
committer: serhiy-storchaka 
date: 2024-01-22T09:37:16Z
summary:

[3.12] gh-114115: Update documentation of array.array (GH-114117) (GH-114417)

(cherry picked from commit 650f9e4c94711ff49ea4e13bf800945a6147b7e0)

Co-authored-by: Hugo van Kemenade <[email protected]>

files:
M Doc/library/array.rst

diff --git a/Doc/library/array.rst b/Doc/library/array.rst
index d6cb8c623adbf1..788dd763ffb915 100644
--- a/Doc/library/array.rst
+++ b/Doc/library/array.rst
@@ -76,14 +76,16 @@ The module defines the following type:
 .. class:: array(typecode[, initializer])
 
A new array whose items are restricted by *typecode*, and initialized
-   from the optional *initializer* value, which must be a list, a
-   :term:`bytes-like object`, or iterable over elements of the
-   appropriate type.
+   from the optional *initializer* value, which must be a :class:`bytes`
+   or :class:`bytearray` object, a Unicode string, or iterable over elements
+   of the appropriate type.
 
-   If given a list or string, the initializer is passed to the new array's
-   :meth:`fromlist`, :meth:`frombytes`, or :meth:`fromunicode` method (see 
below)
-   to add initial items to the array.  Otherwise, the iterable initializer is
-   passed to the :meth:`extend` method.
+   If given a :class:`bytes` or :class:`bytearray` object, the initializer
+   is passed to the new array's :meth:`frombytes` method;
+   if given a Unicode string, the initializer is passed to the
+   :meth:`fromunicode` method;
+   otherwise, the initializer's iterator is passed to the :meth:`extend` method
+   to add initial items to the array.
 
Array objects support the ordinary sequence operations of indexing, slicing,
concatenation, and multiplication.  When using slice assignment, the 
assigned
@@ -149,10 +151,11 @@ The module defines the following type:
   must be the right type to be appended to the array.
 
 
-   .. method:: frombytes(s)
+   .. method:: frombytes(buffer)
 
-  Appends items from the string, interpreting the string as an array of 
machine
-  values (as if it had been read from a file using the :meth:`fromfile` 
method).
+  Appends items from the :term:`bytes-like object`, interpreting
+  its content as an array of machine values (as if it had been read
+  from a file using the :meth:`fromfile` method).
 
   .. versionadded:: 3.2
  :meth:`!fromstring` is renamed to :meth:`frombytes` for clarity.
@@ -174,9 +177,9 @@ The module defines the following type:
 
.. method:: fromunicode(s)
 
-  Extends this array with data from the given unicode string.  The array 
must
-  be a type ``'u'`` array; otherwise a :exc:`ValueError` is raised.  Use
-  ``array.frombytes(unicodestring.encode(enc))`` to append Unicode data to 
an
+  Extends this array with data from the given Unicode string.
+  The array must have type code ``'u'``; otherwise a :exc:`ValueError` is 
raised.
+  Use ``array.frombytes(unicodestring.encode(enc))`` to append Unicode 
data to an
   array of some other type.
 
 
@@ -236,23 +239,27 @@ The module defines the following type:
 
.. method:: tounicode()
 
-  Convert the array to a unicode string.  The array must be a type ``'u'`` 
array;
+  Convert the array to a Unicode string.  The array must have a type 
``'u'``;
   otherwise a :exc:`ValueError` is raised. Use 
``array.tobytes().decode(enc)`` to
-  obtain a unicode string from an array of some other type.
+  obtain a Unicode string from an array of some other type.
 
 
-When an array object is printed or converted to a string, it is represented as
-``array(typecode, initializer)``.  The *initializer* is omitted if the array is
-empty, otherwise it is a string if the *typecode* is ``'u'``, otherwise it is a
-list of numbers.  The string is guaranteed to be able to be converted back to 
an
+The string representation of array objects has the form
+``array(typecode, initializer)``.
+The *initializer* is omitted if the array is empty, otherwise it is
+a Unicode string if the *typecode* is ``'u'``, otherwise it is
+a list of numbers.
+The string representation is guaranteed to be able to be converted back to an
 array with the same type and value using :func:`eval`, so long as the
 :class:`~array.array` class has been imported using ``from array import 
array``.
+Variables ``inf`` and ``nan`` must also be defined if it contains
+corresponding floating point values.
 Examples::
 
array('l')
array('u', 'hello \u2641')
array('l', [1, 2, 3, 4, 5])
-   array('d', [1.0, 2.0, 3.14])
+   array('d', [1.0, 2.0, 3.14, -inf, nan])
 
 
 .. seealso::

___
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to python-checkins-le...@pytho

[Python-checkins] gh-113102: Fix typo in INSTRUMENTED_RESUME (GH-114349)

2024-01-22 Thread markshannon
https://github.com/python/cpython/commit/2f2ddabd1a02e3095b751100b94b529e4e0bcd20
commit: 2f2ddabd1a02e3095b751100b94b529e4e0bcd20
branch: main
author: Guido van Rossum 
committer: markshannon 
date: 2024-01-22T11:56:28Z
summary:

gh-113102: Fix typo in INSTRUMENTED_RESUME (GH-114349)

files:
M Python/bytecodes.c
M Python/generated_cases.c.h

diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index c48f0a17c60fb1..7674ff81f64cec 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -192,7 +192,7 @@ dummy_func(
 ERROR_IF(err, error);
 if (frame->instr_ptr != this_instr) {
 /* Instrumentation has jumped */
-next_instr = this_instr;
+next_instr = frame->instr_ptr;
 DISPATCH();
 }
 }
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index 68468728d44bf8..c4bb3aeec5e224 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -3156,7 +3156,7 @@
 if (err) goto error;
 if (frame->instr_ptr != this_instr) {
 /* Instrumentation has jumped */
-next_instr = this_instr;
+next_instr = frame->instr_ptr;
 DISPATCH();
 }
 }

___
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-113796: Add more validation checks in the csv.Dialect constructor (GH-113797)

2024-01-22 Thread serhiy-storchaka
https://github.com/python/cpython/commit/c8351a617b8970dbe0d3af721c6aea873019c466
commit: c8351a617b8970dbe0d3af721c6aea873019c466
branch: main
author: Serhiy Storchaka 
committer: serhiy-storchaka 
date: 2024-01-22T15:34:16+02:00
summary:

gh-113796: Add more validation checks in the csv.Dialect constructor (GH-113797)

ValueError is now raised if the same character is used in different roles.

files:
A Misc/NEWS.d/next/Library/2024-01-07-21-04-24.gh-issue-113796.6iNsCR.rst
M Lib/test/test_csv.py
M Modules/_csv.c

diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py
index 36da86e6a2c622..69fef5945ae66f 100644
--- a/Lib/test/test_csv.py
+++ b/Lib/test/test_csv.py
@@ -28,14 +28,20 @@ class Test_Csv(unittest.TestCase):
 in TestDialectRegistry.
 """
 def _test_arg_valid(self, ctor, arg):
+ctor(arg)
 self.assertRaises(TypeError, ctor)
 self.assertRaises(TypeError, ctor, None)
-self.assertRaises(TypeError, ctor, arg, bad_attr = 0)
-self.assertRaises(TypeError, ctor, arg, delimiter = 0)
-self.assertRaises(TypeError, ctor, arg, delimiter = 'XX')
+self.assertRaises(TypeError, ctor, arg, bad_attr=0)
+self.assertRaises(TypeError, ctor, arg, delimiter='')
+self.assertRaises(TypeError, ctor, arg, escapechar='')
+self.assertRaises(TypeError, ctor, arg, quotechar='')
+self.assertRaises(TypeError, ctor, arg, delimiter='^^')
+self.assertRaises(TypeError, ctor, arg, escapechar='^^')
+self.assertRaises(TypeError, ctor, arg, quotechar='^^')
 self.assertRaises(csv.Error, ctor, arg, 'foo')
 self.assertRaises(TypeError, ctor, arg, delimiter=None)
 self.assertRaises(TypeError, ctor, arg, delimiter=1)
+self.assertRaises(TypeError, ctor, arg, escapechar=1)
 self.assertRaises(TypeError, ctor, arg, quotechar=1)
 self.assertRaises(TypeError, ctor, arg, lineterminator=None)
 self.assertRaises(TypeError, ctor, arg, lineterminator=1)
@@ -46,6 +52,40 @@ def _test_arg_valid(self, ctor, arg):
   quoting=csv.QUOTE_ALL, quotechar=None)
 self.assertRaises(TypeError, ctor, arg,
   quoting=csv.QUOTE_NONE, quotechar='')
+self.assertRaises(ValueError, ctor, arg, delimiter='\n')
+self.assertRaises(ValueError, ctor, arg, escapechar='\n')
+self.assertRaises(ValueError, ctor, arg, quotechar='\n')
+self.assertRaises(ValueError, ctor, arg, delimiter='\r')
+self.assertRaises(ValueError, ctor, arg, escapechar='\r')
+self.assertRaises(ValueError, ctor, arg, quotechar='\r')
+ctor(arg, delimiter=' ')
+ctor(arg, escapechar=' ')
+ctor(arg, quotechar=' ')
+ctor(arg, delimiter='\t', skipinitialspace=True)
+ctor(arg, escapechar='\t', skipinitialspace=True)
+ctor(arg, quotechar='\t', skipinitialspace=True)
+self.assertRaises(ValueError, ctor, arg,
+  delimiter=' ', skipinitialspace=True)
+self.assertRaises(ValueError, ctor, arg,
+  escapechar=' ', skipinitialspace=True)
+self.assertRaises(ValueError, ctor, arg,
+  quotechar=' ', skipinitialspace=True)
+ctor(arg, delimiter='^')
+ctor(arg, escapechar='^')
+ctor(arg, quotechar='^')
+self.assertRaises(ValueError, ctor, arg, delimiter='^', escapechar='^')
+self.assertRaises(ValueError, ctor, arg, delimiter='^', quotechar='^')
+self.assertRaises(ValueError, ctor, arg, escapechar='^', quotechar='^')
+ctor(arg, delimiter='\x85')
+ctor(arg, escapechar='\x85')
+ctor(arg, quotechar='\x85')
+ctor(arg, lineterminator='\x85')
+self.assertRaises(ValueError, ctor, arg,
+  delimiter='\x85', lineterminator='\x85')
+self.assertRaises(ValueError, ctor, arg,
+  escapechar='\x85', lineterminator='\x85')
+self.assertRaises(ValueError, ctor, arg,
+  quotechar='\x85', lineterminator='\x85')
 
 def test_reader_arg_valid(self):
 self._test_arg_valid(csv.reader, [])
@@ -535,14 +575,6 @@ class unspecified():
 finally:
 csv.unregister_dialect('testC')
 
-def test_bad_dialect(self):
-# Unknown parameter
-self.assertRaises(TypeError, csv.reader, [], bad_attr = 0)
-# Bad values
-self.assertRaises(TypeError, csv.reader, [], delimiter = None)
-self.assertRaises(TypeError, csv.reader, [], quoting = -1)
-self.assertRaises(TypeError, csv.reader, [], quoting = 100)
-
 def test_copy(self):
 for name in csv.list_dialects():
 dialect = csv.get_dialect(name)
@@ -1088,10 +1120,15 @@ class mydialect(csv.Dialect):
  '"lineterminator" must be a string')
 
 def test_invalid_chars(self):
-def create_invalid(field_name, value):
+   

[Python-checkins] gh-108303: Move `smtpd` to `test.support` (#114368)

2024-01-22 Thread vstinner
https://github.com/python/cpython/commit/8f5e7d739f56a75022dfe8fa24675b6c7b321ab5
commit: 8f5e7d739f56a75022dfe8fa24675b6c7b321ab5
branch: main
author: Nikita Sobolev 
committer: vstinner 
date: 2024-01-22T14:36:29+01:00
summary:

gh-108303: Move `smtpd` to `test.support` (#114368)

Update test_logging.py and test_smtplib.py.

files:
A Lib/test/support/smtpd.py
D Lib/test/smtpd.py
M Lib/test/test_logging.py
M Lib/test/test_smtplib.py

diff --git a/Lib/test/smtpd.py b/Lib/test/support/smtpd.py
similarity index 100%
rename from Lib/test/smtpd.py
rename to Lib/test/support/smtpd.py
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index 0be26981184213..908e242b85f5e7 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -49,6 +49,7 @@
 from test.support import threading_helper
 from test.support import warnings_helper
 from test.support import asyncore
+from test.support import smtpd
 from test.support.logging_helper import TestHandler
 import textwrap
 import threading
@@ -63,9 +64,6 @@
 from socketserver import (ThreadingUDPServer, DatagramRequestHandler,
   ThreadingTCPServer, StreamRequestHandler)
 
-with warnings.catch_warnings():
-from . import smtpd
-
 try:
 import win32evtlog, win32evtlogutil, pywintypes
 except ImportError:
diff --git a/Lib/test/test_smtplib.py b/Lib/test/test_smtplib.py
index f2e02dab1c3ca5..4c9fc14bd43f54 100644
--- a/Lib/test/test_smtplib.py
+++ b/Lib/test/test_smtplib.py
@@ -22,10 +22,9 @@
 from test.support import socket_helper
 from test.support import threading_helper
 from test.support import asyncore
+from test.support import smtpd
 from unittest.mock import Mock
 
-from . import smtpd
-
 
 support.requires_working_socket(module=True)
 

___
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-103092: Ensure `_ctypes.c` static types are accessed via global state (#113857)

2024-01-22 Thread vstinner
https://github.com/python/cpython/commit/9f7176d360b5898003d5ca78bab1822ad67867c4
commit: 9f7176d360b5898003d5ca78bab1822ad67867c4
branch: main
author: neonene <[email protected]>
committer: vstinner 
date: 2024-01-22T14:40:36+01:00
summary:

gh-103092: Ensure `_ctypes.c` static types are accessed via global state 
(#113857)

files:
M Modules/_ctypes/_ctypes.c
M Modules/_ctypes/callbacks.c
M Modules/_ctypes/callproc.c
M Modules/_ctypes/cfield.c
M Modules/_ctypes/ctypes.h
M Modules/_ctypes/stgdict.c

diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index b51a03b5497fed..94245ae41afffc 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -128,15 +128,26 @@ bytes(cdata)
 
 #include "pycore_long.h"  // _PyLong_GetZero()
 
-ctypes_state global_state;
+static PyTypeObject Union_Type;
+static PyTypeObject Struct_Type;
+static PyTypeObject Simple_Type;
+
+ctypes_state global_state = {
+.PyCStgDict_Type = &PyCStgDict_Type,
+.PyCData_Type = &PyCData_Type,
+.Struct_Type = &Struct_Type,
+.Union_Type = &Union_Type,
+.PyCArray_Type = &PyCArray_Type,
+.Simple_Type = &Simple_Type,
+.PyCPointer_Type = &PyCPointer_Type,
+.PyCFuncPtr_Type = &PyCFuncPtr_Type,
+};
 
 PyObject *PyExc_ArgError = NULL;
 
 /* This dict maps ctypes types to POINTER types */
 PyObject *_ctypes_ptrtype_cache = NULL;
 
-static PyTypeObject Simple_Type;
-
 /* a callable object used for unpickling:
strong reference to _ctypes._unpickle() function */
 static PyObject *_unpickle;
@@ -521,14 +532,16 @@ StructUnionType_new(PyTypeObject *type, PyObject *args, 
PyObject *kwds, int isSt
 
 /* keep this for bw compatibility */
 int r = PyDict_Contains(result->tp_dict, &_Py_ID(_abstract_));
-if (r > 0)
+if (r > 0) {
 return (PyObject *)result;
+}
 if (r < 0) {
 Py_DECREF(result);
 return NULL;
 }
 
-dict = (StgDictObject *)_PyObject_CallNoArgs((PyObject *)&PyCStgDict_Type);
+ctypes_state *st = GLOBAL_STATE();
+dict = (StgDictObject *)_PyObject_CallNoArgs((PyObject 
*)st->PyCStgDict_Type);
 if (!dict) {
 Py_DECREF(result);
 return NULL;
@@ -568,8 +581,9 @@ StructUnionType_new(PyTypeObject *type, PyObject *args, 
PyObject *kwds, int isSt
 else {
 StgDictObject *basedict = PyType_stgdict((PyObject *)result->tp_base);
 
-if (basedict == NULL)
+if (basedict == NULL) {
 return (PyObject *)result;
+}
 /* copy base dict */
 if (-1 == PyCStgDict_clone(dict, basedict)) {
 Py_DECREF(result);
@@ -1023,16 +1037,19 @@ PyCPointerType_new(PyTypeObject *type, PyObject *args, 
PyObject *kwds)
 
 
 typedict = PyTuple_GetItem(args, 2);
-if (!typedict)
+if (!typedict) {
 return NULL;
+}
 /*
   stgdict items size, align, length contain info about pointers itself,
   stgdict->proto has info about the pointed to type!
 */
+ctypes_state *st = GLOBAL_STATE();
 stgdict = (StgDictObject *)_PyObject_CallNoArgs(
-(PyObject *)&PyCStgDict_Type);
-if (!stgdict)
+(PyObject *)st->PyCStgDict_Type);
+if (!stgdict) {
 return NULL;
+}
 stgdict->size = sizeof(void *);
 stgdict->align = _ctypes_get_fielddesc("P")->pffi_type->alignment;
 stgdict->length = 1;
@@ -1149,7 +1166,8 @@ PyCPointerType_from_param(PyObject *type, PyObject *value)
 break;
 }
 
-if (PointerObject_Check(value) || ArrayObject_Check(value)) {
+ctypes_state *st = GLOBAL_STATE();
+if (PointerObject_Check(st, value) || ArrayObject_Check(st, value)) {
 /* Array instances are also pointers when
the item types are the same.
 */
@@ -1448,11 +1466,12 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, 
PyObject *kwds)
 goto error;
 }
 
+ctypes_state *st = GLOBAL_STATE();
 stgdict = (StgDictObject *)_PyObject_CallNoArgs(
-(PyObject *)&PyCStgDict_Type);
-if (!stgdict)
+(PyObject *)st->PyCStgDict_Type);
+if (!stgdict) {
 goto error;
-
+}
 itemdict = PyType_stgdict(type_attr);
 if (!itemdict) {
 PyErr_SetString(PyExc_TypeError,
@@ -1587,7 +1606,8 @@ c_wchar_p_from_param(PyObject *type, PyObject *value)
 if (res) {
 return Py_NewRef(value);
 }
-if (ArrayObject_Check(value) || PointerObject_Check(value)) {
+ctypes_state *st = GLOBAL_STATE();
+if (ArrayObject_Check(st, value) || PointerObject_Check(st, value)) {
 /* c_wchar array instance or pointer(c_wchar(...)) */
 StgDictObject *dt = PyObject_stgdict(value);
 StgDictObject *dict;
@@ -1597,7 +1617,6 @@ c_wchar_p_from_param(PyObject *type, PyObject *value)
 return Py_NewRef(value);
 }
 }
-ctypes_state *st = GLOBAL_STATE();
 if (PyCArg_CheckExact(st, value)) {
 /* byref(c_char(...)) */
 PyCArgObject *a = (PyCArgObject *)value;
@@ -165

[Python-checkins] [3.12] gh-108303: Move `smtpd` to `test.support` (GH-114368) (#114427)

2024-01-22 Thread vstinner
https://github.com/python/cpython/commit/58fdd15d5a70b0274ed5d4fc491700138aa51cdf
commit: 58fdd15d5a70b0274ed5d4fc491700138aa51cdf
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: vstinner 
date: 2024-01-22T14:08:31Z
summary:

[3.12] gh-108303: Move `smtpd` to `test.support` (GH-114368) (#114427)

gh-108303: Move `smtpd` to `test.support` (GH-114368)

Update test_logging.py and test_smtplib.py.
(cherry picked from commit 8f5e7d739f56a75022dfe8fa24675b6c7b321ab5)

Co-authored-by: Nikita Sobolev 

files:
A Lib/test/support/smtpd.py
D Lib/test/smtpd.py
M Lib/test/test_logging.py
M Lib/test/test_smtplib.py

diff --git a/Lib/test/smtpd.py b/Lib/test/support/smtpd.py
similarity index 100%
rename from Lib/test/smtpd.py
rename to Lib/test/support/smtpd.py
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index 635dd7c26f6eed..d1ec2d6cf7a7d2 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -49,6 +49,7 @@
 from test.support import threading_helper
 from test.support import warnings_helper
 from test.support import asyncore
+from test.support import smtpd
 from test.support.logging_helper import TestHandler
 import textwrap
 import threading
@@ -63,9 +64,6 @@
 from socketserver import (ThreadingUDPServer, DatagramRequestHandler,
   ThreadingTCPServer, StreamRequestHandler)
 
-with warnings.catch_warnings():
-from . import smtpd
-
 try:
 import win32evtlog, win32evtlogutil, pywintypes
 except ImportError:
diff --git a/Lib/test/test_smtplib.py b/Lib/test/test_smtplib.py
index b6d5b8c3d82580..4d8e1438deb0f5 100644
--- a/Lib/test/test_smtplib.py
+++ b/Lib/test/test_smtplib.py
@@ -22,10 +22,9 @@
 from test.support import socket_helper
 from test.support import threading_helper
 from test.support import asyncore
+from test.support import smtpd
 from unittest.mock import Mock
 
-from . import smtpd
-
 
 support.requires_working_socket(module=True)
 

___
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-102512: Turn _DummyThread into _MainThread after os.fork() called from a foreign thread (GH-113261)

2024-01-22 Thread serhiy-storchaka
https://github.com/python/cpython/commit/49785b06ded19c7c4afce186bac90fea707470ea
commit: 49785b06ded19c7c4afce186bac90fea707470ea
branch: main
author: Serhiy Storchaka 
committer: serhiy-storchaka 
date: 2024-01-22T16:14:42+02:00
summary:

gh-102512: Turn _DummyThread into _MainThread after os.fork() called from a 
foreign thread (GH-113261)

Always set a _MainThread as a main thread after os.fork() is called from
a thread started not by the threading module.

A new _MainThread was already set as a new main thread after fork if
threading.current_thread() was not called for a foreign thread before fork.
Now, if it was called before fork, the implicitly created _DummyThread will
be turned into _MainThread after fork.

It fixes, in particularly, an incompatibility of _DummyThread with
the threading shutdown logic which relies on the main thread
having tstate_lock.

Co-authored-by: Marek Marczykowski-Górecki 

files:
A Misc/NEWS.d/next/Library/2023-03-08-00-02-30.gh-issue-102512.LiugDr.rst
M Lib/test/test_threading.py
M Lib/threading.py

diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index 3060af44fd7e3d..7160c53d691ba2 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -115,6 +115,7 @@ def tearDown(self):
 
 
 class ThreadTests(BaseTestCase):
+maxDiff = 
 
 @cpython_only
 def test_name(self):
@@ -676,19 +677,25 @@ def test_main_thread_after_fork(self):
 import os, threading
 from test import support
 
+ident = threading.get_ident()
 pid = os.fork()
 if pid == 0:
+print("current ident", threading.get_ident() == ident)
 main = threading.main_thread()
-print(main.name)
-print(main.ident == threading.current_thread().ident)
-print(main.ident == threading.get_ident())
+print("main", main.name)
+print("main ident", main.ident == ident)
+print("current is main", threading.current_thread() is main)
 else:
 support.wait_process(pid, exitcode=0)
 """
 _, out, err = assert_python_ok("-c", code)
 data = out.decode().replace('\r', '')
 self.assertEqual(err, b"")
-self.assertEqual(data, "MainThread\nTrue\nTrue\n")
+self.assertEqual(data,
+ "current ident True\n"
+ "main MainThread\n"
+ "main ident True\n"
+ "current is main True\n")
 
 @skip_unless_reliable_fork
 @unittest.skipUnless(hasattr(os, 'waitpid'), "test needs os.waitpid()")
@@ -698,15 +705,17 @@ def test_main_thread_after_fork_from_nonmain_thread(self):
 from test import support
 
 def func():
+ident = threading.get_ident()
 with warnings.catch_warnings(record=True) as ws:
 warnings.filterwarnings(
 "always", category=DeprecationWarning)
 pid = os.fork()
 if pid == 0:
+print("current ident", threading.get_ident() == ident)
 main = threading.main_thread()
-print(main.name)
-print(main.ident == threading.current_thread().ident)
-print(main.ident == threading.get_ident())
+print("main", main.name, type(main).__name__)
+print("main ident", main.ident == ident)
+print("current is main", threading.current_thread() is 
main)
 # stdout is fully buffered because not a tty,
 # we have to flush before exit.
 sys.stdout.flush()
@@ -722,7 +731,80 @@ def func():
 _, out, err = assert_python_ok("-c", code)
 data = out.decode().replace('\r', '')
 self.assertEqual(err.decode('utf-8'), "")
-self.assertEqual(data, "Thread-1 (func)\nTrue\nTrue\n")
+self.assertEqual(data,
+ "current ident True\n"
+ "main Thread-1 (func) Thread\n"
+ "main ident True\n"
+ "current is main True\n"
+ )
+
[email protected](sys.platform in platforms_to_skip, "due to known OS bug")
[email protected]_fork()
[email protected](hasattr(os, 'waitpid'), "test needs os.waitpid()")
+def test_main_thread_after_fork_from_foreign_thread(self, 
create_dummy=False):
+code = """if 1:
+import os, threading, sys, traceback, _thread
+from test import support
+
+def func(lock):
+ident = threading.get_ident()
+if %s:
+# call current_thread() before fork to allocate DummyThread
+current = threading.current_threa

[Python-checkins] [3.11] gh-102512: Turn _DummyThread into _MainThread after os.fork() called from a foreign thread (GH-113261) (GH-114431)

2024-01-22 Thread serhiy-storchaka
https://github.com/python/cpython/commit/a0f30b04fe3a54ffe4dbd39bd927fc45a0896f2d
commit: a0f30b04fe3a54ffe4dbd39bd927fc45a0896f2d
branch: 3.11
author: Serhiy Storchaka 
committer: serhiy-storchaka 
date: 2024-01-22T15:00:33Z
summary:

[3.11] gh-102512: Turn _DummyThread into _MainThread after os.fork() called 
from a foreign thread (GH-113261) (GH-114431)

Always set a _MainThread as a main thread after os.fork() is called from
a thread started not by the threading module.

A new _MainThread was already set as a new main thread after fork if
threading.current_thread() was not called for a foreign thread before fork.
Now, if it was called before fork, the implicitly created _DummyThread will
be turned into _MainThread after fork.

It fixes, in particularly, an incompatibility of _DummyThread with
the threading shutdown logic which relies on the main thread
having tstate_lock.

(cherry picked from commit 49785b06ded19c7c4afce186bac90fea707470ea)

Co-authored-by: Marek Marczykowski-Górecki 

files:
A Misc/NEWS.d/next/Library/2023-03-08-00-02-30.gh-issue-102512.LiugDr.rst
M Lib/test/test_threading.py
M Lib/threading.py

diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index 17319c366a483b..ec6a319486624a 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -106,6 +106,7 @@ def tearDown(self):
 
 
 class ThreadTests(BaseTestCase):
+maxDiff = 
 
 @cpython_only
 def test_name(self):
@@ -639,19 +640,25 @@ def test_main_thread_after_fork(self):
 import os, threading
 from test import support
 
+ident = threading.get_ident()
 pid = os.fork()
 if pid == 0:
+print("current ident", threading.get_ident() == ident)
 main = threading.main_thread()
-print(main.name)
-print(main.ident == threading.current_thread().ident)
-print(main.ident == threading.get_ident())
+print("main", main.name)
+print("main ident", main.ident == ident)
+print("current is main", threading.current_thread() is main)
 else:
 support.wait_process(pid, exitcode=0)
 """
 _, out, err = assert_python_ok("-c", code)
 data = out.decode().replace('\r', '')
 self.assertEqual(err, b"")
-self.assertEqual(data, "MainThread\nTrue\nTrue\n")
+self.assertEqual(data,
+ "current ident True\n"
+ "main MainThread\n"
+ "main ident True\n"
+ "current is main True\n")
 
 @skip_unless_reliable_fork
 @unittest.skipUnless(hasattr(os, 'waitpid'), "test needs os.waitpid()")
@@ -661,17 +668,17 @@ def test_main_thread_after_fork_from_nonmain_thread(self):
 from test import support
 
 def func():
+ident = threading.get_ident()
 pid = os.fork()
 if pid == 0:
+print("current ident", threading.get_ident() == ident)
 main = threading.main_thread()
-print(main.name)
-print(main.ident == threading.current_thread().ident)
-print(main.ident == threading.get_ident())
+print("main", main.name, type(main).__name__)
+print("main ident", main.ident == ident)
+print("current is main", threading.current_thread() is 
main)
 # stdout is fully buffered because not a tty,
 # we have to flush before exit.
 sys.stdout.flush()
-else:
-support.wait_process(pid, exitcode=0)
 
 th = threading.Thread(target=func)
 th.start()
@@ -679,8 +686,81 @@ def func():
 """
 _, out, err = assert_python_ok("-c", code)
 data = out.decode().replace('\r', '')
-self.assertEqual(err, b"")
-self.assertEqual(data, "Thread-1 (func)\nTrue\nTrue\n")
+self.assertEqual(err.decode('utf-8'), "")
+self.assertEqual(data,
+ "current ident True\n"
+ "main Thread-1 (func) Thread\n"
+ "main ident True\n"
+ "current is main True\n"
+ )
+
[email protected](sys.platform in platforms_to_skip, "due to known OS bug")
[email protected]_fork()
[email protected](hasattr(os, 'waitpid'), "test needs os.waitpid()")
+def test_main_thread_after_fork_from_foreign_thread(self, 
create_dummy=False):
+code = """if 1:
+import os, threading, sys, traceback, _thread
+from test import support
+
+def func(lock):
+ident = threading.get_ident()
+if %s:
+# call current_thread() before fork to allocate DummyThre

[Python-checkins] gh-108303: Remove `Lib/test/shadowed_super.py` (#114372)

2024-01-22 Thread vstinner
https://github.com/python/cpython/commit/2ef520ebecf5544ba792266a5dbe4d53653a4a03
commit: 2ef520ebecf5544ba792266a5dbe4d53653a4a03
branch: main
author: Nikita Sobolev 
committer: vstinner 
date: 2024-01-22T16:09:10+01:00
summary:

gh-108303: Remove `Lib/test/shadowed_super.py` (#114372)

Move code into Lib/test/test_super.py.

files:
D Lib/test/shadowed_super.py
M Lib/test/test_super.py

diff --git a/Lib/test/shadowed_super.py b/Lib/test/shadowed_super.py
deleted file mode 100644
index 2a62f667e93818..00
--- a/Lib/test/shadowed_super.py
+++ /dev/null
@@ -1,7 +0,0 @@
-class super:
-msg = "truly super"
-
-
-class C:
-def method(self):
-return super().msg
diff --git a/Lib/test/test_super.py b/Lib/test/test_super.py
index f8e968b9b56f82..256b416caaa584 100644
--- a/Lib/test/test_super.py
+++ b/Lib/test/test_super.py
@@ -1,8 +1,9 @@
 """Unit tests for zero-argument super() & related machinery."""
 
+import textwrap
 import unittest
 from unittest.mock import patch
-from test import shadowed_super
+from test.support import import_helper
 
 
 ADAPTIVE_WARMUP_DELAY = 2
@@ -342,7 +343,20 @@ def test_super_argtype(self):
 super(1, int)
 
 def test_shadowed_global(self):
+source = textwrap.dedent(
+"""
+class super:
+msg = "truly super"
+
+class C:
+def method(self):
+return super().msg
+""",
+)
+with import_helper.ready_to_import(name="shadowed_super", 
source=source):
+import shadowed_super
 self.assertEqual(shadowed_super.C().method(), "truly super")
+import_helper.unload("shadowed_super")
 
 def test_shadowed_local(self):
 class super:

___
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-111803: Make test_deep_nesting from test_plistlib more strict (GH-114026) (GH-114406)

2024-01-22 Thread serhiy-storchaka
https://github.com/python/cpython/commit/d1f731ff0839198fd22af539b6ef28d12739d4d8
commit: d1f731ff0839198fd22af539b6ef28d12739d4d8
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka 
date: 2024-01-22T17:16:12+02:00
summary:

[3.12] gh-111803: Make test_deep_nesting from test_plistlib more strict 
(GH-114026) (GH-114406)

It is no longer silently passed if RecursionError was raised for low
recursion depth.
(cherry picked from commit db1c18eb6220653290a3ba9ebbe1df44394a3f19)

Co-authored-by: Serhiy Storchaka 

files:
M Lib/test/test_plistlib.py

diff --git a/Lib/test/test_plistlib.py b/Lib/test/test_plistlib.py
index b08ababa341cfe..3f10f16d71996d 100644
--- a/Lib/test/test_plistlib.py
+++ b/Lib/test/test_plistlib.py
@@ -908,12 +908,13 @@ def test_cycles(self):
 self.assertIs(b['x'], b)
 
 def test_deep_nesting(self):
-for N in [300, 10]:
+tests = [50, 100_000] if support.is_wasi else [50, 300, 100_000]
+for N in tests:
 chunks = [b'\xa1' + (i + 1).to_bytes(4, 'big') for i in range(N)]
 try:
 result = self.decode(*chunks, b'\x54seed', offset_size=4, 
ref_size=4)
 except RecursionError:
-pass
+self.assertGreater(N, sys.getrecursionlimit()//2)
 else:
 for i in range(N):
 self.assertIsInstance(result, list)

___
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-102512: Turn _DummyThread into _MainThread after os.fork() called from a foreign thread (GH-113261) (GH-114430)

2024-01-22 Thread serhiy-storchaka
https://github.com/python/cpython/commit/1bd2c93474792dae99664a43cfb70120a809c05d
commit: 1bd2c93474792dae99664a43cfb70120a809c05d
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka 
date: 2024-01-22T15:24:43Z
summary:

[3.12] gh-102512: Turn _DummyThread into _MainThread after os.fork() called 
from a foreign thread (GH-113261) (GH-114430)

Always set a _MainThread as a main thread after os.fork() is called from
a thread started not by the threading module.

A new _MainThread was already set as a new main thread after fork if
threading.current_thread() was not called for a foreign thread before fork.
Now, if it was called before fork, the implicitly created _DummyThread will
be turned into _MainThread after fork.

It fixes, in particularly, an incompatibility of _DummyThread with
the threading shutdown logic which relies on the main thread
having tstate_lock.

(cherry picked from commit 49785b06ded19c7c4afce186bac90fea707470ea)

Co-authored-by: Serhiy Storchaka 
Co-authored-by: Marek Marczykowski-Górecki 

files:
A Misc/NEWS.d/next/Library/2023-03-08-00-02-30.gh-issue-102512.LiugDr.rst
M Lib/test/test_threading.py
M Lib/threading.py

diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index 756d5e329fc6d3..00d9e591c764ea 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -115,6 +115,7 @@ def tearDown(self):
 
 
 class ThreadTests(BaseTestCase):
+maxDiff = 
 
 @cpython_only
 def test_name(self):
@@ -627,19 +628,25 @@ def test_main_thread_after_fork(self):
 import os, threading
 from test import support
 
+ident = threading.get_ident()
 pid = os.fork()
 if pid == 0:
+print("current ident", threading.get_ident() == ident)
 main = threading.main_thread()
-print(main.name)
-print(main.ident == threading.current_thread().ident)
-print(main.ident == threading.get_ident())
+print("main", main.name)
+print("main ident", main.ident == ident)
+print("current is main", threading.current_thread() is main)
 else:
 support.wait_process(pid, exitcode=0)
 """
 _, out, err = assert_python_ok("-c", code)
 data = out.decode().replace('\r', '')
 self.assertEqual(err, b"")
-self.assertEqual(data, "MainThread\nTrue\nTrue\n")
+self.assertEqual(data,
+ "current ident True\n"
+ "main MainThread\n"
+ "main ident True\n"
+ "current is main True\n")
 
 @skip_unless_reliable_fork
 @unittest.skipUnless(hasattr(os, 'waitpid'), "test needs os.waitpid()")
@@ -649,15 +656,17 @@ def test_main_thread_after_fork_from_nonmain_thread(self):
 from test import support
 
 def func():
+ident = threading.get_ident()
 with warnings.catch_warnings(record=True) as ws:
 warnings.filterwarnings(
 "always", category=DeprecationWarning)
 pid = os.fork()
 if pid == 0:
+print("current ident", threading.get_ident() == ident)
 main = threading.main_thread()
-print(main.name)
-print(main.ident == threading.current_thread().ident)
-print(main.ident == threading.get_ident())
+print("main", main.name, type(main).__name__)
+print("main ident", main.ident == ident)
+print("current is main", threading.current_thread() is 
main)
 # stdout is fully buffered because not a tty,
 # we have to flush before exit.
 sys.stdout.flush()
@@ -673,7 +682,80 @@ def func():
 _, out, err = assert_python_ok("-c", code)
 data = out.decode().replace('\r', '')
 self.assertEqual(err.decode('utf-8'), "")
-self.assertEqual(data, "Thread-1 (func)\nTrue\nTrue\n")
+self.assertEqual(data,
+ "current ident True\n"
+ "main Thread-1 (func) Thread\n"
+ "main ident True\n"
+ "current is main True\n"
+ )
+
[email protected](sys.platform in platforms_to_skip, "due to known OS bug")
[email protected]_fork()
[email protected](hasattr(os, 'waitpid'), "test needs os.waitpid()")
+def test_main_thread_after_fork_from_foreign_thread(self, 
create_dummy=False):
+code = """if 1:
+import os, threading, sys, traceback, _thread
+from test import support
+
+def func(lock):
+ident = threading

[Python-checkins] [3.11] gh-111803: Make test_deep_nesting from test_plistlib more strict (GH-114026) (GH-114407)

2024-01-22 Thread serhiy-storchaka
https://github.com/python/cpython/commit/804037ee4a282be0c65698a94505cc8a45f327aa
commit: 804037ee4a282be0c65698a94505cc8a45f327aa
branch: 3.11
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka 
date: 2024-01-22T15:31:21Z
summary:

[3.11] gh-111803: Make test_deep_nesting from test_plistlib more strict 
(GH-114026) (GH-114407)

It is no longer silently passed if RecursionError was raised for low
recursion depth.
(cherry picked from commit db1c18eb6220653290a3ba9ebbe1df44394a3f19)

Co-authored-by: Serhiy Storchaka 

files:
M Lib/test/test_plistlib.py

diff --git a/Lib/test/test_plistlib.py b/Lib/test/test_plistlib.py
index 6b457440be5430..95b7a649774dca 100644
--- a/Lib/test/test_plistlib.py
+++ b/Lib/test/test_plistlib.py
@@ -908,12 +908,13 @@ def test_cycles(self):
 self.assertIs(b['x'], b)
 
 def test_deep_nesting(self):
-for N in [300, 10]:
+tests = [50, 100_000] if support.is_wasi else [50, 300, 100_000]
+for N in tests:
 chunks = [b'\xa1' + (i + 1).to_bytes(4, 'big') for i in range(N)]
 try:
 result = self.decode(*chunks, b'\x54seed', offset_size=4, 
ref_size=4)
 except RecursionError:
-pass
+self.assertGreater(N, sys.getrecursionlimit()//3)
 else:
 for i in range(N):
 self.assertIsInstance(result, list)

___
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-108303: Remove `Lib/test/shadowed_super.py` (GH-114372) (#114433)

2024-01-22 Thread vstinner
https://github.com/python/cpython/commit/954bbcc1b9daed3169719f6ca66302f164e362e1
commit: 954bbcc1b9daed3169719f6ca66302f164e362e1
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: vstinner 
date: 2024-01-22T16:40:42+01:00
summary:

[3.12] gh-108303: Remove `Lib/test/shadowed_super.py` (GH-114372) (#114433)

gh-108303: Remove `Lib/test/shadowed_super.py` (GH-114372)

Move code into Lib/test/test_super.py.
(cherry picked from commit 2ef520ebecf5544ba792266a5dbe4d53653a4a03)

Co-authored-by: Nikita Sobolev 

files:
D Lib/test/shadowed_super.py
M Lib/test/test_super.py

diff --git a/Lib/test/shadowed_super.py b/Lib/test/shadowed_super.py
deleted file mode 100644
index 2a62f667e93818..00
--- a/Lib/test/shadowed_super.py
+++ /dev/null
@@ -1,7 +0,0 @@
-class super:
-msg = "truly super"
-
-
-class C:
-def method(self):
-return super().msg
diff --git a/Lib/test/test_super.py b/Lib/test/test_super.py
index 43162c540b55ae..3ea01413c8e900 100644
--- a/Lib/test/test_super.py
+++ b/Lib/test/test_super.py
@@ -1,8 +1,9 @@
 """Unit tests for zero-argument super() & related machinery."""
 
+import textwrap
 import unittest
 from unittest.mock import patch
-from test import shadowed_super
+from test.support import import_helper
 
 
 ADAPTIVE_WARMUP_DELAY = 2
@@ -342,7 +343,20 @@ def test_super_argtype(self):
 super(1, int)
 
 def test_shadowed_global(self):
+source = textwrap.dedent(
+"""
+class super:
+msg = "truly super"
+
+class C:
+def method(self):
+return super().msg
+""",
+)
+with import_helper.ready_to_import(name="shadowed_super", 
source=source):
+import shadowed_super
 self.assertEqual(shadowed_super.C().method(), "truly super")
+import_helper.unload("shadowed_super")
 
 def test_shadowed_local(self):
 class super:

___
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] Docs: Fix typo in code snippet (GH-114421)

2024-01-22 Thread serhiy-storchaka
https://github.com/python/cpython/commit/6d30cbee013b4182937ffa11a7c87d2a7b6b7b41
commit: 6d30cbee013b4182937ffa11a7c87d2a7b6b7b41
branch: main
author: Kirill Podoprigora 
committer: serhiy-storchaka 
date: 2024-01-22T17:56:30+02:00
summary:

Docs: Fix typo in code snippet (GH-114421)

files:
M Doc/library/dis.rst

diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst
index 7492ae85c4ea46..b97d48fafab3b6 100644
--- a/Doc/library/dis.rst
+++ b/Doc/library/dis.rst
@@ -576,7 +576,7 @@ operations on it as if it was a Python list. The top of the 
stack corresponds to
 
Swap the top of the stack with the i-th element::
 
-  STACK[-i], STACK[-1] = stack[-1], STACK[-i]
+  STACK[-i], STACK[-1] = STACK[-1], STACK[-i]
 
.. versionadded:: 3.11
 

___
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] Docs: Fix typo in code snippet (GH-114421) (GH-114434)

2024-01-22 Thread serhiy-storchaka
https://github.com/python/cpython/commit/d705582f7377935301c45a4d112daca2a39d2f1c
commit: d705582f7377935301c45a4d112daca2a39d2f1c
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka 
date: 2024-01-22T16:03:22Z
summary:

[3.12] Docs: Fix typo in code snippet (GH-114421) (GH-114434)

(cherry picked from commit 6d30cbee013b4182937ffa11a7c87d2a7b6b7b41)

Co-authored-by: Kirill Podoprigora 

files:
M Doc/library/dis.rst

diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst
index ba7e13e2a19b8e..abcc3cde23526c 100644
--- a/Doc/library/dis.rst
+++ b/Doc/library/dis.rst
@@ -483,7 +483,7 @@ operations on it as if it was a Python list. The top of the 
stack corresponds to
 
Swap the top of the stack with the i-th element::
 
-  STACK[-i], STACK[-1] = stack[-1], STACK[-i]
+  STACK[-i], STACK[-1] = STACK[-1], STACK[-i]
 
.. versionadded:: 3.11
 

___
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-114321: Expose more constants in the fcntl module (GH-114322)

2024-01-22 Thread serhiy-storchaka
https://github.com/python/cpython/commit/1b719b39b9cd125258739699ac5168d139901b48
commit: 1b719b39b9cd125258739699ac5168d139901b48
branch: main
author: Serhiy Storchaka 
committer: serhiy-storchaka 
date: 2024-01-22T18:09:22+02:00
summary:

gh-114321: Expose more constants in the fcntl module (GH-114322)

files:
A Misc/NEWS.d/next/Library/2024-01-19-18-41-02.gh-issue-114321.yj_Xw3.rst
M Doc/library/fcntl.rst
M Modules/fcntlmodule.c

diff --git a/Doc/library/fcntl.rst b/Doc/library/fcntl.rst
index 309ad652d4af34..13ad2dd7da5090 100644
--- a/Doc/library/fcntl.rst
+++ b/Doc/library/fcntl.rst
@@ -31,26 +31,26 @@ descriptor.
raise an :exc:`OSError`.
 
 .. versionchanged:: 3.8
-   The fcntl module now contains ``F_ADD_SEALS``, ``F_GET_SEALS``, and
+   The :mod:`!fcntl` module now contains ``F_ADD_SEALS``, ``F_GET_SEALS``, and
``F_SEAL_*`` constants for sealing of :func:`os.memfd_create` file
descriptors.
 
 .. versionchanged:: 3.9
-   On macOS, the fcntl module exposes the ``F_GETPATH`` constant, which obtains
-   the path of a file from a file descriptor.
-   On Linux(>=3.15), the fcntl module exposes the ``F_OFD_GETLK``, 
``F_OFD_SETLK``
-   and ``F_OFD_SETLKW`` constants, which are used when working with open file
-   description locks.
+   On macOS, the :mod:`!fcntl` module exposes the ``F_GETPATH`` constant,
+   which obtains the path of a file from a file descriptor.
+   On Linux(>=3.15), the :mod:`!fcntl` module exposes the ``F_OFD_GETLK``,
+   ``F_OFD_SETLK`` and ``F_OFD_SETLKW`` constants, which are used when working
+   with open file description locks.
 
 .. versionchanged:: 3.10
-   On Linux >= 2.6.11, the fcntl module exposes the ``F_GETPIPE_SZ`` and
+   On Linux >= 2.6.11, the :mod:`!fcntl` module exposes the ``F_GETPIPE_SZ`` 
and
``F_SETPIPE_SZ`` constants, which allow to check and modify a pipe's size
respectively.
 
 .. versionchanged:: 3.11
-   On FreeBSD, the fcntl module exposes the ``F_DUP2FD`` and 
``F_DUP2FD_CLOEXEC``
-   constants, which allow to duplicate a file descriptor, the latter setting
-   ``FD_CLOEXEC`` flag in addition.
+   On FreeBSD, the :mod:`!fcntl` module exposes the ``F_DUP2FD`` and
+   ``F_DUP2FD_CLOEXEC`` constants, which allow to duplicate a file descriptor,
+   the latter setting ``FD_CLOEXEC`` flag in addition.
 
 .. versionchanged:: 3.12
On Linux >= 4.5, the :mod:`fcntl` module exposes the ``FICLONE`` and
@@ -58,6 +58,27 @@ descriptor.
another file by reflinking on some filesystems (e.g., btrfs, OCFS2, and
XFS). This behavior is commonly referred to as "copy-on-write".
 
+.. versionchanged:: 3.13
+   On Linux >= 2.6.32, the :mod:`!fcntl` module exposes the
+   ``F_GETOWN_EX``, ``F_SETOWN_EX``, ``F_OWNER_TID``, ``F_OWNER_PID``, 
``F_OWNER_PGRP`` constants, which allow to direct I/O availability signals
+   to a specific thread, process, or process group.
+   On Linux >= 4.13, the :mod:`!fcntl` module exposes the
+   ``F_GET_RW_HINT``, ``F_SET_RW_HINT``, ``F_GET_FILE_RW_HINT``,
+   ``F_SET_FILE_RW_HINT``, and ``RWH_WRITE_LIFE_*`` constants, which allow
+   to inform the kernel about the relative expected lifetime of writes on
+   a given inode or via a particular open file description.
+   On Linux >= 5.1 and NetBSD, the :mod:`!fcntl` module exposes the
+   ``F_SEAL_FUTURE_WRITE`` constant for use with ``F_ADD_SEALS`` and
+   ``F_GET_SEALS`` operations.
+   On FreeBSD, the :mod:`!fcntl` module exposes the ``F_READAHEAD``, 
``F_ISUNIONSTACK``, and ``F_KINFO`` constants.
+   On macOS and FreeBSD, the :mod:`!fcntl` module exposes the ``F_RDAHEAD``
+   constant.
+   On NetBSD and AIX, the :mod:`!fcntl` module exposes the ``F_CLOSEM``
+   constant.
+   On NetBSD, the :mod:`!fcntl` module exposes the ``F_MAXFD`` constant.
+   On macOS and NetBSD, the :mod:`!fcntl` module exposes the ``F_GETNOSIGPIPE``
+   and ``F_SETNOSIGPIPE`` constant.
+
 The module defines the following functions:
 
 
diff --git 
a/Misc/NEWS.d/next/Library/2024-01-19-18-41-02.gh-issue-114321.yj_Xw3.rst 
b/Misc/NEWS.d/next/Library/2024-01-19-18-41-02.gh-issue-114321.yj_Xw3.rst
new file mode 100644
index 00..dc2934bd81a42a
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-01-19-18-41-02.gh-issue-114321.yj_Xw3.rst
@@ -0,0 +1,2 @@
+Expose more platform specific constants in the :mod:`fcntl` module on Linux,
+macOS, FreeBSD and NetBSD.
diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c
index fd03abf0561da6..0d16602692b62d 100644
--- a/Modules/fcntlmodule.c
+++ b/Modules/fcntlmodule.c
@@ -583,6 +583,30 @@ all_ins(PyObject* m)
 #ifdef FICLONERANGE
 if (PyModule_AddIntMacro(m, FICLONERANGE)) return -1;
 #endif
+#ifdef F_GETOWN_EX
+// since Linux 2.6.32
+if (PyModule_AddIntMacro(m, F_GETOWN_EX)) return -1;
+if (PyModule_AddIntMacro(m, F_SETOWN_EX)) return -1;
+if (PyModule_AddIntMacro(m, F_OWNER_TID)) return -1;
+if (PyModule_AddIntMacro(m, F_OWNER_PID)) return -1;
+if (PyModule_AddIntMacro(m, F_OWNER_PGRP)) return -1;
+#endif
+#ifdef 

[Python-checkins] gh-101100: Fix Sphinx warnings in `reference/expressions.rst` (#114194)

2024-01-22 Thread hugovk
https://github.com/python/cpython/commit/8ccd1ba461b44ca078ab120559637bd3ffe22e50
commit: 8ccd1ba461b44ca078ab120559637bd3ffe22e50
branch: main
author: Hugo van Kemenade <[email protected]>
committer: hugovk <[email protected]>
date: 2024-01-22T18:21:14+02:00
summary:

gh-101100: Fix Sphinx warnings in `reference/expressions.rst` (#114194)

files:
M Doc/reference/expressions.rst
M Doc/tools/.nitignore

diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst
index e543c1228d4d19..87ebdc1ca1c9c6 100644
--- a/Doc/reference/expressions.rst
+++ b/Doc/reference/expressions.rst
@@ -1001,7 +1001,7 @@ but does not affect the semantics.
 
 The primary must evaluate to a callable object (user-defined functions, 
built-in
 functions, methods of built-in objects, class objects, methods of class
-instances, and all objects having a :meth:`__call__` method are callable).  All
+instances, and all objects having a :meth:`~object.__call__` method are 
callable).  All
 argument expressions are evaluated before the call is attempted.  Please refer
 to section :ref:`function` for the syntax of formal :term:`parameter` lists.
 
@@ -1159,7 +1159,7 @@ a class instance:
   pair: instance; call
   single: __call__() (object method)
 
-   The class must define a :meth:`__call__` method; the effect is then the 
same as
+   The class must define a :meth:`~object.__call__` method; the effect is then 
the same as
if that method was called.
 
 
@@ -1211,7 +1211,7 @@ Raising ``0.0`` to a negative power results in a 
:exc:`ZeroDivisionError`.
 Raising a negative number to a fractional power results in a :class:`complex`
 number. (In earlier versions it raised a :exc:`ValueError`.)
 
-This operation can be customized using the special :meth:`__pow__` method.
+This operation can be customized using the special :meth:`~object.__pow__` 
method.
 
 .. _unary:
 
@@ -1234,7 +1234,7 @@ All unary arithmetic and bitwise operations have the same 
priority:
single: - (minus); unary operator
 
 The unary ``-`` (minus) operator yields the negation of its numeric argument; 
the
-operation can be overridden with the :meth:`__neg__` special method.
+operation can be overridden with the :meth:`~object.__neg__` special method.
 
 .. index::
single: plus
@@ -1242,7 +1242,7 @@ operation can be overridden with the :meth:`__neg__` 
special method.
single: + (plus); unary operator
 
 The unary ``+`` (plus) operator yields its numeric argument unchanged; the
-operation can be overridden with the :meth:`__pos__` special method.
+operation can be overridden with the :meth:`~object.__pos__` special method.
 
 .. index::
single: inversion
@@ -1251,7 +1251,7 @@ operation can be overridden with the :meth:`__pos__` 
special method.
 The unary ``~`` (invert) operator yields the bitwise inversion of its integer
 argument.  The bitwise inversion of ``x`` is defined as ``-(x+1)``.  It only
 applies to integral numbers or to custom objects that override the
-:meth:`__invert__` special method.
+:meth:`~object.__invert__` special method.
 
 
 
@@ -1289,8 +1289,8 @@ the other must be a sequence. In the former case, the 
numbers are converted to a
 common type and then multiplied together.  In the latter case, sequence
 repetition is performed; a negative repetition factor yields an empty sequence.
 
-This operation can be customized using the special :meth:`__mul__` and
-:meth:`__rmul__` methods.
+This operation can be customized using the special :meth:`~object.__mul__` and
+:meth:`~object.__rmul__` methods.
 
 .. index::
single: matrix multiplication
@@ -1314,8 +1314,8 @@ integer; the result is that of mathematical division with 
the 'floor' function
 applied to the result.  Division by zero raises the :exc:`ZeroDivisionError`
 exception.
 
-This operation can be customized using the special :meth:`__truediv__` and
-:meth:`__floordiv__` methods.
+This operation can be customized using the special :meth:`~object.__truediv__` 
and
+:meth:`~object.__floordiv__` methods.
 
 .. index::
single: modulo
@@ -1340,7 +1340,7 @@ also overloaded by string objects to perform old-style 
string formatting (also
 known as interpolation).  The syntax for string formatting is described in the
 Python Library Reference, section :ref:`old-string-formatting`.
 
-The *modulo* operation can be customized using the special :meth:`__mod__` 
method.
+The *modulo* operation can be customized using the special 
:meth:`~object.__mod__` method.
 
 The floor division operator, the modulo operator, and the :func:`divmod`
 function are not defined for complex numbers.  Instead, convert to a floating
@@ -1356,8 +1356,8 @@ must either both be numbers or both be sequences of the 
same type.  In the
 former case, the numbers are converted to a common type and then added 
together.
 In the latter case, the sequences are concatenated.
 
-This operation can be customized using the special :meth:`__add__` and
-:meth:`__r

[Python-checkins] gh-75128: Ignore EADDRNOTAVAIL error in asyncio.BaseEventLoop.create_server() (GH-114420)

2024-01-22 Thread serhiy-storchaka
https://github.com/python/cpython/commit/a53e56e7d88b4f2a2943c9f191024198009fcf9e
commit: a53e56e7d88b4f2a2943c9f191024198009fcf9e
branch: main
author: Serhiy Storchaka 
committer: serhiy-storchaka 
date: 2024-01-22T18:40:35+02:00
summary:

gh-75128: Ignore EADDRNOTAVAIL error in asyncio.BaseEventLoop.create_server() 
(GH-114420)

Co-authored-by: Antoine Pitrou 

files:
A Misc/NEWS.d/next/Library/2024-01-22-12-10-34.gh-issue-75128.4FGlRS.rst
M Lib/asyncio/base_events.py

diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index a8870b636d1df5..c60d7688ef8c77 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -16,6 +16,7 @@
 import collections
 import collections.abc
 import concurrent.futures
+import errno
 import functools
 import heapq
 import itertools
@@ -1585,9 +1586,22 @@ async def create_server(
 try:
 sock.bind(sa)
 except OSError as err:
-raise OSError(err.errno, 'error while attempting '
-  'to bind on address %r: %s'
-  % (sa, err.strerror.lower())) from None
+msg = ('error while attempting '
+   'to bind on address %r: %s'
+   % (sa, err.strerror.lower()))
+if err.errno == errno.EADDRNOTAVAIL:
+# Assume the family is not enabled (bpo-30945)
+sockets.pop()
+sock.close()
+if self._debug:
+logger.warning(msg)
+continue
+raise OSError(err.errno, msg) from None
+
+if not sockets:
+raise OSError('could not bind on any address out of %r'
+  % ([info[4] for info in infos],))
+
 completed = True
 finally:
 if not completed:
diff --git 
a/Misc/NEWS.d/next/Library/2024-01-22-12-10-34.gh-issue-75128.4FGlRS.rst 
b/Misc/NEWS.d/next/Library/2024-01-22-12-10-34.gh-issue-75128.4FGlRS.rst
new file mode 100644
index 00..d875148e89b41b
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-01-22-12-10-34.gh-issue-75128.4FGlRS.rst
@@ -0,0 +1,2 @@
+Ignore an :exc:`OSError` in :meth:`asyncio.BaseEventLoop.create_server` when
+IPv6 is available but the interface cannot actually support it.

___
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-101100: Fix Sphinx warnings in `reference/expressions.rst` (GH-114194) (#114436)

2024-01-22 Thread hugovk
https://github.com/python/cpython/commit/f9979212f890708c1795119d7b8a5a06ceb4fba2
commit: f9979212f890708c1795119d7b8a5a06ceb4fba2
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: hugovk <[email protected]>
date: 2024-01-22T18:50:20+02:00
summary:

[3.12] gh-101100: Fix Sphinx warnings in `reference/expressions.rst` 
(GH-114194) (#114436)

Co-authored-by: Hugo van Kemenade <[email protected]>

files:
M Doc/reference/expressions.rst
M Doc/tools/.nitignore

diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst
index c30a97f3f2e7f6..9ce2589fb3281d 100644
--- a/Doc/reference/expressions.rst
+++ b/Doc/reference/expressions.rst
@@ -994,7 +994,7 @@ but does not affect the semantics.
 
 The primary must evaluate to a callable object (user-defined functions, 
built-in
 functions, methods of built-in objects, class objects, methods of class
-instances, and all objects having a :meth:`__call__` method are callable).  All
+instances, and all objects having a :meth:`~object.__call__` method are 
callable).  All
 argument expressions are evaluated before the call is attempted.  Please refer
 to section :ref:`function` for the syntax of formal :term:`parameter` lists.
 
@@ -1152,7 +1152,7 @@ a class instance:
   pair: instance; call
   single: __call__() (object method)
 
-   The class must define a :meth:`__call__` method; the effect is then the 
same as
+   The class must define a :meth:`~object.__call__` method; the effect is then 
the same as
if that method was called.
 
 
@@ -1204,7 +1204,7 @@ Raising ``0.0`` to a negative power results in a 
:exc:`ZeroDivisionError`.
 Raising a negative number to a fractional power results in a :class:`complex`
 number. (In earlier versions it raised a :exc:`ValueError`.)
 
-This operation can be customized using the special :meth:`__pow__` method.
+This operation can be customized using the special :meth:`~object.__pow__` 
method.
 
 .. _unary:
 
@@ -1227,7 +1227,7 @@ All unary arithmetic and bitwise operations have the same 
priority:
single: - (minus); unary operator
 
 The unary ``-`` (minus) operator yields the negation of its numeric argument; 
the
-operation can be overridden with the :meth:`__neg__` special method.
+operation can be overridden with the :meth:`~object.__neg__` special method.
 
 .. index::
single: plus
@@ -1235,7 +1235,7 @@ operation can be overridden with the :meth:`__neg__` 
special method.
single: + (plus); unary operator
 
 The unary ``+`` (plus) operator yields its numeric argument unchanged; the
-operation can be overridden with the :meth:`__pos__` special method.
+operation can be overridden with the :meth:`~object.__pos__` special method.
 
 .. index::
single: inversion
@@ -1244,7 +1244,7 @@ operation can be overridden with the :meth:`__pos__` 
special method.
 The unary ``~`` (invert) operator yields the bitwise inversion of its integer
 argument.  The bitwise inversion of ``x`` is defined as ``-(x+1)``.  It only
 applies to integral numbers or to custom objects that override the
-:meth:`__invert__` special method.
+:meth:`~object.__invert__` special method.
 
 
 
@@ -1282,8 +1282,8 @@ the other must be a sequence. In the former case, the 
numbers are converted to a
 common type and then multiplied together.  In the latter case, sequence
 repetition is performed; a negative repetition factor yields an empty sequence.
 
-This operation can be customized using the special :meth:`__mul__` and
-:meth:`__rmul__` methods.
+This operation can be customized using the special :meth:`~object.__mul__` and
+:meth:`~object.__rmul__` methods.
 
 .. index::
single: matrix multiplication
@@ -1307,8 +1307,8 @@ integer; the result is that of mathematical division with 
the 'floor' function
 applied to the result.  Division by zero raises the :exc:`ZeroDivisionError`
 exception.
 
-This operation can be customized using the special :meth:`__truediv__` and
-:meth:`__floordiv__` methods.
+This operation can be customized using the special :meth:`~object.__truediv__` 
and
+:meth:`~object.__floordiv__` methods.
 
 .. index::
single: modulo
@@ -1333,7 +1333,7 @@ also overloaded by string objects to perform old-style 
string formatting (also
 known as interpolation).  The syntax for string formatting is described in the
 Python Library Reference, section :ref:`old-string-formatting`.
 
-The *modulo* operation can be customized using the special :meth:`__mod__` 
method.
+The *modulo* operation can be customized using the special 
:meth:`~object.__mod__` method.
 
 The floor division operator, the modulo operator, and the :func:`divmod`
 function are not defined for complex numbers.  Instead, convert to a floating
@@ -1349,8 +1349,8 @@ must either both be numbers or both be sequences of the 
same type.  In the
 former case, the numbers are converted to a common type and then added 
together.
 In the latter case, the sequen

[Python-checkins] [3.11] gh-101100: Fix Sphinx warnings in `reference/expressions.rst` (GH-114194) (#114437)

2024-01-22 Thread hugovk
https://github.com/python/cpython/commit/350b4c7c0cfbc221597a66eeb657e481335ffe0b
commit: 350b4c7c0cfbc221597a66eeb657e481335ffe0b
branch: 3.11
author: Miss Islington (bot) <[email protected]>
committer: hugovk <[email protected]>
date: 2024-01-22T18:50:28+02:00
summary:

[3.11] gh-101100: Fix Sphinx warnings in `reference/expressions.rst` 
(GH-114194) (#114437)

Co-authored-by: Hugo van Kemenade <[email protected]>

files:
M Doc/reference/expressions.rst
M Doc/tools/.nitignore

diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst
index 05055b62498d91..1fec404260d20e 100644
--- a/Doc/reference/expressions.rst
+++ b/Doc/reference/expressions.rst
@@ -984,7 +984,7 @@ but does not affect the semantics.
 
 The primary must evaluate to a callable object (user-defined functions, 
built-in
 functions, methods of built-in objects, class objects, methods of class
-instances, and all objects having a :meth:`__call__` method are callable).  All
+instances, and all objects having a :meth:`~object.__call__` method are 
callable).  All
 argument expressions are evaluated before the call is attempted.  Please refer
 to section :ref:`function` for the syntax of formal :term:`parameter` lists.
 
@@ -1142,7 +1142,7 @@ a class instance:
   pair: instance; call
   single: __call__() (object method)
 
-   The class must define a :meth:`__call__` method; the effect is then the 
same as
+   The class must define a :meth:`~object.__call__` method; the effect is then 
the same as
if that method was called.
 
 
@@ -1194,7 +1194,7 @@ Raising ``0.0`` to a negative power results in a 
:exc:`ZeroDivisionError`.
 Raising a negative number to a fractional power results in a :class:`complex`
 number. (In earlier versions it raised a :exc:`ValueError`.)
 
-This operation can be customized using the special :meth:`__pow__` method.
+This operation can be customized using the special :meth:`~object.__pow__` 
method.
 
 .. _unary:
 
@@ -1217,7 +1217,7 @@ All unary arithmetic and bitwise operations have the same 
priority:
single: - (minus); unary operator
 
 The unary ``-`` (minus) operator yields the negation of its numeric argument; 
the
-operation can be overridden with the :meth:`__neg__` special method.
+operation can be overridden with the :meth:`~object.__neg__` special method.
 
 .. index::
single: plus
@@ -1225,7 +1225,7 @@ operation can be overridden with the :meth:`__neg__` 
special method.
single: + (plus); unary operator
 
 The unary ``+`` (plus) operator yields its numeric argument unchanged; the
-operation can be overridden with the :meth:`__pos__` special method.
+operation can be overridden with the :meth:`~object.__pos__` special method.
 
 .. index::
single: inversion
@@ -1234,7 +1234,7 @@ operation can be overridden with the :meth:`__pos__` 
special method.
 The unary ``~`` (invert) operator yields the bitwise inversion of its integer
 argument.  The bitwise inversion of ``x`` is defined as ``-(x+1)``.  It only
 applies to integral numbers or to custom objects that override the
-:meth:`__invert__` special method.
+:meth:`~object.__invert__` special method.
 
 
 
@@ -1272,8 +1272,8 @@ the other must be a sequence. In the former case, the 
numbers are converted to a
 common type and then multiplied together.  In the latter case, sequence
 repetition is performed; a negative repetition factor yields an empty sequence.
 
-This operation can be customized using the special :meth:`__mul__` and
-:meth:`__rmul__` methods.
+This operation can be customized using the special :meth:`~object.__mul__` and
+:meth:`~object.__rmul__` methods.
 
 .. index::
single: matrix multiplication
@@ -1297,8 +1297,8 @@ integer; the result is that of mathematical division with 
the 'floor' function
 applied to the result.  Division by zero raises the :exc:`ZeroDivisionError`
 exception.
 
-This operation can be customized using the special :meth:`__truediv__` and
-:meth:`__floordiv__` methods.
+This operation can be customized using the special :meth:`~object.__truediv__` 
and
+:meth:`~object.__floordiv__` methods.
 
 .. index::
single: modulo
@@ -1323,7 +1323,7 @@ also overloaded by string objects to perform old-style 
string formatting (also
 known as interpolation).  The syntax for string formatting is described in the
 Python Library Reference, section :ref:`old-string-formatting`.
 
-The *modulo* operation can be customized using the special :meth:`__mod__` 
method.
+The *modulo* operation can be customized using the special 
:meth:`~object.__mod__` method.
 
 The floor division operator, the modulo operator, and the :func:`divmod`
 function are not defined for complex numbers.  Instead, convert to a floating
@@ -1339,8 +1339,8 @@ must either both be numbers or both be sequences of the 
same type.  In the
 former case, the numbers are converted to a common type and then added 
together.
 In the latter case, the sequen

[Python-checkins] [3.12] gh-114275: Skip doctests that use `asyncio` in `test_pdb` for WASI builds (GH-114309) (#114439)

2024-01-22 Thread vstinner
https://github.com/python/cpython/commit/4890ac136b48eebb4d84fde55988b82d0220cfd0
commit: 4890ac136b48eebb4d84fde55988b82d0220cfd0
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: vstinner 
date: 2024-01-22T18:02:23+01:00
summary:

[3.12] gh-114275: Skip doctests that use `asyncio` in `test_pdb` for WASI 
builds (GH-114309) (#114439)

gh-114275: Skip doctests that use `asyncio` in `test_pdb` for WASI builds 
(GH-114309)
(cherry picked from commit efb81a60f5ce7e192095230a0f7ff9684d6f835a)

Co-authored-by: Nikita Sobolev 

files:
M Lib/test/test_pdb.py

diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index 514ed85f72e259..51b844262ed1e8 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -19,6 +19,9 @@
 from test.support.pty_helper import run_pty, FakeInput
 from unittest.mock import patch
 
+# gh-114275: WASI fails to run asyncio tests, similar skip than test_asyncio.
+SKIP_ASYNCIO_TESTS = (not support.has_socket_support)
+
 
 class PdbTestInput(object):
 """Context manager that makes testing Pdb in doctests easier."""
@@ -1180,122 +1183,123 @@ def test_pdb_next_command_for_generator():
 finished
 """
 
-def test_pdb_next_command_for_coroutine():
-"""Testing skip unwindng stack on yield for coroutines for "next" command
-
->>> import asyncio
-
->>> async def test_coro():
-... await asyncio.sleep(0)
-... await asyncio.sleep(0)
-... await asyncio.sleep(0)
-
->>> async def test_main():
-... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
-... await test_coro()
-
->>> def test_function():
-... loop = asyncio.new_event_loop()
-... loop.run_until_complete(test_main())
-... loop.close()
-... asyncio.set_event_loop_policy(None)
-... print("finished")
-
->>> with PdbTestInput(['step',
-...'step',
-...'next',
-...'next',
-...'next',
-...'step',
-...'continue']):
-... test_function()
-> (3)test_main()
--> await test_coro()
-(Pdb) step
---Call--
-> (1)test_coro()
--> async def test_coro():
-(Pdb) step
-> (2)test_coro()
--> await asyncio.sleep(0)
-(Pdb) next
-> (3)test_coro()
--> await asyncio.sleep(0)
-(Pdb) next
-> (4)test_coro()
--> await asyncio.sleep(0)
-(Pdb) next
-Internal StopIteration
-> (3)test_main()
--> await test_coro()
-(Pdb) step
---Return--
-> (3)test_main()->None
--> await test_coro()
-(Pdb) continue
-finished
-"""
-
-def test_pdb_next_command_for_asyncgen():
-"""Testing skip unwindng stack on yield for coroutines for "next" command
-
->>> import asyncio
-
->>> async def agen():
-... yield 1
-... await asyncio.sleep(0)
-... yield 2
-
->>> async def test_coro():
-... async for x in agen():
-... print(x)
-
->>> async def test_main():
-... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
-... await test_coro()
-
->>> def test_function():
-... loop = asyncio.new_event_loop()
-... loop.run_until_complete(test_main())
-... loop.close()
-... asyncio.set_event_loop_policy(None)
-... print("finished")
+if not SKIP_ASYNCIO_TESTS:
+def test_pdb_next_command_for_coroutine():
+"""Testing skip unwindng stack on yield for coroutines for "next" 
command
+
+>>> import asyncio
+
+>>> async def test_coro():
+... await asyncio.sleep(0)
+... await asyncio.sleep(0)
+... await asyncio.sleep(0)
+
+>>> async def test_main():
+... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
+... await test_coro()
+
+>>> def test_function():
+... loop = asyncio.new_event_loop()
+... loop.run_until_complete(test_main())
+... loop.close()
+... asyncio.set_event_loop_policy(None)
+... print("finished")
+
+>>> with PdbTestInput(['step',
+...'step',
+...'next',
+...'next',
+...'next',
+...'step',
+...'continue']):
+... test_function()
+> (3)test_main()
+-> await test_coro()
+(Pdb) step
+--Call--
+> (1)test_coro()
+-> async def test_coro():
+(Pdb) step
+> (2)test_coro()
+-> await asyncio.sleep(0)
+(Pdb) next
+> (3)test_coro()
+-> await asyncio.sleep(0)
+(Pdb) next
+> (4)test_coro()
+-> await asyncio.sleep(0)
+(Pdb) next
+Internal StopIteration
+> (3)test_main()
+ 

[Python-checkins] [3.11] gh-114275: Skip doctests that use `asyncio` in `test_pdb` for WASI builds (GH-114309) (#114438)

2024-01-22 Thread vstinner
https://github.com/python/cpython/commit/5b12f7d2bd1f992c7140518806471739b215d498
commit: 5b12f7d2bd1f992c7140518806471739b215d498
branch: 3.11
author: Miss Islington (bot) <[email protected]>
committer: vstinner 
date: 2024-01-22T18:02:16+01:00
summary:

[3.11] gh-114275: Skip doctests that use `asyncio` in `test_pdb` for WASI 
builds (GH-114309) (#114438)

gh-114275: Skip doctests that use `asyncio` in `test_pdb` for WASI builds 
(GH-114309)
(cherry picked from commit efb81a60f5ce7e192095230a0f7ff9684d6f835a)

Co-authored-by: Nikita Sobolev 

files:
M Lib/test/test_pdb.py

diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index 30ad8523d9b7d6..eed02737e8bd48 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -19,6 +19,9 @@
 from test.support.pty_helper import run_pty, FakeInput
 from unittest.mock import patch
 
+# gh-114275: WASI fails to run asyncio tests, similar skip than test_asyncio.
+SKIP_ASYNCIO_TESTS = (not support.has_socket_support)
+
 
 class PdbTestInput(object):
 """Context manager that makes testing Pdb in doctests easier."""
@@ -1071,122 +1074,123 @@ def test_pdb_next_command_for_generator():
 finished
 """
 
-def test_pdb_next_command_for_coroutine():
-"""Testing skip unwindng stack on yield for coroutines for "next" command
-
->>> import asyncio
-
->>> async def test_coro():
-... await asyncio.sleep(0)
-... await asyncio.sleep(0)
-... await asyncio.sleep(0)
-
->>> async def test_main():
-... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
-... await test_coro()
-
->>> def test_function():
-... loop = asyncio.new_event_loop()
-... loop.run_until_complete(test_main())
-... loop.close()
-... asyncio.set_event_loop_policy(None)
-... print("finished")
-
->>> with PdbTestInput(['step',
-...'step',
-...'next',
-...'next',
-...'next',
-...'step',
-...'continue']):
-... test_function()
-> (3)test_main()
--> await test_coro()
-(Pdb) step
---Call--
-> (1)test_coro()
--> async def test_coro():
-(Pdb) step
-> (2)test_coro()
--> await asyncio.sleep(0)
-(Pdb) next
-> (3)test_coro()
--> await asyncio.sleep(0)
-(Pdb) next
-> (4)test_coro()
--> await asyncio.sleep(0)
-(Pdb) next
-Internal StopIteration
-> (3)test_main()
--> await test_coro()
-(Pdb) step
---Return--
-> (3)test_main()->None
--> await test_coro()
-(Pdb) continue
-finished
-"""
-
-def test_pdb_next_command_for_asyncgen():
-"""Testing skip unwindng stack on yield for coroutines for "next" command
-
->>> import asyncio
-
->>> async def agen():
-... yield 1
-... await asyncio.sleep(0)
-... yield 2
-
->>> async def test_coro():
-... async for x in agen():
-... print(x)
-
->>> async def test_main():
-... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
-... await test_coro()
-
->>> def test_function():
-... loop = asyncio.new_event_loop()
-... loop.run_until_complete(test_main())
-... loop.close()
-... asyncio.set_event_loop_policy(None)
-... print("finished")
+if not SKIP_ASYNCIO_TESTS:
+def test_pdb_next_command_for_coroutine():
+"""Testing skip unwindng stack on yield for coroutines for "next" 
command
+
+>>> import asyncio
+
+>>> async def test_coro():
+... await asyncio.sleep(0)
+... await asyncio.sleep(0)
+... await asyncio.sleep(0)
+
+>>> async def test_main():
+... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
+... await test_coro()
+
+>>> def test_function():
+... loop = asyncio.new_event_loop()
+... loop.run_until_complete(test_main())
+... loop.close()
+... asyncio.set_event_loop_policy(None)
+... print("finished")
+
+>>> with PdbTestInput(['step',
+...'step',
+...'next',
+...'next',
+...'next',
+...'step',
+...'continue']):
+... test_function()
+> (3)test_main()
+-> await test_coro()
+(Pdb) step
+--Call--
+> (1)test_coro()
+-> async def test_coro():
+(Pdb) step
+> (2)test_coro()
+-> await asyncio.sleep(0)
+(Pdb) next
+> (3)test_coro()
+-> await asyncio.sleep(0)
+(Pdb) next
+> (4)test_coro()
+-> await asyncio.sleep(0)
+(Pdb) next
+Internal StopIteration
+> (3)test_main()
+ 

[Python-checkins] gh-114083: apply optimization of LOAD_CONST instructions to the whole CFG before optimize_basic_block. (#114408)

2024-01-22 Thread iritkatriel
https://github.com/python/cpython/commit/ed30a3c337f30abd2ea5357565a956ed3dc0719c
commit: ed30a3c337f30abd2ea5357565a956ed3dc0719c
branch: main
author: Irit Katriel <[email protected]>
committer: iritkatriel <[email protected]>
date: 2024-01-22T17:12:06Z
summary:

gh-114083: apply optimization of LOAD_CONST instructions to the whole CFG 
before optimize_basic_block. (#114408)

files:
A Misc/NEWS.d/next/Core and 
Builtins/2024-01-22-09-49-02.gh-issue-114083.hf1-ku.rst
M Lib/test/test_compile.py
M Python/flowgraph.c

diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 9c36f053314f9f..3b1ceceaa6305f 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -449,9 +449,17 @@ def 
test_condition_expression_with_dead_blocks_compiles(self):
 compile('if (5 if 5 else T): 0', '', 'exec')
 
 def test_condition_expression_with_redundant_comparisons_compiles(self):
-# See gh-113054
-with self.assertWarns(SyntaxWarning):
-compile('if 9<9<9and 9or 9:9', '', 'exec')
+# See gh-113054, gh-114083
+exprs = [
+'if 9<9<9and 9or 9:9',
+'if 9<9<9and 9or 9or 9:9',
+'if 9<9<9and 9or 9or 9or 9:9',
+'if 9<9<9and 9or 9or 9or 9or 9:9',
+]
+for expr in exprs:
+with self.subTest(expr=expr):
+with self.assertWarns(SyntaxWarning):
+compile(expr, '', 'exec')
 
 def test_dead_code_with_except_handler_compiles(self):
 compile(textwrap.dedent("""
diff --git a/Misc/NEWS.d/next/Core and 
Builtins/2024-01-22-09-49-02.gh-issue-114083.hf1-ku.rst b/Misc/NEWS.d/next/Core 
and Builtins/2024-01-22-09-49-02.gh-issue-114083.hf1-ku.rst
new file mode 100644
index 00..79be45e87b90d3
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and 
Builtins/2024-01-22-09-49-02.gh-issue-114083.hf1-ku.rst 
@@ -0,0 +1 @@
+Compiler applies folding of LOAD_CONST with following instruction in a 
separate pass before other optimisations. This enables jump threading in 
certain circumstances.
diff --git a/Python/flowgraph.c b/Python/flowgraph.c
index e84030c87b1b4b..2fc90b8877b475 100644
--- a/Python/flowgraph.c
+++ b/Python/flowgraph.c
@@ -472,14 +472,12 @@ next_nonempty_block(basicblock *b)
 /* debugging helpers */
 
 #ifndef NDEBUG
-static int remove_redundant_nops(basicblock *bb);
+static int remove_redundant_nops(cfg_builder *g);
 
 static bool
 no_redundant_nops(cfg_builder *g) {
-for (basicblock *b = g->g_entryblock; b != NULL; b = b->b_next) {
-if (remove_redundant_nops(b) != 0) {
-return false;
-}
+if (remove_redundant_nops(g) != 0) {
+return false;
 }
 return true;
 }
@@ -1003,7 +1001,7 @@ remove_unreachable(basicblock *entryblock) {
 }
 
 static int
-remove_redundant_nops(basicblock *bb) {
+basicblock_remove_redundant_nops(basicblock *bb) {
 /* Remove NOPs when legal to do so. */
 int dest = 0;
 int prev_lineno = -1;
@@ -1062,6 +1060,17 @@ remove_redundant_nops(basicblock *bb) {
 return num_removed;
 }
 
+static int
+remove_redundant_nops(cfg_builder *g) {
+int changes = 0;
+for (basicblock *b = g->g_entryblock; b != NULL; b = b->b_next) {
+int change = basicblock_remove_redundant_nops(b);
+RETURN_IF_ERROR(change);
+changes += change;
+}
+return changes;
+}
+
 static int
 remove_redundant_nops_and_pairs(basicblock *entryblock)
 {
@@ -1072,7 +1081,7 @@ remove_redundant_nops_and_pairs(basicblock *entryblock)
 cfg_instr *prev_instr = NULL;
 cfg_instr *instr = NULL;
 for (basicblock *b = entryblock; b != NULL; b = b->b_next) {
-remove_redundant_nops(b);
+RETURN_IF_ERROR(basicblock_remove_redundant_nops(b));
 if (IS_LABEL(b->b_label)) {
 /* this block is a jump target, forget instr */
 instr = NULL;
@@ -1112,8 +1121,11 @@ remove_redundant_jumps(cfg_builder *g) {
  * non-empty block reached through normal flow control is the target
  * of that jump. If it is, then the jump instruction is redundant and
  * can be deleted.
+ *
+ * Return the number of changes applied, or -1 on error.
  */
 
+int changes = 0;
 for (basicblock *b = g->g_entryblock; b != NULL; b = b->b_next) {
 cfg_instr *last = basicblock_last_instr(b);
 if (last == NULL) {
@@ -1128,17 +1140,19 @@ remove_redundant_jumps(cfg_builder *g) {
 }
 basicblock *next = next_nonempty_block(b->b_next);
 if (jump_target == next) {
-if (last->i_loc.lineno == NO_LOCATION.lineno) {
+changes++;
+if (last->i_loc_propagated) {
 b->b_iused--;
 }
 else {
+assert(last->i_loc.lineno != -1);
 INSTR_SET_OP0(last, NOP);
 }

[Python-checkins] [3.12] gh-75128: Ignore EADDRNOTAVAIL error in asyncio.BaseEventLoop.create_server() (GH-114420) (GH-114441)

2024-01-22 Thread serhiy-storchaka
https://github.com/python/cpython/commit/4bbb9f6f29e08d88ebc4965165b8aa1aec47f427
commit: 4bbb9f6f29e08d88ebc4965165b8aa1aec47f427
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka 
date: 2024-01-22T17:15:08Z
summary:

[3.12] gh-75128: Ignore EADDRNOTAVAIL error in 
asyncio.BaseEventLoop.create_server() (GH-114420) (GH-114441)

(cherry picked from commit a53e56e7d88b4f2a2943c9f191024198009fcf9e)

Co-authored-by: Serhiy Storchaka 
Co-authored-by: Antoine Pitrou 

files:
A Misc/NEWS.d/next/Library/2024-01-22-12-10-34.gh-issue-75128.4FGlRS.rst
M Lib/asyncio/base_events.py

diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index 5318a597e09ae7..06024cbb34d466 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -16,6 +16,7 @@
 import collections
 import collections.abc
 import concurrent.futures
+import errno
 import functools
 import heapq
 import itertools
@@ -1556,9 +1557,22 @@ async def create_server(
 try:
 sock.bind(sa)
 except OSError as err:
-raise OSError(err.errno, 'error while attempting '
-  'to bind on address %r: %s'
-  % (sa, err.strerror.lower())) from None
+msg = ('error while attempting '
+   'to bind on address %r: %s'
+   % (sa, err.strerror.lower()))
+if err.errno == errno.EADDRNOTAVAIL:
+# Assume the family is not enabled (bpo-30945)
+sockets.pop()
+sock.close()
+if self._debug:
+logger.warning(msg)
+continue
+raise OSError(err.errno, msg) from None
+
+if not sockets:
+raise OSError('could not bind on any address out of %r'
+  % ([info[4] for info in infos],))
+
 completed = True
 finally:
 if not completed:
diff --git 
a/Misc/NEWS.d/next/Library/2024-01-22-12-10-34.gh-issue-75128.4FGlRS.rst 
b/Misc/NEWS.d/next/Library/2024-01-22-12-10-34.gh-issue-75128.4FGlRS.rst
new file mode 100644
index 00..d875148e89b41b
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-01-22-12-10-34.gh-issue-75128.4FGlRS.rst
@@ -0,0 +1,2 @@
+Ignore an :exc:`OSError` in :meth:`asyncio.BaseEventLoop.create_server` when
+IPv6 is available but the interface cannot actually support it.

___
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-114257: Ignore the FileNotFound error in ctypes.util._is_elf() (GH-114394)

2024-01-22 Thread serhiy-storchaka
https://github.com/python/cpython/commit/7fc51c3f6b7b13f88480557ff14bdb1c049f9a37
commit: 7fc51c3f6b7b13f88480557ff14bdb1c049f9a37
branch: main
author: AN Long 
committer: serhiy-storchaka 
date: 2024-01-22T17:15:29Z
summary:

gh-114257: Ignore the FileNotFound error in ctypes.util._is_elf() (GH-114394)

files:
A Misc/NEWS.d/next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst
M Lib/ctypes/util.py
M Lib/test/test_ctypes/test_find.py

diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
index 0c2510e1619c8e..c550883e7c7d4b 100644
--- a/Lib/ctypes/util.py
+++ b/Lib/ctypes/util.py
@@ -96,8 +96,11 @@ def find_library(name):
 def _is_elf(filename):
 "Return True if the given file is an ELF file"
 elf_header = b'\x7fELF'
-with open(filename, 'br') as thefile:
-return thefile.read(4) == elf_header
+try:
+with open(filename, 'br') as thefile:
+return thefile.read(4) == elf_header
+except FileNotFoundError:
+return False
 
 def _findLib_gcc(name):
 # Run GCC's linker with the -t (aka --trace) option and examine the
diff --git a/Lib/test/test_ctypes/test_find.py 
b/Lib/test/test_ctypes/test_find.py
index 66ff23e72b5e10..7732ff37308848 100644
--- a/Lib/test/test_ctypes/test_find.py
+++ b/Lib/test/test_ctypes/test_find.py
@@ -125,6 +125,9 @@ def test_find_library_with_ld(self):
  unittest.mock.patch("ctypes.util._findLib_gcc", lambda *args: 
None):
 self.assertNotEqual(find_library('c'), None)
 
+def test_gh114257(self):
+self.assertIsNone(find_library("libc"))
+
 
 if __name__ == "__main__":
 unittest.main()
diff --git 
a/Misc/NEWS.d/next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst 
b/Misc/NEWS.d/next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst
new file mode 100644
index 00..6f02ff9e62617d
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst
@@ -0,0 +1,2 @@
+Dismiss the :exc:`FileNotFound` error in :func:`ctypes.util.find_library` and
+just return ``None`` on Linux.

___
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.11] gh-75128: Ignore EADDRNOTAVAIL error in asyncio.BaseEventLoop.create_server() (GH-114420) (GH-114442)

2024-01-22 Thread serhiy-storchaka
https://github.com/python/cpython/commit/acea9d8e879c15255a3b08f11729bb1ec6b9fbd6
commit: acea9d8e879c15255a3b08f11729bb1ec6b9fbd6
branch: 3.11
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka 
date: 2024-01-22T17:20:01Z
summary:

[3.11] gh-75128: Ignore EADDRNOTAVAIL error in 
asyncio.BaseEventLoop.create_server() (GH-114420) (GH-114442)

(cherry picked from commit a53e56e7d88b4f2a2943c9f191024198009fcf9e)

Co-authored-by: Serhiy Storchaka 
Co-authored-by: Antoine Pitrou 

files:
A Misc/NEWS.d/next/Library/2024-01-22-12-10-34.gh-issue-75128.4FGlRS.rst
M Lib/asyncio/base_events.py

diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index d4c8238ba5217f..c5dfc15729a734 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -16,6 +16,7 @@
 import collections
 import collections.abc
 import concurrent.futures
+import errno
 import functools
 import heapq
 import itertools
@@ -1522,9 +1523,22 @@ async def create_server(
 try:
 sock.bind(sa)
 except OSError as err:
-raise OSError(err.errno, 'error while attempting '
-  'to bind on address %r: %s'
-  % (sa, err.strerror.lower())) from None
+msg = ('error while attempting '
+   'to bind on address %r: %s'
+   % (sa, err.strerror.lower()))
+if err.errno == errno.EADDRNOTAVAIL:
+# Assume the family is not enabled (bpo-30945)
+sockets.pop()
+sock.close()
+if self._debug:
+logger.warning(msg)
+continue
+raise OSError(err.errno, msg) from None
+
+if not sockets:
+raise OSError('could not bind on any address out of %r'
+  % ([info[4] for info in infos],))
+
 completed = True
 finally:
 if not completed:
diff --git 
a/Misc/NEWS.d/next/Library/2024-01-22-12-10-34.gh-issue-75128.4FGlRS.rst 
b/Misc/NEWS.d/next/Library/2024-01-22-12-10-34.gh-issue-75128.4FGlRS.rst
new file mode 100644
index 00..d875148e89b41b
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-01-22-12-10-34.gh-issue-75128.4FGlRS.rst
@@ -0,0 +1,2 @@
+Ignore an :exc:`OSError` in :meth:`asyncio.BaseEventLoop.create_server` when
+IPv6 is available but the interface cannot actually support it.

___
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-114257: Ignore the FileNotFound error in ctypes.util._is_elf() (GH-114394) (GH-114444)

2024-01-22 Thread serhiy-storchaka
https://github.com/python/cpython/commit/ed567c1e1f27df507ca45478bdf9143b21ed06e1
commit: ed567c1e1f27df507ca45478bdf9143b21ed06e1
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka 
date: 2024-01-22T18:10:41Z
summary:

[3.12] gh-114257: Ignore the FileNotFound error in ctypes.util._is_elf() 
(GH-114394) (GH-11)

(cherry picked from commit 7fc51c3f6b7b13f88480557ff14bdb1c049f9a37)

Co-authored-by: AN Long 

files:
A Misc/NEWS.d/next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst
M Lib/ctypes/util.py
M Lib/test/test_ctypes/test_find.py

diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
index 0c2510e1619c8e..c550883e7c7d4b 100644
--- a/Lib/ctypes/util.py
+++ b/Lib/ctypes/util.py
@@ -96,8 +96,11 @@ def find_library(name):
 def _is_elf(filename):
 "Return True if the given file is an ELF file"
 elf_header = b'\x7fELF'
-with open(filename, 'br') as thefile:
-return thefile.read(4) == elf_header
+try:
+with open(filename, 'br') as thefile:
+return thefile.read(4) == elf_header
+except FileNotFoundError:
+return False
 
 def _findLib_gcc(name):
 # Run GCC's linker with the -t (aka --trace) option and examine the
diff --git a/Lib/test/test_ctypes/test_find.py 
b/Lib/test/test_ctypes/test_find.py
index 1ff9d019b138a4..a41e94971dfbab 100644
--- a/Lib/test/test_ctypes/test_find.py
+++ b/Lib/test/test_ctypes/test_find.py
@@ -122,6 +122,9 @@ def test_find_library_with_ld(self):
  unittest.mock.patch("ctypes.util._findLib_gcc", lambda *args: 
None):
 self.assertNotEqual(find_library('c'), None)
 
+def test_gh114257(self):
+self.assertIsNone(find_library("libc"))
+
 
 if __name__ == "__main__":
 unittest.main()
diff --git 
a/Misc/NEWS.d/next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst 
b/Misc/NEWS.d/next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst
new file mode 100644
index 00..6f02ff9e62617d
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst
@@ -0,0 +1,2 @@
+Dismiss the :exc:`FileNotFound` error in :func:`ctypes.util.find_library` and
+just return ``None`` on Linux.

___
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.11] gh-114257: Ignore the FileNotFound error in ctypes.util._is_elf() (GH-114394) (GH-114445)

2024-01-22 Thread serhiy-storchaka
https://github.com/python/cpython/commit/f5d9980217b2f36d095aa58a9b949b828f113082
commit: f5d9980217b2f36d095aa58a9b949b828f113082
branch: 3.11
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka 
date: 2024-01-22T18:10:44Z
summary:

[3.11] gh-114257: Ignore the FileNotFound error in ctypes.util._is_elf() 
(GH-114394) (GH-114445)

(cherry picked from commit 7fc51c3f6b7b13f88480557ff14bdb1c049f9a37)

Co-authored-by: AN Long 

files:
A Misc/NEWS.d/next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst
M Lib/ctypes/test/test_find.py
M Lib/ctypes/util.py

diff --git a/Lib/ctypes/test/test_find.py b/Lib/ctypes/test/test_find.py
index 1ff9d019b138a4..a41e94971dfbab 100644
--- a/Lib/ctypes/test/test_find.py
+++ b/Lib/ctypes/test/test_find.py
@@ -122,6 +122,9 @@ def test_find_library_with_ld(self):
  unittest.mock.patch("ctypes.util._findLib_gcc", lambda *args: 
None):
 self.assertNotEqual(find_library('c'), None)
 
+def test_gh114257(self):
+self.assertIsNone(find_library("libc"))
+
 
 if __name__ == "__main__":
 unittest.main()
diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
index 0c2510e1619c8e..c550883e7c7d4b 100644
--- a/Lib/ctypes/util.py
+++ b/Lib/ctypes/util.py
@@ -96,8 +96,11 @@ def find_library(name):
 def _is_elf(filename):
 "Return True if the given file is an ELF file"
 elf_header = b'\x7fELF'
-with open(filename, 'br') as thefile:
-return thefile.read(4) == elf_header
+try:
+with open(filename, 'br') as thefile:
+return thefile.read(4) == elf_header
+except FileNotFoundError:
+return False
 
 def _findLib_gcc(name):
 # Run GCC's linker with the -t (aka --trace) option and examine the
diff --git 
a/Misc/NEWS.d/next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst 
b/Misc/NEWS.d/next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst
new file mode 100644
index 00..6f02ff9e62617d
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst
@@ -0,0 +1,2 @@
+Dismiss the :exc:`FileNotFound` error in :func:`ctypes.util.find_library` and
+just return ``None`` on Linux.

___
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] Fix `wasi.py build` after adding the `clean` subcommand. ({GH-114447)

2024-01-22 Thread brettcannon
https://github.com/python/cpython/commit/5cd9c6b1fca549741828288febf9d5c13293847d
commit: 5cd9c6b1fca549741828288febf9d5c13293847d
branch: main
author: Brett Cannon 
committer: brettcannon 
date: 2024-01-22T10:28:57-08:00
summary:

Fix `wasi.py build` after adding the `clean` subcommand. ({GH-114447)

files:
M Tools/wasm/wasi.py

diff --git a/Tools/wasm/wasi.py b/Tools/wasm/wasi.py
index e71b0b302a5561..46ecae74a9ecea 100644
--- a/Tools/wasm/wasi.py
+++ b/Tools/wasm/wasi.py
@@ -68,7 +68,8 @@ def wrapper(context):
 terminal_width = 80
 print("⎯" * terminal_width)
 print("📁", working_dir)
-if clean_ok and context.clean and working_dir.exists():
+if (clean_ok and getattr(context, "clean", False) and
+working_dir.exists()):
 print(f"🚮 Deleting directory (--clean)...")
 shutil.rmtree(working_dir)
 

___
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-114448: Don't sort summarize_stats.py histograms by amount of change (GH-114449)

2024-01-22 Thread brandtbucher
https://github.com/python/cpython/commit/e45bae7a45e5696c3ebdf477ecc948374cf8ebff
commit: e45bae7a45e5696c3ebdf477ecc948374cf8ebff
branch: main
author: Michael Droettboom 
committer: brandtbucher 
date: 2024-01-22T11:45:15-08:00
summary:

GH-114448: Don't sort summarize_stats.py histograms by amount of change 
(GH-114449)

files:
M Tools/scripts/summarize_stats.py

diff --git a/Tools/scripts/summarize_stats.py b/Tools/scripts/summarize_stats.py
index df8a7fddfb8866..1e9dc07bae8981 100644
--- a/Tools/scripts/summarize_stats.py
+++ b/Tools/scripts/summarize_stats.py
@@ -460,8 +460,11 @@ class JoinMode(enum.Enum):
 # second column of each input table as a new column
 CHANGE = 1
 # Join using the first column as a key, indicating the change in the second
-# column of each input table as a ne column, and omit all other columns
+# column of each input table as a new column, and omit all other columns
 CHANGE_ONE_COLUMN = 2
+# Join using the first column as a key, and indicate the change as a new
+# column, but don't sort by the amount of change.
+CHANGE_NO_SORT = 3
 
 
 class Table:
@@ -484,7 +487,7 @@ def join_row(self, key: str, row_a: tuple, row_b: tuple) -> 
tuple:
 match self.join_mode:
 case JoinMode.SIMPLE:
 return (key, *row_a, *row_b)
-case JoinMode.CHANGE:
+case JoinMode.CHANGE | JoinMode.CHANGE_NO_SORT:
 return (key, *row_a, *row_b, DiffRatio(row_a[0], row_b[0]))
 case JoinMode.CHANGE_ONE_COLUMN:
 return (key, row_a[0], row_b[0], DiffRatio(row_a[0], row_b[0]))
@@ -497,7 +500,7 @@ def join_columns(self, columns: Columns) -> Columns:
 *("Base " + x for x in columns[1:]),
 *("Head " + x for x in columns[1:]),
 )
-case JoinMode.CHANGE:
+case JoinMode.CHANGE | JoinMode.CHANGE_NO_SORT:
 return (
 columns[0],
 *("Base " + x for x in columns[1:]),
@@ -1027,7 +1030,7 @@ def iter_optimization_tables(base_stats: Stats, 
head_stats: Stats | None = None)
 Table(
 ("Range", "Count:", "Ratio:"),
 calc_histogram_table(name, den),
-JoinMode.CHANGE,
+JoinMode.CHANGE_NO_SORT,
 )
 ],
 )

___
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-112532: Improve mimalloc page visiting (#114133)

2024-01-22 Thread DinoV
https://github.com/python/cpython/commit/412920a41efc6f3307e710d5ce61bfe00c0f3c11
commit: 412920a41efc6f3307e710d5ce61bfe00c0f3c11
branch: main
author: Sam Gross 
committer: DinoV 
date: 2024-01-22T13:10:21-08:00
summary:

gh-112532: Improve mimalloc page visiting (#114133)

This adds support for visiting abandoned pages in mimalloc and improves
the performance of the page visiting code. Abandoned pages contain
memory blocks from threads that have exited. At some point, they may be
later reclaimed by other threads. We still need to visit those pages in
the free-threaded GC because they contain live objects.

This also reduces the overhead of visiting mimalloc pages:

 * Special cases for full, empty, and pages containing only a single
   block.
 * Fix free_map to use one bit instead of one byte per block.
 * Use fast integer division by a constant algorithm when computing
   block offset from block size and index.

files:
M Include/internal/mimalloc/mimalloc/internal.h
M Objects/mimalloc/heap.c
M Objects/mimalloc/segment.c

diff --git a/Include/internal/mimalloc/mimalloc/internal.h 
b/Include/internal/mimalloc/mimalloc/internal.h
index 887bf26c956982..8af841cfdffc01 100644
--- a/Include/internal/mimalloc/mimalloc/internal.h
+++ b/Include/internal/mimalloc/mimalloc/internal.h
@@ -120,6 +120,8 @@ void   _mi_segment_page_free(mi_page_t* page, bool 
force, mi_segments_tld_t*
 void   _mi_segment_page_abandon(mi_page_t* page, mi_segments_tld_t* tld);
 bool   _mi_segment_try_reclaim_abandoned( mi_heap_t* heap, bool try_all, 
mi_segments_tld_t* tld);
 void   _mi_segment_thread_collect(mi_segments_tld_t* tld);
+bool   _mi_abandoned_pool_visit_blocks(mi_abandoned_pool_t* pool, uint8_t 
page_tag, bool visit_blocks, mi_block_visit_fun* visitor, void* arg);
+
 
 #if MI_HUGE_PAGE_ABANDON
 void   _mi_segment_huge_page_free(mi_segment_t* segment, mi_page_t* page, 
mi_block_t* block);
@@ -161,6 +163,8 @@ void   _mi_heap_collect_abandon(mi_heap_t* heap);
 void   _mi_heap_set_default_direct(mi_heap_t* heap);
 bool   _mi_heap_memid_is_suitable(mi_heap_t* heap, mi_memid_t memid);
 void   _mi_heap_unsafe_destroy_all(void);
+void   _mi_heap_area_init(mi_heap_area_t* area, mi_page_t* page);
+bool   _mi_heap_area_visit_blocks(const mi_heap_area_t* area, mi_page_t 
*page, mi_block_visit_fun* visitor, void* arg);
 
 // "stats.c"
 void   _mi_stats_done(mi_stats_t* stats);
diff --git a/Objects/mimalloc/heap.c b/Objects/mimalloc/heap.c
index 6468999a7d5766..164b28f0fab240 100644
--- a/Objects/mimalloc/heap.c
+++ b/Objects/mimalloc/heap.c
@@ -26,7 +26,7 @@ typedef bool (heap_page_visitor_fun)(mi_heap_t* heap, 
mi_page_queue_t* pq, mi_pa
 // Visit all pages in a heap; returns `false` if break was called.
 static bool mi_heap_visit_pages(mi_heap_t* heap, heap_page_visitor_fun* fn, 
void* arg1, void* arg2)
 {
-  if (heap==NULL || heap->page_count==0) return 0;
+  if (heap==NULL || heap->page_count==0) return true;
 
   // visit all pages
   #if MI_DEBUG>1
@@ -521,11 +521,20 @@ typedef struct mi_heap_area_ex_s {
   mi_page_t* page;
 } mi_heap_area_ex_t;
 
-static bool mi_heap_area_visit_blocks(const mi_heap_area_ex_t* xarea, 
mi_block_visit_fun* visitor, void* arg) {
-  mi_assert(xarea != NULL);
-  if (xarea==NULL) return true;
-  const mi_heap_area_t* area = &xarea->area;
-  mi_page_t* page = xarea->page;
+static void mi_fast_divisor(size_t divisor, size_t* magic, size_t* shift) {
+  mi_assert_internal(divisor > 0 && divisor <= UINT32_MAX);
+  *shift = MI_INTPTR_BITS - mi_clz(divisor - 1);
+  *magic = (size_t)(((1ULL << 32) * ((1ULL << *shift) - divisor)) / divisor + 
1);
+}
+
+static size_t mi_fast_divide(size_t n, size_t magic, size_t shift) {
+  mi_assert_internal(n <= UINT32_MAX);
+  return uint64_t) n * magic) >> 32) + n) >> shift;
+}
+
+bool _mi_heap_area_visit_blocks(const mi_heap_area_t* area, mi_page_t *page, 
mi_block_visit_fun* visitor, void* arg) {
+  mi_assert(area != NULL);
+  if (area==NULL) return true;
   mi_assert(page != NULL);
   if (page == NULL) return true;
 
@@ -537,17 +546,39 @@ static bool mi_heap_area_visit_blocks(const 
mi_heap_area_ex_t* xarea, mi_block_v
   const size_t ubsize = mi_page_usable_block_size(page); // without padding
   size_t   psize;
   uint8_t* pstart = _mi_page_start(_mi_page_segment(page), page, &psize);
+  mi_heap_t* heap = mi_page_heap(page);
 
   if (page->capacity == 1) {
 // optimize page with one block
 mi_assert_internal(page->used == 1 && page->free == NULL);
-return visitor(mi_page_heap(page), area, pstart, ubsize, arg);
+return visitor(heap, area, pstart, ubsize, arg);
+  }
+
+  if (page->used == page->capacity) {
+// optimize full pages
+uint8_t* block = pstart;
+for (size_t i = 0; i < page->capacity; i++) {
+if (!visitor(heap, area, block, ubsize, arg)) return false;
+block += bsize;
+}
+return true;
   }
 
   // create a bitmap of free blocks.
   #define MI_MAX_BLOCKS  

[Python-checkins] gh-113655: Revert extra stack reserve in PGO builds unless UseExtraStackReserve=true (GH-114263)

2024-01-22 Thread zooba
https://github.com/python/cpython/commit/665b8f365efc4e0063f764e20d3cad13635232f3
commit: 665b8f365efc4e0063f764e20d3cad13635232f3
branch: main
author: Steve Dower 
committer: zooba 
date: 2024-01-22T21:19:16Z
summary:

gh-113655: Revert extra stack reserve in PGO builds unless 
UseExtraStackReserve=true (GH-114263)

files:
M PCbuild/python.vcxproj
M PCbuild/pythonw.vcxproj

diff --git a/PCbuild/python.vcxproj b/PCbuild/python.vcxproj
index 1e5ab877488e4a..4a99ffc677c287 100644
--- a/PCbuild/python.vcxproj
+++ b/PCbuild/python.vcxproj
@@ -99,7 +99,7 @@
   1200
   1200
   
-  300
+  300
 
   
   
diff --git a/PCbuild/pythonw.vcxproj b/PCbuild/pythonw.vcxproj
index d6cf0c97dedb09..d08c210ef8a1dc 100644
--- a/PCbuild/pythonw.vcxproj
+++ b/PCbuild/pythonw.vcxproj
@@ -94,7 +94,7 @@
   1200
   1200
   
-  300
+  300
 
   
   

___
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] Docs: align usage of versionadded/versionchanged with recommended practice (#114409)

2024-01-22 Thread erlend-aasland
https://github.com/python/cpython/commit/1d7bddd9612bcbaaedbc837e2936de773e855411
commit: 1d7bddd9612bcbaaedbc837e2936de773e855411
branch: main
author: Erlend E. Aasland 
committer: erlend-aasland 
date: 2024-01-22T21:40:26Z
summary:

Docs: align usage of versionadded/versionchanged with recommended practice 
(#114409)

Co-authored-by: C.A.M. Gerlach 
Co-authored-by: Ezio Melotti 

files:
M Doc/library/argparse.rst
M Doc/library/asyncio-stream.rst
M Doc/library/bdb.rst
M Doc/library/concurrent.futures.rst
M Doc/library/configparser.rst
M Doc/library/datetime.rst
M Doc/library/difflib.rst
M Doc/library/email.policy.rst
M Doc/library/functions.rst
M Doc/library/functools.rst
M Doc/library/http.client.rst
M Doc/library/http.server.rst
M Doc/library/logging.config.rst
M Doc/library/logging.handlers.rst
M Doc/library/logging.rst
M Doc/library/multiprocessing.shared_memory.rst
M Doc/library/os.rst
M Doc/library/pdb.rst
M Doc/library/pickletools.rst
M Doc/library/shutil.rst
M Doc/library/subprocess.rst
M Doc/library/unittest.rst
M Doc/library/urllib.parse.rst
M Doc/library/venv.rst
M Doc/library/xml.etree.elementtree.rst
M Doc/library/xml.sax.utils.rst
M Doc/library/zipapp.rst
M Doc/library/zipfile.rst

diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst
index fbffa71d200735..1395d457f874b0 100644
--- a/Doc/library/argparse.rst
+++ b/Doc/library/argparse.rst
@@ -1936,8 +1936,8 @@ FileType objects
   >>> parser.parse_args(['-'])
   Namespace(infile=<_io.TextIOWrapper name='' encoding='UTF-8'>)
 
-   .. versionadded:: 3.4
-  The *encodings* and *errors* keyword arguments.
+   .. versionchanged:: 3.4
+  Added the *encodings* and *errors* parameters.
 
 
 Argument groups
diff --git a/Doc/library/asyncio-stream.rst b/Doc/library/asyncio-stream.rst
index 0736e783bbc8c8..3427da1b43caef 100644
--- a/Doc/library/asyncio-stream.rst
+++ b/Doc/library/asyncio-stream.rst
@@ -77,8 +77,8 @@ and work with streams:
.. versionchanged:: 3.7
   Added the *ssl_handshake_timeout* parameter.
 
-   .. versionadded:: 3.8
-  Added *happy_eyeballs_delay* and *interleave* parameters.
+   .. versionchanged:: 3.8
+  Added the *happy_eyeballs_delay* and *interleave* parameters.
 
.. versionchanged:: 3.10
   Removed the *loop* parameter.
diff --git a/Doc/library/bdb.rst b/Doc/library/bdb.rst
index 4ce5c9bcde38ff..52f0ca7c013482 100644
--- a/Doc/library/bdb.rst
+++ b/Doc/library/bdb.rst
@@ -132,8 +132,8 @@ The :mod:`bdb` module also defines two classes:
frame is considered to originate in a certain module is determined
by the ``__name__`` in the frame globals.
 
-   .. versionadded:: 3.1
-  The *skip* argument.
+   .. versionchanged:: 3.1
+  Added the *skip* parameter.
 
The following methods of :class:`Bdb` normally don't need to be overridden.
 
diff --git a/Doc/library/concurrent.futures.rst 
b/Doc/library/concurrent.futures.rst
index 760e1196d7cf9a..800c7f6739d8a3 100644
--- a/Doc/library/concurrent.futures.rst
+++ b/Doc/library/concurrent.futures.rst
@@ -171,8 +171,8 @@ And::
   should be higher than the number of workers
   for :class:`ProcessPoolExecutor`.
 
-   .. versionadded:: 3.6
-  The *thread_name_prefix* argument was added to allow users to
+   .. versionchanged:: 3.6
+  Added the *thread_name_prefix* parameter to allow users to
   control the :class:`threading.Thread` names for worker threads created by
   the pool for easier debugging.
 
diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst
index 0031737853e7b4..18e5bc20f3f690 100644
--- a/Doc/library/configparser.rst
+++ b/Doc/library/configparser.rst
@@ -1045,14 +1045,14 @@ ConfigParser Objects
  config.read(['site.cfg', os.path.expanduser('~/.myapp.cfg')],
  encoding='cp1250')
 
-  .. versionadded:: 3.2
- The *encoding* parameter.  Previously, all files were read using the
- default encoding for :func:`open`.
+  .. versionchanged:: 3.2
+ Added the *encoding* parameter.
+ Previously, all files were read using the default encoding for 
:func:`open`.
 
-  .. versionadded:: 3.6.1
+  .. versionchanged:: 3.6.1
  The *filenames* parameter accepts a :term:`path-like object`.
 
-  .. versionadded:: 3.7
+  .. versionchanged:: 3.7
  The *filenames* parameter accepts a :class:`bytes` object.
 
 
@@ -1291,9 +1291,9 @@ Exceptions
that is already present or in strict parsers when a section if found more
than once in a single input file, string or dictionary.
 
-   .. versionadded:: 3.2
-  Optional ``source`` and ``lineno`` attributes and arguments to
-  :meth:`!__init__` were added.
+   .. versionchanged:: 3.2
+  Added the optional *source* and *lineno* attributes and parameters to
+  :meth:`!__init__`.
 
 
 .. exception:: DuplicateOptionError
diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst
index 3674b4bd97d39d..b36f8c19cd6040 100644
--- a

[Python-checkins] Add me to codeowners for hashlib & multiprocessing (#114454)

2024-01-22 Thread gpshead
https://github.com/python/cpython/commit/57255236957573e73033d2d345028f5a676533a0
commit: 57255236957573e73033d2d345028f5a676533a0
branch: main
author: Gregory P. Smith 
committer: gpshead 
date: 2024-01-22T23:55:12Z
summary:

Add me to codeowners for hashlib & multiprocessing (#114454)

I already effectively own these. (multiprocessing reluctantly, but I've
spent enough time in the code of late, it is important, and and
championing some changes, so I may as well be looped in there).

files:
M .github/CODEOWNERS

diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index 8038206441ab9b..9587b3996a9ac2 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -50,13 +50,13 @@ Objects/exceptions.c  @iritkatriel
 Python/traceback.c@iritkatriel
 
 # Hashing
-**/*hashlib*  @tiran
-**/*pyhash*   @tiran
-**/*sha*  @tiran
-**/*md5*  @tiran
-**/*blake*@tiran
-/Modules/_blake2/**   @tiran
-/Modules/_sha3/** @tiran
+**/*hashlib*  @gpshead @tiran
+**/*pyhash*   @gpshead @tiran
+**/sha*   @gpshead @tiran
+Modules/md5*  @gpshead @tiran
+**/*blake*@gpshead @tiran
+Modules/_blake2/**@gpshead @tiran
+Modules/_hacl/**  @gpshead
 
 # logging
 **/*logging*  @vsajip
@@ -120,6 +120,9 @@ Lib/ast.py@isidentical
 /Lib/unittest/mock.py @cjw296
 /Lib/test/test_unittest/testmock/* @cjw296
 
+# multiprocessing
+**/*multiprocessing*  @gpshead
+
 # SQLite 3
 **/*sqlite*   @berkerpeksag @erlend-aasland
 

___
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] Docs: minor amendments to runpy.rst (#18416)

2024-01-22 Thread erlend-aasland
https://github.com/python/cpython/commit/647b6cc7f16c03535cede7e1748a58ab884135b2
commit: 647b6cc7f16c03535cede7e1748a58ab884135b2
branch: main
author: Géry Ogam 
committer: erlend-aasland 
date: 2024-01-23T00:00:26Z
summary:

Docs: minor amendments to runpy.rst (#18416)

- Add missing single quote in inline code
- Align parameter formatting with style guide recommendations
- Fix punctuation around parenthesised sentence

files:
M Doc/library/runpy.rst

diff --git a/Doc/library/runpy.rst b/Doc/library/runpy.rst
index 406b080b7be30f..f2cb595f495f6b 100644
--- a/Doc/library/runpy.rst
+++ b/Doc/library/runpy.rst
@@ -32,7 +32,7 @@ The :mod:`runpy` module provides two functions:
.. index::
   pair: module; __main__
 
-   Execute the code of the specified module and return the resulting module
+   Execute the code of the specified module and return the resulting module's
globals dictionary. The module's code is first located using the standard
import mechanism (refer to :pep:`302` for details) and then executed in a
fresh module namespace.
@@ -44,16 +44,16 @@ The :mod:`runpy` module provides two functions:
returned.
 
The optional dictionary argument *init_globals* may be used to pre-populate
-   the module's globals dictionary before the code is executed. The supplied
-   dictionary will not be modified. If any of the special global variables
-   below are defined in the supplied dictionary, those definitions are
+   the module's globals dictionary before the code is executed.
+   *init_globals* will not be modified. If any of the special global variables
+   below are defined in *init_globals*, those definitions are
overridden by :func:`run_module`.
 
The special global variables ``__name__``, ``__spec__``, ``__file__``,
``__cached__``, ``__loader__`` and ``__package__`` are set in the globals
-   dictionary before the module code is executed (Note that this is a
+   dictionary before the module code is executed. (Note that this is a
minimal set of variables - other variables may be set implicitly as an
-   interpreter implementation detail).
+   interpreter implementation detail.)
 
``__name__`` is set to *run_name* if this optional argument is not
:const:`None`, to ``mod_name + '.__main__'`` if the named module is a
@@ -61,7 +61,7 @@ The :mod:`runpy` module provides two functions:
 
``__spec__`` will be set appropriately for the *actually* imported
module (that is, ``__spec__.name`` will always be *mod_name* or
-   ``mod_name + '.__main__``, never *run_name*).
+   ``mod_name + '.__main__'``, never *run_name*).
 
``__file__``, ``__cached__``, ``__loader__`` and ``__package__`` are
:ref:`set as normal ` based on the module spec.
@@ -104,11 +104,11 @@ The :mod:`runpy` module provides two functions:
   pair: module; __main__
 
Execute the code at the named filesystem location and return the resulting
-   module globals dictionary. As with a script name supplied to the CPython
-   command line, the supplied path may refer to a Python source file, a
+   module's globals dictionary. As with a script name supplied to the CPython
+   command line, *file_path* may refer to a Python source file, a
compiled bytecode file or a valid :data:`sys.path` entry containing a
:mod:`__main__` module
-   (e.g. a zipfile containing a top-level ``__main__.py`` file).
+   (e.g. a zipfile containing a top-level :file:`__main__.py` file).
 
For a simple script, the specified code is simply executed in a fresh
module namespace. For a valid :data:`sys.path` entry (typically a zipfile or
@@ -119,26 +119,26 @@ The :mod:`runpy` module provides two functions:
there is no such module at the specified location.
 
The optional dictionary argument *init_globals* may be used to pre-populate
-   the module's globals dictionary before the code is executed. The supplied
-   dictionary will not be modified. If any of the special global variables
-   below are defined in the supplied dictionary, those definitions are
+   the module's globals dictionary before the code is executed.
+   *init_globals* will not be modified. If any of the special global variables
+   below are defined in *init_globals*, those definitions are
overridden by :func:`run_path`.
 
The special global variables ``__name__``, ``__spec__``, ``__file__``,
``__cached__``, ``__loader__`` and ``__package__`` are set in the globals
-   dictionary before the module code is executed (Note that this is a
+   dictionary before the module code is executed. (Note that this is a
minimal set of variables - other variables may be set implicitly as an
-   interpreter implementation detail).
+   interpreter implementation detail.)
 
``__name__`` is set to *run_name* if this optional argument is not
:const:`None` and to ``''`` otherwise.
 
-   If the supplied path directly references a script file (whether as source
-   or as precompiled byte code), then ``__file__`` will be s

[Python-checkins] gh-66944: Note that the `contextlib.closing` example is for illustrative purposes (#112198)

2024-01-22 Thread AA-Turner
https://github.com/python/cpython/commit/9af9ac153acb4198878ad81ef438aca2b808e45d
commit: 9af9ac153acb4198878ad81ef438aca2b808e45d
branch: main
author: Ville Skyttä 
committer: AA-Turner <[email protected]>
date: 2024-01-23T01:00:53Z
summary:

gh-66944: Note that the `contextlib.closing` example is for illustrative 
purposes (#112198)

Co-authored-by: Adam Turner <[email protected]>

files:
M Doc/library/contextlib.rst

diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst
index aab319cbe7405e..b73373bc2363fb 100644
--- a/Doc/library/contextlib.rst
+++ b/Doc/library/contextlib.rst
@@ -182,6 +182,14 @@ Functions and classes provided:
without needing to explicitly close ``page``.  Even if an error occurs,
``page.close()`` will be called when the :keyword:`with` block is exited.
 
+   .. note::
+
+  Most types managing resources support the :term:`context manager` 
protocol,
+  which closes *thing* on leaving the :keyword:`with` statment.
+  As such, :func:`!closing` is most useful for third party types that don't
+  support context managers.
+  This example is purely for illustration purposes,
+  as :func:`~urllib.request.urlopen` would normally be used in a context 
manager.
 
 .. function:: aclosing(thing)
 

___
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-99334: Explain that `PurePath.is_relative_to()` is purely lexical. (#114031)

2024-01-22 Thread barneygale
https://github.com/python/cpython/commit/3a61d24062aaa1e13ba794360b6c765d9a1f2b06
commit: 3a61d24062aaa1e13ba794360b6c765d9a1f2b06
branch: main
author: Barney Gale 
committer: barneygale 
date: 2024-01-23T01:06:44Z
summary:

GH-99334: Explain that `PurePath.is_relative_to()` is purely lexical. (#114031)

files:
M Doc/library/pathlib.rst

diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst
index b924f470e0be04..faff3bc5823cb4 100644
--- a/Doc/library/pathlib.rst
+++ b/Doc/library/pathlib.rst
@@ -515,6 +515,13 @@ Pure paths provide the following methods and properties:
   >>> p.is_relative_to('/usr')
   False
 
+   This method is string-based; it neither accesses the filesystem nor treats
+   "``..``" segments specially. The following code is equivalent:
+
+  >>> u = PurePath('/usr')
+  >>> u == p or u in p.parents
+  False
+
.. versionadded:: 3.9
 
.. deprecated-removed:: 3.12 3.14

___
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.11] gh-66944: Note that the `contextlib.closing` example is for illustrative purposes (GH-112198) (#114459)

2024-01-22 Thread AA-Turner
https://github.com/python/cpython/commit/dcda3aaa6a6c279579da4b96747dc7c3c8216715
commit: dcda3aaa6a6c279579da4b96747dc7c3c8216715
branch: 3.11
author: Miss Islington (bot) <[email protected]>
committer: AA-Turner <[email protected]>
date: 2024-01-23T01:07:14Z
summary:

[3.11] gh-66944: Note that the `contextlib.closing` example is for illustrative 
purposes (GH-112198) (#114459)

files:
M Doc/library/contextlib.rst

diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst
index c01112a0a85895..fd264883c6823c 100644
--- a/Doc/library/contextlib.rst
+++ b/Doc/library/contextlib.rst
@@ -182,6 +182,14 @@ Functions and classes provided:
without needing to explicitly close ``page``.  Even if an error occurs,
``page.close()`` will be called when the :keyword:`with` block is exited.
 
+   .. note::
+
+  Most types managing resources support the :term:`context manager` 
protocol,
+  which closes *thing* on leaving the :keyword:`with` statment.
+  As such, :func:`!closing` is most useful for third party types that don't
+  support context managers.
+  This example is purely for illustration purposes,
+  as :func:`~urllib.request.urlopen` would normally be used in a context 
manager.
 
 .. function:: aclosing(thing)
 

___
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-66944: Note that the `contextlib.closing` example is for illustrative purposes (GH-112198) (#114458)

2024-01-22 Thread AA-Turner
https://github.com/python/cpython/commit/536b66f8fa6f8374bd8083ff2ce6a5796791b45f
commit: 536b66f8fa6f8374bd8083ff2ce6a5796791b45f
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: AA-Turner <[email protected]>
date: 2024-01-23T01:07:34Z
summary:

[3.12] gh-66944: Note that the `contextlib.closing` example is for illustrative 
purposes (GH-112198) (#114458)

files:
M Doc/library/contextlib.rst

diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst
index aab319cbe7405e..b73373bc2363fb 100644
--- a/Doc/library/contextlib.rst
+++ b/Doc/library/contextlib.rst
@@ -182,6 +182,14 @@ Functions and classes provided:
without needing to explicitly close ``page``.  Even if an error occurs,
``page.close()`` will be called when the :keyword:`with` block is exited.
 
+   .. note::
+
+  Most types managing resources support the :term:`context manager` 
protocol,
+  which closes *thing* on leaving the :keyword:`with` statment.
+  As such, :func:`!closing` is most useful for third party types that don't
+  support context managers.
+  This example is purely for illustration purposes,
+  as :func:`~urllib.request.urlopen` would normally be used in a context 
manager.
 
 .. function:: aclosing(thing)
 

___
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-99334: Explain that `PurePath.is_relative_to()` is purely lexical. (GH-114031) (#114460)

2024-01-22 Thread barneygale
https://github.com/python/cpython/commit/a199ab3f333a2e0bab37db935030f835c0740d08
commit: a199ab3f333a2e0bab37db935030f835c0740d08
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: barneygale 
date: 2024-01-23T01:12:59Z
summary:

[3.12] GH-99334: Explain that `PurePath.is_relative_to()` is purely lexical. 
(GH-114031) (#114460)

(cherry picked from commit 3a61d24062aaa1e13ba794360b6c765d9a1f2b06)

files:
M Doc/library/pathlib.rst

diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst
index 46a4d10b11d602..701131b5b2ec46 100644
--- a/Doc/library/pathlib.rst
+++ b/Doc/library/pathlib.rst
@@ -509,6 +509,13 @@ Pure paths provide the following methods and properties:
   >>> p.is_relative_to('/usr')
   False
 
+   This method is string-based; it neither accesses the filesystem nor treats
+   "``..``" segments specially. The following code is equivalent:
+
+  >>> u = PurePath('/usr')
+  >>> u == p or u in p.parents
+  False
+
.. versionadded:: 3.9
 
.. deprecated-removed:: 3.12 3.14

___
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.11] GH-99334: Explain that `PurePath.is_relative_to()` is purely lexical. (GH-114031) (#114461)

2024-01-22 Thread barneygale
https://github.com/python/cpython/commit/20f3669ac2f989646f0e9ba42b3f658febb334c7
commit: 20f3669ac2f989646f0e9ba42b3f658febb334c7
branch: 3.11
author: Barney Gale 
committer: barneygale 
date: 2024-01-23T01:16:21Z
summary:

[3.11] GH-99334: Explain that `PurePath.is_relative_to()` is purely lexical. 
(GH-114031) (#114461)

(cherry picked from commit 3a61d24062aaa1e13ba794360b6c765d9a1f2b06)

files:
M Doc/library/pathlib.rst

diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst
index 2d35285c12bd31..283e324a7f1b05 100644
--- a/Doc/library/pathlib.rst
+++ b/Doc/library/pathlib.rst
@@ -510,6 +510,13 @@ Pure paths provide the following methods and properties:
 
If multiple arguments are supplied, they are joined together.
 
+   This method is string-based; it neither accesses the filesystem nor treats
+   "``..``" segments specially. The following code is equivalent:
+
+  >>> u = PurePath('/usr')
+  >>> u == p or u in p.parents
+  False
+
.. versionadded:: 3.9
 
 

___
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-82695: Clarify `pathlib.Path.mkdir()` documentation (#114032)

2024-01-22 Thread barneygale
https://github.com/python/cpython/commit/32c227470aa6f72950b76206ffc529c258b4b8fa
commit: 32c227470aa6f72950b76206ffc529c258b4b8fa
branch: main
author: Barney Gale 
committer: barneygale 
date: 2024-01-23T02:31:09Z
summary:

GH-82695: Clarify `pathlib.Path.mkdir()` documentation (#114032)

Remove a double negative in the documentation of `mkdir()`'s *exist_ok*
parameter.

Co-authored-by: Adam Turner <[email protected]>

files:
M Doc/library/pathlib.rst

diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst
index faff3bc5823cb4..a6d99d4a64f801 100644
--- a/Doc/library/pathlib.rst
+++ b/Doc/library/pathlib.rst
@@ -1306,9 +1306,9 @@ call fails (for example because the path doesn't exist).
If *exist_ok* is false (the default), :exc:`FileExistsError` is
raised if the target directory already exists.
 
-   If *exist_ok* is true, :exc:`FileExistsError` exceptions will be
-   ignored (same behavior as the POSIX ``mkdir -p`` command), but only if the
-   last path component is not an existing non-directory file.
+   If *exist_ok* is true, :exc:`FileExistsError` will not be raised unless the 
given
+   path already exists in the file system and is not a directory (same
+   behavior as the POSIX ``mkdir -p`` command).
 
.. versionchanged:: 3.5
   The *exist_ok* parameter was added.

___
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-82695: Clarify `pathlib.Path.mkdir()` documentation (GH-114032) (#114462)

2024-01-22 Thread barneygale
https://github.com/python/cpython/commit/9c2db5725ee736222af519cc9deb68a0dec1a4c2
commit: 9c2db5725ee736222af519cc9deb68a0dec1a4c2
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: barneygale 
date: 2024-01-23T02:37:35Z
summary:

[3.12] GH-82695: Clarify `pathlib.Path.mkdir()` documentation (GH-114032) 
(#114462)

Remove a double negative in the documentation of `mkdir()`'s *exist_ok*
parameter.

(cherry picked from commit 32c227470aa6f72950b76206ffc529c258b4b8fa)

Co-authored-by: Barney Gale 
Co-authored-by: Adam Turner <[email protected]>

files:
M Doc/library/pathlib.rst

diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst
index 701131b5b2ec46..345a974dcb10bd 100644
--- a/Doc/library/pathlib.rst
+++ b/Doc/library/pathlib.rst
@@ -1184,9 +1184,9 @@ call fails (for example because the path doesn't exist).
If *exist_ok* is false (the default), :exc:`FileExistsError` is
raised if the target directory already exists.
 
-   If *exist_ok* is true, :exc:`FileExistsError` exceptions will be
-   ignored (same behavior as the POSIX ``mkdir -p`` command), but only if the
-   last path component is not an existing non-directory file.
+   If *exist_ok* is true, :exc:`FileExistsError` will not be raised unless the 
given
+   path already exists in the file system and is not a directory (same
+   behavior as the POSIX ``mkdir -p`` command).
 
.. versionchanged:: 3.5
   The *exist_ok* parameter was added.

___
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.11] GH-82695: Clarify `pathlib.Path.mkdir()` documentation (GH-114032) (#114463)

2024-01-22 Thread barneygale
https://github.com/python/cpython/commit/9d2ad6f24a0801d58ab47c5d07907adf260a3436
commit: 9d2ad6f24a0801d58ab47c5d07907adf260a3436
branch: 3.11
author: Miss Islington (bot) <[email protected]>
committer: barneygale 
date: 2024-01-23T02:37:55Z
summary:

[3.11] GH-82695: Clarify `pathlib.Path.mkdir()` documentation (GH-114032) 
(#114463)

Remove a double negative in the documentation of `mkdir()`'s *exist_ok*
parameter.

(cherry picked from commit 32c227470aa6f72950b76206ffc529c258b4b8fa)

Co-authored-by: Barney Gale 
Co-authored-by: Adam Turner <[email protected]>

files:
M Doc/library/pathlib.rst

diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst
index 283e324a7f1b05..528236cfa7eaa6 100644
--- a/Doc/library/pathlib.rst
+++ b/Doc/library/pathlib.rst
@@ -994,9 +994,9 @@ call fails (for example because the path doesn't exist).
If *exist_ok* is false (the default), :exc:`FileExistsError` is
raised if the target directory already exists.
 
-   If *exist_ok* is true, :exc:`FileExistsError` exceptions will be
-   ignored (same behavior as the POSIX ``mkdir -p`` command), but only if the
-   last path component is not an existing non-directory file.
+   If *exist_ok* is true, :exc:`FileExistsError` will not be raised unless the 
given
+   path already exists in the file system and is not a directory (same
+   behavior as the POSIX ``mkdir -p`` command).
 
.. versionchanged:: 3.5
   The *exist_ok* parameter was added.

___
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-105900: Fix `pathlib.Path.symlink_to(target_is_directory=...)` docs (#114035)

2024-01-22 Thread barneygale
https://github.com/python/cpython/commit/b822b85ac11e73bbe4417bf03ee770ab116bb42d
commit: b822b85ac11e73bbe4417bf03ee770ab116bb42d
branch: main
author: Barney Gale 
committer: barneygale 
date: 2024-01-23T05:30:16Z
summary:

GH-105900: Fix `pathlib.Path.symlink_to(target_is_directory=...)` docs (#114035)

Clarify that *target_is_directory* only matters if the target doesn't
exist.

files:
M Doc/library/pathlib.rst

diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst
index a6d99d4a64f801..fcbc0bf489b344 100644
--- a/Doc/library/pathlib.rst
+++ b/Doc/library/pathlib.rst
@@ -1539,9 +1539,13 @@ call fails (for example because the path doesn't exist).
 
 .. method:: Path.symlink_to(target, target_is_directory=False)
 
-   Make this path a symbolic link to *target*.  Under Windows,
-   *target_is_directory* must be true (default ``False``) if the link's target
-   is a directory.  Under POSIX, *target_is_directory*'s value is ignored.
+   Make this path a symbolic link pointing to *target*.
+
+   On Windows, a symlink represents either a file or a directory, and does not
+   morph to the target dynamically.  If the target is present, the type of the
+   symlink will be created to match. Otherwise, the symlink will be created
+   as a directory if *target_is_directory* is ``True`` or a file symlink (the
+   default) otherwise.  On non-Windows platforms, *target_is_directory* is 
ignored.
 
::
 

___
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-105900: Fix `pathlib.Path.symlink_to(target_is_directory=...)` docs (GH-114035) (#114464)

2024-01-22 Thread barneygale
https://github.com/python/cpython/commit/ccd8d77112088f00b511749117263df5aae4630a
commit: ccd8d77112088f00b511749117263df5aae4630a
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: barneygale 
date: 2024-01-23T05:36:16Z
summary:

[3.12] GH-105900: Fix `pathlib.Path.symlink_to(target_is_directory=...)` docs 
(GH-114035) (#114464)

Clarify that *target_is_directory* only matters if the target doesn't
exist.
(cherry picked from commit b822b85ac11e73bbe4417bf03ee770ab116bb42d)

Co-authored-by: Barney Gale 

files:
M Doc/library/pathlib.rst

diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst
index 345a974dcb10bd..d839557993742a 100644
--- a/Doc/library/pathlib.rst
+++ b/Doc/library/pathlib.rst
@@ -1387,9 +1387,13 @@ call fails (for example because the path doesn't exist).
 
 .. method:: Path.symlink_to(target, target_is_directory=False)
 
-   Make this path a symbolic link to *target*.  Under Windows,
-   *target_is_directory* must be true (default ``False``) if the link's target
-   is a directory.  Under POSIX, *target_is_directory*'s value is ignored.
+   Make this path a symbolic link pointing to *target*.
+
+   On Windows, a symlink represents either a file or a directory, and does not
+   morph to the target dynamically.  If the target is present, the type of the
+   symlink will be created to match. Otherwise, the symlink will be created
+   as a directory if *target_is_directory* is ``True`` or a file symlink (the
+   default) otherwise.  On non-Windows platforms, *target_is_directory* is 
ignored.
 
::
 

___
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.11] GH-105900: Fix `pathlib.Path.symlink_to(target_is_directory=...)` docs (GH-114035) (#114465)

2024-01-22 Thread barneygale
https://github.com/python/cpython/commit/1f04ac8e277a744193db08079582462a11c80331
commit: 1f04ac8e277a744193db08079582462a11c80331
branch: 3.11
author: Miss Islington (bot) <[email protected]>
committer: barneygale 
date: 2024-01-23T05:37:32Z
summary:

[3.11] GH-105900: Fix `pathlib.Path.symlink_to(target_is_directory=...)` docs 
(GH-114035) (#114465)

Clarify that *target_is_directory* only matters if the target doesn't
exist.
(cherry picked from commit b822b85ac11e73bbe4417bf03ee770ab116bb42d)

Co-authored-by: Barney Gale 

files:
M Doc/library/pathlib.rst

diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst
index 528236cfa7eaa6..4c3edcb6361007 100644
--- a/Doc/library/pathlib.rst
+++ b/Doc/library/pathlib.rst
@@ -1187,9 +1187,13 @@ call fails (for example because the path doesn't exist).
 
 .. method:: Path.symlink_to(target, target_is_directory=False)
 
-   Make this path a symbolic link to *target*.  Under Windows,
-   *target_is_directory* must be true (default ``False``) if the link's target
-   is a directory.  Under POSIX, *target_is_directory*'s value is ignored.
+   Make this path a symbolic link pointing to *target*.
+
+   On Windows, a symlink represents either a file or a directory, and does not
+   morph to the target dynamically.  If the target is present, the type of the
+   symlink will be created to match. Otherwise, the symlink will be created
+   as a directory if *target_is_directory* is ``True`` or a file symlink (the
+   default) otherwise.  On non-Windows platforms, *target_is_directory* is 
ignored.
 
::
 

___
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]