[Python-checkins] gh-89159: Add some TarFile attribute types (GH-114520)

2024-01-29 Thread encukou
https://github.com/python/cpython/commit/d7d0d13cd37651990586d31d8974c59bd25e1045
commit: d7d0d13cd37651990586d31d8974c59bd25e1045
branch: main
author: Stanley <[email protected]>
committer: encukou 
date: 2024-01-29T09:19:22Z
summary:

gh-89159: Add some TarFile attribute types  (GH-114520)


Co-authored-by: Stanley <[email protected]>

files:
M Doc/library/tarfile.rst

diff --git a/Doc/library/tarfile.rst b/Doc/library/tarfile.rst
index 34a738a7f1c41f..2134293a0bb0de 100644
--- a/Doc/library/tarfile.rst
+++ b/Doc/library/tarfile.rst
@@ -673,6 +673,7 @@ be finalized; only the internally used file object will be 
closed. See the
 
 
 .. attribute:: TarFile.pax_headers
+   :type: dict
 
A dictionary containing key-value pairs of pax global headers.
 
@@ -838,26 +839,31 @@ A ``TarInfo`` object has the following public data 
attributes:
   attribute.
 
 .. attribute:: TarInfo.chksum
+   :type: int
 
Header checksum.
 
 
 .. attribute:: TarInfo.devmajor
+   :type: int
 
Device major number.
 
 
 .. attribute:: TarInfo.devminor
+   :type: int
 
Device minor number.
 
 
 .. attribute:: TarInfo.offset
+   :type: int
 
The tar header starts here.
 
 
 .. attribute:: TarInfo.offset_data
+   :type: int
 
The file's data starts here.
 

___
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-109653: Improve import time of importlib.metadata / email.utils (#114664)

2024-01-29 Thread hauntsaninja
https://github.com/python/cpython/commit/2124a3ddcc0e274521f74d239f0e94060e17dd7f
commit: 2124a3ddcc0e274521f74d239f0e94060e17dd7f
branch: main
author: Shantanu <[email protected]>
committer: hauntsaninja <[email protected]>
date: 2024-01-29T01:30:22-08:00
summary:

gh-109653: Improve import time of importlib.metadata / email.utils (#114664)

My criterion for delayed imports is that they're only worth it if the
majority of users of the module would benefit from it, otherwise you're
just moving latency around unpredictably.

mktime_tz is not used anywhere in the standard library and grep.app
indicates it's not got much use in the ecosystem either.

Distribution.files is not nearly as widely used as other
importlib.metadata APIs, so we defer the csv import.

Before:
```
λ hyperfine -w 8 './python -c "import importlib.metadata"'
Benchmark 1: ./python -c "import importlib.metadata"
  Time (mean ± σ):  65.1 ms ±   0.5 ms[User: 55.3 ms, System: 9.8 ms]
  Range (min … max):64.4 ms …  66.4 ms44 runs
```

After:
```
λ hyperfine -w 8 './python -c "import importlib.metadata"'
Benchmark 1: ./python -c "import importlib.metadata"
  Time (mean ± σ):  62.0 ms ±   0.3 ms[User: 52.5 ms, System: 9.6 ms]
  Range (min … max):61.3 ms …  62.8 ms46 runs
```

for about a 3ms saving with warm disk cache, maybe 7-11ms with cold disk
cache.

files:
A Misc/NEWS.d/next/Library/2024-01-28-00-48-12.gh-issue-109653.vF4exe.rst
M Lib/email/_parseaddr.py
M Lib/importlib/metadata/__init__.py

diff --git a/Lib/email/_parseaddr.py b/Lib/email/_parseaddr.py
index febe411355d6be..0f1bf8e4253ec4 100644
--- a/Lib/email/_parseaddr.py
+++ b/Lib/email/_parseaddr.py
@@ -13,7 +13,7 @@
 'quote',
 ]
 
-import time, calendar
+import time
 
 SPACE = ' '
 EMPTYSTRING = ''
@@ -194,6 +194,9 @@ def mktime_tz(data):
 # No zone info, so localtime is better assumption than GMT
 return time.mktime(data[:8] + (-1,))
 else:
+# Delay the import, since mktime_tz is rarely used
+import calendar
+
 t = calendar.timegm(data)
 return t - data[9]
 
diff --git a/Lib/importlib/metadata/__init__.py 
b/Lib/importlib/metadata/__init__.py
index 7b142e786e829e..c612fbefee2e80 100644
--- a/Lib/importlib/metadata/__init__.py
+++ b/Lib/importlib/metadata/__init__.py
@@ -1,7 +1,6 @@
 import os
 import re
 import abc
-import csv
 import sys
 import json
 import email
@@ -478,6 +477,10 @@ def make_file(name, hash=None, size_str=None):
 
 @pass_none
 def make_files(lines):
+# Delay csv import, since Distribution.files is not as widely used
+# as other parts of importlib.metadata
+import csv
+
 return starmap(make_file, csv.reader(lines))
 
 @pass_none
diff --git 
a/Misc/NEWS.d/next/Library/2024-01-28-00-48-12.gh-issue-109653.vF4exe.rst 
b/Misc/NEWS.d/next/Library/2024-01-28-00-48-12.gh-issue-109653.vF4exe.rst
new file mode 100644
index 00..fb3382098853b3
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-01-28-00-48-12.gh-issue-109653.vF4exe.rst
@@ -0,0 +1 @@
+Improve import time of :mod:`importlib.metadata` and :mod:`email.utils`.

___
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-114685: Fix incorrect use of PyBUF_READ in import.c (GH-114686)

2024-01-29 Thread serhiy-storchaka
https://github.com/python/cpython/commit/1ac1b2f9536a581f1656f0ac9330a7382420cda1
commit: 1ac1b2f9536a581f1656f0ac9330a7382420cda1
branch: main
author: Nikita Sobolev 
committer: serhiy-storchaka 
date: 2024-01-29T11:37:06+02:00
summary:

gh-114685: Fix incorrect use of PyBUF_READ in import.c (GH-114686)

files:
M Python/import.c

diff --git a/Python/import.c b/Python/import.c
index 2dd95d8364a0be..2fd0c08a6bb5ae 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -3544,7 +3544,7 @@ _imp_get_frozen_object_impl(PyObject *module, PyObject 
*name,
 struct frozen_info info = {0};
 Py_buffer buf = {0};
 if (PyObject_CheckBuffer(dataobj)) {
-if (PyObject_GetBuffer(dataobj, &buf, PyBUF_READ) != 0) {
+if (PyObject_GetBuffer(dataobj, &buf, PyBUF_SIMPLE) != 0) {
 return NULL;
 }
 info.data = (const char *)buf.buf;

___
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-110893: Improve the documentation for __future__ module (#114642)

2024-01-29 Thread hauntsaninja
https://github.com/python/cpython/commit/3b86891fd69093b60141300862f278614ba80613
commit: 3b86891fd69093b60141300862f278614ba80613
branch: main
author: Shantanu <[email protected]>
committer: hauntsaninja <[email protected]>
date: 2024-01-29T01:37:28-08:00
summary:

gh-110893: Improve the documentation for __future__ module (#114642)

nedbat took issue with the phrasing "real module". I'm actually fine
with that phrasing, but I do think the `__future__` page should be clear
about the way in which the `__future__` module is special. (Yes, there
was a footnote linking to the future statements part of the reference,
but there should be upfront discussion).

I'm sympathetic to nedbat's claim that no one really cares about
`__future__._Feature`, so I've moved the interesting table up to the
top.

files:
M Doc/library/__future__.rst

diff --git a/Doc/library/__future__.rst b/Doc/library/__future__.rst
index d261e4a4f338a5..762f8b4695b3dd 100644
--- a/Doc/library/__future__.rst
+++ b/Doc/library/__future__.rst
@@ -8,20 +8,68 @@
 
 --
 
-:mod:`__future__` is a real module, and serves three purposes:
+Imports of the form ``from __future__ import feature`` are called
+:ref:`future statements `. These are special-cased by the Python 
compiler
+to allow the use of new Python features in modules containing the future 
statement
+before the release in which the feature becomes standard.
+
+While these future statements are given additional special meaning by the
+Python compiler, they are still executed like any other import statement and
+the :mod:`__future__` exists and is handled by the import system the same way
+any other Python module would be. This design serves three purposes:
 
 * To avoid confusing existing tools that analyze import statements and expect 
to
   find the modules they're importing.
 
-* To ensure that :ref:`future statements ` run under releases prior to
-  2.1 at least yield runtime exceptions (the import of :mod:`__future__` will
-  fail, because there was no module of that name prior to 2.1).
-
 * To document when incompatible changes were introduced, and when they will be
   --- or were --- made mandatory.  This is a form of executable documentation, 
and
   can be inspected programmatically via importing :mod:`__future__` and 
examining
   its contents.
 
+* To ensure that :ref:`future statements ` run under releases prior to
+  Python 2.1 at least yield runtime exceptions (the import of :mod:`__future__`
+  will fail, because there was no module of that name prior to 2.1).
+
+Module Contents
+---
+
+No feature description will ever be deleted from :mod:`__future__`. Since its
+introduction in Python 2.1 the following features have found their way into the
+language using this mechanism:
+
++--+-+--+-+
+| feature  | optional in | mandatory in | effect   
   |
++==+=+==+=+
+| nested_scopes| 2.1.0b1 | 2.2  | :pep:`227`:  
   |
+|  | |  | *Statically Nested Scopes*   
   |
++--+-+--+-+
+| generators   | 2.2.0a1 | 2.3  | :pep:`255`:  
   |
+|  | |  | *Simple Generators*  
   |
++--+-+--+-+
+| division | 2.2.0a2 | 3.0  | :pep:`238`:  
   |
+|  | |  | *Changing the Division 
Operator*|
++--+-+--+-+
+| absolute_import  | 2.5.0a1 | 3.0  | :pep:`328`:  
   |
+|  | |  | *Imports: Multi-Line and 
Absolute/Relative* |
++--+-+--+-+
+| with_statement   | 2.5.0a1 | 2.6  | :pep:`343`:  
   |
+|  | |  | *The "with" Statement*   
   |
++--+-+--+-+
+| print_function   | 2.6.0a2 | 3.0  | :pep:`3105`: 
   |
+|  | |  | *Make print a function*  
   |
++--+-+--+-+
+| unicode_literals | 2.6.0a2 | 3.0  | :pep:`3112`: 
   |
+|

[Python-checkins] [3.11] gh-110893: Improve the documentation for __future__ module (GH-114642) (#114703)

2024-01-29 Thread hauntsaninja
https://github.com/python/cpython/commit/a2c55c56d3b3431ff554636e2be135b6c9714ec6
commit: a2c55c56d3b3431ff554636e2be135b6c9714ec6
branch: 3.11
author: Miss Islington (bot) <[email protected]>
committer: hauntsaninja <[email protected]>
date: 2024-01-29T09:46:04Z
summary:

[3.11] gh-110893: Improve the documentation for __future__ module (GH-114642) 
(#114703)

gh-110893: Improve the documentation for __future__ module (GH-114642)

nedbat took issue with the phrasing "real module". I'm actually fine
with that phrasing, but I do think the `__future__` page should be clear
about the way in which the `__future__` module is special. (Yes, there
was a footnote linking to the future statements part of the reference,
but there should be upfront discussion).

I'm sympathetic to nedbat's claim that no one really cares about
`__future__._Feature`, so I've moved the interesting table up to the
top.
(cherry picked from commit 3b86891fd69093b60141300862f278614ba80613)

Co-authored-by: Shantanu <[email protected]>

files:
M Doc/library/__future__.rst

diff --git a/Doc/library/__future__.rst b/Doc/library/__future__.rst
index d261e4a4f338a5..762f8b4695b3dd 100644
--- a/Doc/library/__future__.rst
+++ b/Doc/library/__future__.rst
@@ -8,20 +8,68 @@
 
 --
 
-:mod:`__future__` is a real module, and serves three purposes:
+Imports of the form ``from __future__ import feature`` are called
+:ref:`future statements `. These are special-cased by the Python 
compiler
+to allow the use of new Python features in modules containing the future 
statement
+before the release in which the feature becomes standard.
+
+While these future statements are given additional special meaning by the
+Python compiler, they are still executed like any other import statement and
+the :mod:`__future__` exists and is handled by the import system the same way
+any other Python module would be. This design serves three purposes:
 
 * To avoid confusing existing tools that analyze import statements and expect 
to
   find the modules they're importing.
 
-* To ensure that :ref:`future statements ` run under releases prior to
-  2.1 at least yield runtime exceptions (the import of :mod:`__future__` will
-  fail, because there was no module of that name prior to 2.1).
-
 * To document when incompatible changes were introduced, and when they will be
   --- or were --- made mandatory.  This is a form of executable documentation, 
and
   can be inspected programmatically via importing :mod:`__future__` and 
examining
   its contents.
 
+* To ensure that :ref:`future statements ` run under releases prior to
+  Python 2.1 at least yield runtime exceptions (the import of :mod:`__future__`
+  will fail, because there was no module of that name prior to 2.1).
+
+Module Contents
+---
+
+No feature description will ever be deleted from :mod:`__future__`. Since its
+introduction in Python 2.1 the following features have found their way into the
+language using this mechanism:
+
++--+-+--+-+
+| feature  | optional in | mandatory in | effect   
   |
++==+=+==+=+
+| nested_scopes| 2.1.0b1 | 2.2  | :pep:`227`:  
   |
+|  | |  | *Statically Nested Scopes*   
   |
++--+-+--+-+
+| generators   | 2.2.0a1 | 2.3  | :pep:`255`:  
   |
+|  | |  | *Simple Generators*  
   |
++--+-+--+-+
+| division | 2.2.0a2 | 3.0  | :pep:`238`:  
   |
+|  | |  | *Changing the Division 
Operator*|
++--+-+--+-+
+| absolute_import  | 2.5.0a1 | 3.0  | :pep:`328`:  
   |
+|  | |  | *Imports: Multi-Line and 
Absolute/Relative* |
++--+-+--+-+
+| with_statement   | 2.5.0a1 | 2.6  | :pep:`343`:  
   |
+|  | |  | *The "with" Statement*   
   |
++--+-+--+-+
+| print_function   | 2.6.0a2 | 3.0  | :pep:`3105`: 
   |
+|  | |  | *Make print

[Python-checkins] [3.12] gh-110893: Improve the documentation for __future__ module (GH-114642) (#114702)

2024-01-29 Thread hauntsaninja
https://github.com/python/cpython/commit/d14003adf267dc09f5a245235ad1fc25888b8848
commit: d14003adf267dc09f5a245235ad1fc25888b8848
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: hauntsaninja <[email protected]>
date: 2024-01-29T09:46:48Z
summary:

[3.12] gh-110893: Improve the documentation for __future__ module (GH-114642) 
(#114702)

gh-110893: Improve the documentation for __future__ module (GH-114642)

nedbat took issue with the phrasing "real module". I'm actually fine
with that phrasing, but I do think the `__future__` page should be clear
about the way in which the `__future__` module is special. (Yes, there
was a footnote linking to the future statements part of the reference,
but there should be upfront discussion).

I'm sympathetic to nedbat's claim that no one really cares about
`__future__._Feature`, so I've moved the interesting table up to the
top.
(cherry picked from commit 3b86891fd69093b60141300862f278614ba80613)

Co-authored-by: Shantanu <[email protected]>

files:
M Doc/library/__future__.rst

diff --git a/Doc/library/__future__.rst b/Doc/library/__future__.rst
index d261e4a4f338a5..762f8b4695b3dd 100644
--- a/Doc/library/__future__.rst
+++ b/Doc/library/__future__.rst
@@ -8,20 +8,68 @@
 
 --
 
-:mod:`__future__` is a real module, and serves three purposes:
+Imports of the form ``from __future__ import feature`` are called
+:ref:`future statements `. These are special-cased by the Python 
compiler
+to allow the use of new Python features in modules containing the future 
statement
+before the release in which the feature becomes standard.
+
+While these future statements are given additional special meaning by the
+Python compiler, they are still executed like any other import statement and
+the :mod:`__future__` exists and is handled by the import system the same way
+any other Python module would be. This design serves three purposes:
 
 * To avoid confusing existing tools that analyze import statements and expect 
to
   find the modules they're importing.
 
-* To ensure that :ref:`future statements ` run under releases prior to
-  2.1 at least yield runtime exceptions (the import of :mod:`__future__` will
-  fail, because there was no module of that name prior to 2.1).
-
 * To document when incompatible changes were introduced, and when they will be
   --- or were --- made mandatory.  This is a form of executable documentation, 
and
   can be inspected programmatically via importing :mod:`__future__` and 
examining
   its contents.
 
+* To ensure that :ref:`future statements ` run under releases prior to
+  Python 2.1 at least yield runtime exceptions (the import of :mod:`__future__`
+  will fail, because there was no module of that name prior to 2.1).
+
+Module Contents
+---
+
+No feature description will ever be deleted from :mod:`__future__`. Since its
+introduction in Python 2.1 the following features have found their way into the
+language using this mechanism:
+
++--+-+--+-+
+| feature  | optional in | mandatory in | effect   
   |
++==+=+==+=+
+| nested_scopes| 2.1.0b1 | 2.2  | :pep:`227`:  
   |
+|  | |  | *Statically Nested Scopes*   
   |
++--+-+--+-+
+| generators   | 2.2.0a1 | 2.3  | :pep:`255`:  
   |
+|  | |  | *Simple Generators*  
   |
++--+-+--+-+
+| division | 2.2.0a2 | 3.0  | :pep:`238`:  
   |
+|  | |  | *Changing the Division 
Operator*|
++--+-+--+-+
+| absolute_import  | 2.5.0a1 | 3.0  | :pep:`328`:  
   |
+|  | |  | *Imports: Multi-Line and 
Absolute/Relative* |
++--+-+--+-+
+| with_statement   | 2.5.0a1 | 2.6  | :pep:`343`:  
   |
+|  | |  | *The "with" Statement*   
   |
++--+-+--+-+
+| print_function   | 2.6.0a2 | 3.0  | :pep:`3105`: 
   |
+|  | |  | *Make print

[Python-checkins] gh-101100: Fix sphinx warnings in `Doc/c-api/memoryview.rst` (GH-114669)

2024-01-29 Thread serhiy-storchaka
https://github.com/python/cpython/commit/97fb2480e4807a34b8197243ad57566ed7769e24
commit: 97fb2480e4807a34b8197243ad57566ed7769e24
branch: main
author: Nikita Sobolev 
committer: serhiy-storchaka 
date: 2024-01-29T11:56:11+02:00
summary:

gh-101100: Fix sphinx warnings in `Doc/c-api/memoryview.rst` (GH-114669)

files:
M Doc/c-api/memoryview.rst
M Doc/tools/.nitignore

diff --git a/Doc/c-api/memoryview.rst b/Doc/c-api/memoryview.rst
index 2aa43318e7a455..f6038032805259 100644
--- a/Doc/c-api/memoryview.rst
+++ b/Doc/c-api/memoryview.rst
@@ -20,6 +20,17 @@ any other object.
read/write, otherwise it may be either read-only or read/write at the
discretion of the exporter.
 
+
+.. c:macro:: PyBUF_READ
+
+   Flag to request a readonly buffer.
+
+
+.. c:macro:: PyBUF_WRITE
+
+   Flag to request a writable buffer.
+
+
 .. c:function:: PyObject *PyMemoryView_FromMemory(char *mem, Py_ssize_t size, 
int flags)
 
Create a memoryview object using *mem* as the underlying buffer.
@@ -41,6 +52,8 @@ any other object.
original memory. Otherwise, a copy is made and the memoryview points to a
new bytes object.
 
+   *buffertype* can be one of :c:macro:`PyBUF_READ` or :c:macro:`PyBUF_WRITE`.
+
 
 .. c:function:: int PyMemoryView_Check(PyObject *obj)
 
diff --git a/Doc/tools/.nitignore b/Doc/tools/.nitignore
index 8b6847ef2a7d76..b8b7c2299ca9f4 100644
--- a/Doc/tools/.nitignore
+++ b/Doc/tools/.nitignore
@@ -9,7 +9,6 @@ Doc/c-api/gcsupport.rst
 Doc/c-api/init.rst
 Doc/c-api/init_config.rst
 Doc/c-api/intro.rst
-Doc/c-api/memoryview.rst
 Doc/c-api/module.rst
 Doc/c-api/stable.rst
 Doc/c-api/sys.rst

___
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]


[Python-checkins] [3.12] gh-101100: Fix sphinx warnings in `Doc/c-api/memoryview.rst` (GH-114669) (GH-114704)

2024-01-29 Thread serhiy-storchaka
https://github.com/python/cpython/commit/930f805e72587655cd4c2a7c0f28125bde234914
commit: 930f805e72587655cd4c2a7c0f28125bde234914
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka 
date: 2024-01-29T10:02:06Z
summary:

[3.12] gh-101100: Fix sphinx warnings in `Doc/c-api/memoryview.rst` (GH-114669) 
(GH-114704)

(cherry picked from commit 97fb2480e4807a34b8197243ad57566ed7769e24)

Co-authored-by: Nikita Sobolev 

files:
M Doc/c-api/memoryview.rst
M Doc/tools/.nitignore

diff --git a/Doc/c-api/memoryview.rst b/Doc/c-api/memoryview.rst
index 2aa43318e7a455..f6038032805259 100644
--- a/Doc/c-api/memoryview.rst
+++ b/Doc/c-api/memoryview.rst
@@ -20,6 +20,17 @@ any other object.
read/write, otherwise it may be either read-only or read/write at the
discretion of the exporter.
 
+
+.. c:macro:: PyBUF_READ
+
+   Flag to request a readonly buffer.
+
+
+.. c:macro:: PyBUF_WRITE
+
+   Flag to request a writable buffer.
+
+
 .. c:function:: PyObject *PyMemoryView_FromMemory(char *mem, Py_ssize_t size, 
int flags)
 
Create a memoryview object using *mem* as the underlying buffer.
@@ -41,6 +52,8 @@ any other object.
original memory. Otherwise, a copy is made and the memoryview points to a
new bytes object.
 
+   *buffertype* can be one of :c:macro:`PyBUF_READ` or :c:macro:`PyBUF_WRITE`.
+
 
 .. c:function:: int PyMemoryView_Check(PyObject *obj)
 
diff --git a/Doc/tools/.nitignore b/Doc/tools/.nitignore
index 89721e405ee770..9edbdf18d9a24a 100644
--- a/Doc/tools/.nitignore
+++ b/Doc/tools/.nitignore
@@ -11,7 +11,6 @@ Doc/c-api/gcsupport.rst
 Doc/c-api/init.rst
 Doc/c-api/init_config.rst
 Doc/c-api/intro.rst
-Doc/c-api/memoryview.rst
 Doc/c-api/module.rst
 Doc/c-api/object.rst
 Doc/c-api/stable.rst

___
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]


[Python-checkins] [3.11] gh-101100: Fix sphinx warnings in `Doc/c-api/memoryview.rst` (GH-114669) (GH-114705)

2024-01-29 Thread serhiy-storchaka
https://github.com/python/cpython/commit/9fd8aaab8314924c0af41d0a03c5140f42f52d9d
commit: 9fd8aaab8314924c0af41d0a03c5140f42f52d9d
branch: 3.11
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka 
date: 2024-01-29T10:02:52Z
summary:

[3.11] gh-101100: Fix sphinx warnings in `Doc/c-api/memoryview.rst` (GH-114669) 
(GH-114705)

(cherry picked from commit 97fb2480e4807a34b8197243ad57566ed7769e24)

Co-authored-by: Nikita Sobolev 

files:
M Doc/c-api/memoryview.rst
M Doc/tools/.nitignore

diff --git a/Doc/c-api/memoryview.rst b/Doc/c-api/memoryview.rst
index 2aa43318e7a455..f6038032805259 100644
--- a/Doc/c-api/memoryview.rst
+++ b/Doc/c-api/memoryview.rst
@@ -20,6 +20,17 @@ any other object.
read/write, otherwise it may be either read-only or read/write at the
discretion of the exporter.
 
+
+.. c:macro:: PyBUF_READ
+
+   Flag to request a readonly buffer.
+
+
+.. c:macro:: PyBUF_WRITE
+
+   Flag to request a writable buffer.
+
+
 .. c:function:: PyObject *PyMemoryView_FromMemory(char *mem, Py_ssize_t size, 
int flags)
 
Create a memoryview object using *mem* as the underlying buffer.
@@ -41,6 +52,8 @@ any other object.
original memory. Otherwise, a copy is made and the memoryview points to a
new bytes object.
 
+   *buffertype* can be one of :c:macro:`PyBUF_READ` or :c:macro:`PyBUF_WRITE`.
+
 
 .. c:function:: int PyMemoryView_Check(PyObject *obj)
 
diff --git a/Doc/tools/.nitignore b/Doc/tools/.nitignore
index 3248f328479871..76fbc3c3d4d71f 100644
--- a/Doc/tools/.nitignore
+++ b/Doc/tools/.nitignore
@@ -9,7 +9,6 @@ Doc/c-api/gcsupport.rst
 Doc/c-api/init.rst
 Doc/c-api/init_config.rst
 Doc/c-api/intro.rst
-Doc/c-api/memoryview.rst
 Doc/c-api/module.rst
 Doc/c-api/stable.rst
 Doc/c-api/structures.rst

___
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]


[Python-checkins] [3.11] gh-114685: Fix incorrect use of PyBUF_READ in import.c (GH-114686) (GH-114701)

2024-01-29 Thread serhiy-storchaka
https://github.com/python/cpython/commit/ee3ca96359a27e893e4f642b3d490a7d355f7da7
commit: ee3ca96359a27e893e4f642b3d490a7d355f7da7
branch: 3.11
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka 
date: 2024-01-29T10:03:14Z
summary:

[3.11] gh-114685: Fix incorrect use of PyBUF_READ in import.c (GH-114686) 
(GH-114701)

(cherry picked from commit 1ac1b2f9536a581f1656f0ac9330a7382420cda1)

Co-authored-by: Nikita Sobolev 

files:
M Python/import.c

diff --git a/Python/import.c b/Python/import.c
index 39144d302193ac..c4e2145a47c4d2 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -2194,7 +2194,7 @@ _imp_get_frozen_object_impl(PyObject *module, PyObject 
*name,
 struct frozen_info info = {0};
 Py_buffer buf = {0};
 if (PyObject_CheckBuffer(dataobj)) {
-if (PyObject_GetBuffer(dataobj, &buf, PyBUF_READ) != 0) {
+if (PyObject_GetBuffer(dataobj, &buf, PyBUF_SIMPLE) != 0) {
 return NULL;
 }
 info.data = (const char *)buf.buf;

___
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-114685: Fix incorrect use of PyBUF_READ in import.c (GH-114686) (GH-114700)

2024-01-29 Thread serhiy-storchaka
https://github.com/python/cpython/commit/2a1d2c83256e6445793ec8b79363e4ac4494db78
commit: 2a1d2c83256e6445793ec8b79363e4ac4494db78
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka 
date: 2024-01-29T10:09:51Z
summary:

[3.12] gh-114685: Fix incorrect use of PyBUF_READ in import.c (GH-114686) 
(GH-114700)

(cherry picked from commit 1ac1b2f9536a581f1656f0ac9330a7382420cda1)

Co-authored-by: Nikita Sobolev 

files:
M Python/import.c

diff --git a/Python/import.c b/Python/import.c
index 54232a130082f0..db70909982fa3e 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -3570,7 +3570,7 @@ _imp_get_frozen_object_impl(PyObject *module, PyObject 
*name,
 struct frozen_info info = {0};
 Py_buffer buf = {0};
 if (PyObject_CheckBuffer(dataobj)) {
-if (PyObject_GetBuffer(dataobj, &buf, PyBUF_READ) != 0) {
+if (PyObject_GetBuffer(dataobj, &buf, PyBUF_SIMPLE) != 0) {
 return NULL;
 }
 info.data = (const char *)buf.buf;

___
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-101100: Fix Sphinx warnings in `whatsnew/2.2.rst` (#112366)

2024-01-29 Thread hugovk
https://github.com/python/cpython/commit/b7a12ab2146f946ae57e2d8019372cafe94d8375
commit: b7a12ab2146f946ae57e2d8019372cafe94d8375
branch: main
author: Hugo van Kemenade <[email protected]>
committer: hugovk <[email protected]>
date: 2024-01-29T13:12:19Z
summary:

gh-101100: Fix Sphinx warnings in `whatsnew/2.2.rst` (#112366)

Co-authored-by: Hugo van Kemenade 

files:
M Doc/tools/.nitignore
M Doc/whatsnew/2.2.rst

diff --git a/Doc/tools/.nitignore b/Doc/tools/.nitignore
index b8b7c2299ca9f4..763503205e1670 100644
--- a/Doc/tools/.nitignore
+++ b/Doc/tools/.nitignore
@@ -90,7 +90,6 @@ Doc/tutorial/datastructures.rst
 Doc/using/windows.rst
 Doc/whatsnew/2.0.rst
 Doc/whatsnew/2.1.rst
-Doc/whatsnew/2.2.rst
 Doc/whatsnew/2.4.rst
 Doc/whatsnew/2.5.rst
 Doc/whatsnew/2.6.rst
diff --git a/Doc/whatsnew/2.2.rst b/Doc/whatsnew/2.2.rst
index 6efc23a82de923..968bd7a126bdf0 100644
--- a/Doc/whatsnew/2.2.rst
+++ b/Doc/whatsnew/2.2.rst
@@ -53,9 +53,9 @@ A long time ago I wrote a web page listing flaws in Python's 
design.  One of the
 most significant flaws was that it's impossible to subclass Python types
 implemented in C.  In particular, it's not possible to subclass built-in types,
 so you can't just subclass, say, lists in order to add a single useful method 
to
-them. The :mod:`UserList` module provides a class that supports all of the
+them. The :mod:`!UserList` module provides a class that supports all of the
 methods of lists and that can be subclassed further, but there's lots of C code
-that expects a regular Python list and won't accept a :class:`UserList`
+that expects a regular Python list and won't accept a :class:`!UserList`
 instance.
 
 Python 2.2 fixes this, and in the process adds some exciting new capabilities.
@@ -69,7 +69,7 @@ A brief summary:
 
 * It's also possible to automatically call methods on accessing or setting an
   instance attribute by using a new mechanism called :dfn:`properties`.  Many 
uses
-  of :meth:`__getattr__` can be rewritten to use properties instead, making the
+  of :meth:`!__getattr__` can be rewritten to use properties instead, making 
the
   resulting code simpler and faster.  As a small side benefit, attributes can 
now
   have docstrings, too.
 
@@ -120,7 +120,7 @@ added so if no built-in type is suitable, you can just 
subclass
 
 This means that :keyword:`class` statements that don't have any base classes 
are
 always classic classes in Python 2.2.  (Actually you can also change this by
-setting a module-level variable named :attr:`__metaclass__` --- see :pep:`253`
+setting a module-level variable named :attr:`!__metaclass__` --- see :pep:`253`
 for the details --- but it's easier to just subclass :class:`object`.)
 
 The type objects for the built-in types are available as built-ins, named using
@@ -134,8 +134,8 @@ type objects that behave as factories when called. ::
123
 
 To make the set of types complete, new type objects such as :func:`dict` and
-:func:`file` have been added.  Here's a more interesting example, adding a
-:meth:`lock` method to file objects::
+:func:`!file` have been added.  Here's a more interesting example, adding a
+:meth:`!lock` method to file objects::
 
class LockableFile(file):
def lock (self, operation, length=0, start=0, whence=0):
@@ -146,7 +146,7 @@ To make the set of types complete, new type objects such as 
:func:`dict` and
 The now-obsolete :mod:`!posixfile` module contained a class that emulated all 
of
 a file object's methods and also added a :meth:`!lock` method, but this class
 couldn't be passed to internal functions that expected a built-in file,
-something which is possible with our new :class:`LockableFile`.
+something which is possible with our new :class:`!LockableFile`.
 
 
 Descriptors
@@ -154,11 +154,11 @@ Descriptors
 
 In previous versions of Python, there was no consistent way to discover what
 attributes and methods were supported by an object. There were some informal
-conventions, such as defining :attr:`__members__` and :attr:`__methods__`
+conventions, such as defining :attr:`!__members__` and :attr:`!__methods__`
 attributes that were lists of names, but often the author of an extension type
 or a class wouldn't bother to define them.  You could fall back on inspecting
 the :attr:`~object.__dict__` of an object, but when class inheritance or an 
arbitrary
-:meth:`__getattr__` hook were in use this could still be inaccurate.
+:meth:`!__getattr__` hook were in use this could still be inaccurate.
 
 The one big idea underlying the new class model is that an API for describing
 the attributes of an object using :dfn:`descriptors` has been formalized.
@@ -171,7 +171,7 @@ attributes of their own:
 
 * :attr:`~definition.__name__` is the attribute's name.
 
-* :attr:`__doc__` is the attribute's docstring.
+* :attr:`!__doc__` is the attribute's docstring.
 
 * ``__get__(object)`` is a method that retrieves the attribute value from
   *object*.
@@ -186,7 +186

[Python-checkins] [3.12] gh-101100: Fix Sphinx warnings in `whatsnew/2.2.rst` (GH-112366) (#114711)

2024-01-29 Thread hugovk
https://github.com/python/cpython/commit/c09a01032df9a121d525838141e3fed203735404
commit: c09a01032df9a121d525838141e3fed203735404
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: hugovk <[email protected]>
date: 2024-01-29T13:18:34Z
summary:

[3.12] gh-101100: Fix Sphinx warnings in `whatsnew/2.2.rst` (GH-112366) 
(#114711)

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

files:
M Doc/tools/.nitignore
M Doc/whatsnew/2.2.rst

diff --git a/Doc/tools/.nitignore b/Doc/tools/.nitignore
index 9edbdf18d9a24a..e520359e12ebe6 100644
--- a/Doc/tools/.nitignore
+++ b/Doc/tools/.nitignore
@@ -109,7 +109,6 @@ Doc/tutorial/datastructures.rst
 Doc/using/windows.rst
 Doc/whatsnew/2.0.rst
 Doc/whatsnew/2.1.rst
-Doc/whatsnew/2.2.rst
 Doc/whatsnew/2.4.rst
 Doc/whatsnew/2.5.rst
 Doc/whatsnew/2.6.rst
diff --git a/Doc/whatsnew/2.2.rst b/Doc/whatsnew/2.2.rst
index 6efc23a82de923..968bd7a126bdf0 100644
--- a/Doc/whatsnew/2.2.rst
+++ b/Doc/whatsnew/2.2.rst
@@ -53,9 +53,9 @@ A long time ago I wrote a web page listing flaws in Python's 
design.  One of the
 most significant flaws was that it's impossible to subclass Python types
 implemented in C.  In particular, it's not possible to subclass built-in types,
 so you can't just subclass, say, lists in order to add a single useful method 
to
-them. The :mod:`UserList` module provides a class that supports all of the
+them. The :mod:`!UserList` module provides a class that supports all of the
 methods of lists and that can be subclassed further, but there's lots of C code
-that expects a regular Python list and won't accept a :class:`UserList`
+that expects a regular Python list and won't accept a :class:`!UserList`
 instance.
 
 Python 2.2 fixes this, and in the process adds some exciting new capabilities.
@@ -69,7 +69,7 @@ A brief summary:
 
 * It's also possible to automatically call methods on accessing or setting an
   instance attribute by using a new mechanism called :dfn:`properties`.  Many 
uses
-  of :meth:`__getattr__` can be rewritten to use properties instead, making the
+  of :meth:`!__getattr__` can be rewritten to use properties instead, making 
the
   resulting code simpler and faster.  As a small side benefit, attributes can 
now
   have docstrings, too.
 
@@ -120,7 +120,7 @@ added so if no built-in type is suitable, you can just 
subclass
 
 This means that :keyword:`class` statements that don't have any base classes 
are
 always classic classes in Python 2.2.  (Actually you can also change this by
-setting a module-level variable named :attr:`__metaclass__` --- see :pep:`253`
+setting a module-level variable named :attr:`!__metaclass__` --- see :pep:`253`
 for the details --- but it's easier to just subclass :class:`object`.)
 
 The type objects for the built-in types are available as built-ins, named using
@@ -134,8 +134,8 @@ type objects that behave as factories when called. ::
123
 
 To make the set of types complete, new type objects such as :func:`dict` and
-:func:`file` have been added.  Here's a more interesting example, adding a
-:meth:`lock` method to file objects::
+:func:`!file` have been added.  Here's a more interesting example, adding a
+:meth:`!lock` method to file objects::
 
class LockableFile(file):
def lock (self, operation, length=0, start=0, whence=0):
@@ -146,7 +146,7 @@ To make the set of types complete, new type objects such as 
:func:`dict` and
 The now-obsolete :mod:`!posixfile` module contained a class that emulated all 
of
 a file object's methods and also added a :meth:`!lock` method, but this class
 couldn't be passed to internal functions that expected a built-in file,
-something which is possible with our new :class:`LockableFile`.
+something which is possible with our new :class:`!LockableFile`.
 
 
 Descriptors
@@ -154,11 +154,11 @@ Descriptors
 
 In previous versions of Python, there was no consistent way to discover what
 attributes and methods were supported by an object. There were some informal
-conventions, such as defining :attr:`__members__` and :attr:`__methods__`
+conventions, such as defining :attr:`!__members__` and :attr:`!__methods__`
 attributes that were lists of names, but often the author of an extension type
 or a class wouldn't bother to define them.  You could fall back on inspecting
 the :attr:`~object.__dict__` of an object, but when class inheritance or an 
arbitrary
-:meth:`__getattr__` hook were in use this could still be inaccurate.
+:meth:`!__getattr__` hook were in use this could still be inaccurate.
 
 The one big idea underlying the new class model is that an API for describing
 the attributes of an object using :dfn:`descriptors` has been formalized.
@@ -171,7 +171,7 @@ attributes of their own:
 
 * :attr:`~definition.__name__` is the attribute's name.
 
-* :attr:`__doc__` is the attribute's docstring.
+* :attr:`!__doc__` is the attribute's docst

[Python-checkins] [3.11] gh-101100: Fix Sphinx warnings in `whatsnew/2.2.rst` (GH-112366) (#114712)

2024-01-29 Thread hugovk
https://github.com/python/cpython/commit/ca9a7fc24f606a4b2daa6d23297d9e0c33a36d8e
commit: ca9a7fc24f606a4b2daa6d23297d9e0c33a36d8e
branch: 3.11
author: Miss Islington (bot) <[email protected]>
committer: hugovk <[email protected]>
date: 2024-01-29T13:18:59Z
summary:

[3.11] gh-101100: Fix Sphinx warnings in `whatsnew/2.2.rst` (GH-112366) 
(#114712)

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

files:
M Doc/tools/.nitignore
M Doc/whatsnew/2.2.rst

diff --git a/Doc/tools/.nitignore b/Doc/tools/.nitignore
index 76fbc3c3d4d71f..d7261fe2922e73 100644
--- a/Doc/tools/.nitignore
+++ b/Doc/tools/.nitignore
@@ -95,7 +95,6 @@ Doc/tutorial/datastructures.rst
 Doc/using/windows.rst
 Doc/whatsnew/2.0.rst
 Doc/whatsnew/2.1.rst
-Doc/whatsnew/2.2.rst
 Doc/whatsnew/2.4.rst
 Doc/whatsnew/2.5.rst
 Doc/whatsnew/2.6.rst
diff --git a/Doc/whatsnew/2.2.rst b/Doc/whatsnew/2.2.rst
index 6efc23a82de923..968bd7a126bdf0 100644
--- a/Doc/whatsnew/2.2.rst
+++ b/Doc/whatsnew/2.2.rst
@@ -53,9 +53,9 @@ A long time ago I wrote a web page listing flaws in Python's 
design.  One of the
 most significant flaws was that it's impossible to subclass Python types
 implemented in C.  In particular, it's not possible to subclass built-in types,
 so you can't just subclass, say, lists in order to add a single useful method 
to
-them. The :mod:`UserList` module provides a class that supports all of the
+them. The :mod:`!UserList` module provides a class that supports all of the
 methods of lists and that can be subclassed further, but there's lots of C code
-that expects a regular Python list and won't accept a :class:`UserList`
+that expects a regular Python list and won't accept a :class:`!UserList`
 instance.
 
 Python 2.2 fixes this, and in the process adds some exciting new capabilities.
@@ -69,7 +69,7 @@ A brief summary:
 
 * It's also possible to automatically call methods on accessing or setting an
   instance attribute by using a new mechanism called :dfn:`properties`.  Many 
uses
-  of :meth:`__getattr__` can be rewritten to use properties instead, making the
+  of :meth:`!__getattr__` can be rewritten to use properties instead, making 
the
   resulting code simpler and faster.  As a small side benefit, attributes can 
now
   have docstrings, too.
 
@@ -120,7 +120,7 @@ added so if no built-in type is suitable, you can just 
subclass
 
 This means that :keyword:`class` statements that don't have any base classes 
are
 always classic classes in Python 2.2.  (Actually you can also change this by
-setting a module-level variable named :attr:`__metaclass__` --- see :pep:`253`
+setting a module-level variable named :attr:`!__metaclass__` --- see :pep:`253`
 for the details --- but it's easier to just subclass :class:`object`.)
 
 The type objects for the built-in types are available as built-ins, named using
@@ -134,8 +134,8 @@ type objects that behave as factories when called. ::
123
 
 To make the set of types complete, new type objects such as :func:`dict` and
-:func:`file` have been added.  Here's a more interesting example, adding a
-:meth:`lock` method to file objects::
+:func:`!file` have been added.  Here's a more interesting example, adding a
+:meth:`!lock` method to file objects::
 
class LockableFile(file):
def lock (self, operation, length=0, start=0, whence=0):
@@ -146,7 +146,7 @@ To make the set of types complete, new type objects such as 
:func:`dict` and
 The now-obsolete :mod:`!posixfile` module contained a class that emulated all 
of
 a file object's methods and also added a :meth:`!lock` method, but this class
 couldn't be passed to internal functions that expected a built-in file,
-something which is possible with our new :class:`LockableFile`.
+something which is possible with our new :class:`!LockableFile`.
 
 
 Descriptors
@@ -154,11 +154,11 @@ Descriptors
 
 In previous versions of Python, there was no consistent way to discover what
 attributes and methods were supported by an object. There were some informal
-conventions, such as defining :attr:`__members__` and :attr:`__methods__`
+conventions, such as defining :attr:`!__members__` and :attr:`!__methods__`
 attributes that were lists of names, but often the author of an extension type
 or a class wouldn't bother to define them.  You could fall back on inspecting
 the :attr:`~object.__dict__` of an object, but when class inheritance or an 
arbitrary
-:meth:`__getattr__` hook were in use this could still be inaccurate.
+:meth:`!__getattr__` hook were in use this could still be inaccurate.
 
 The one big idea underlying the new class model is that an API for describing
 the attributes of an object using :dfn:`descriptors` has been formalized.
@@ -171,7 +171,7 @@ attributes of their own:
 
 * :attr:`~definition.__name__` is the attribute's name.
 
-* :attr:`__doc__` is the attribute's docstring.
+* :attr:`!__doc__` is the attribute's docstri

[Python-checkins] [3.12] gh-89159: Add some TarFile attribute types (GH-114520) (GH-114714)

2024-01-29 Thread encukou
https://github.com/python/cpython/commit/0795d9a17a4c95cdb6dd032efb9ebf193f7fb274
commit: 0795d9a17a4c95cdb6dd032efb9ebf193f7fb274
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: encukou 
date: 2024-01-29T14:25:46Z
summary:

[3.12] gh-89159: Add some TarFile attribute types  (GH-114520) (GH-114714)


(cherry picked from commit d7d0d13cd37651990586d31d8974c59bd25e1045)

Co-authored-by: Stanley <[email protected]>

files:
M Doc/library/tarfile.rst

diff --git a/Doc/library/tarfile.rst b/Doc/library/tarfile.rst
index dbbcb127f6f209..755581cfc6f640 100644
--- a/Doc/library/tarfile.rst
+++ b/Doc/library/tarfile.rst
@@ -668,6 +668,7 @@ be finalized; only the internally used file object will be 
closed. See the
 
 
 .. attribute:: TarFile.pax_headers
+   :type: dict
 
A dictionary containing key-value pairs of pax global headers.
 
@@ -833,26 +834,31 @@ A ``TarInfo`` object has the following public data 
attributes:
   attribute.
 
 .. attribute:: TarInfo.chksum
+   :type: int
 
Header checksum.
 
 
 .. attribute:: TarInfo.devmajor
+   :type: int
 
Device major number.
 
 
 .. attribute:: TarInfo.devminor
+   :type: int
 
Device minor number.
 
 
 .. attribute:: TarInfo.offset
+   :type: int
 
The tar header starts here.
 
 
 .. attribute:: TarInfo.offset_data
+   :type: int
 
The file's data starts here.
 

___
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-89159: Add some TarFile attribute types (GH-114520) (GH-114715)

2024-01-29 Thread encukou
https://github.com/python/cpython/commit/07d68ea843d6251efcdadc167cd7840112bc13d2
commit: 07d68ea843d6251efcdadc167cd7840112bc13d2
branch: 3.11
author: Miss Islington (bot) <[email protected]>
committer: encukou 
date: 2024-01-29T14:25:52Z
summary:

[3.11] gh-89159: Add some TarFile attribute types  (GH-114520) (GH-114715)


(cherry picked from commit d7d0d13cd37651990586d31d8974c59bd25e1045)

Co-authored-by: Stanley <[email protected]>

files:
M Doc/library/tarfile.rst

diff --git a/Doc/library/tarfile.rst b/Doc/library/tarfile.rst
index cd2df3e69e3729..32d77d5d87bf82 100644
--- a/Doc/library/tarfile.rst
+++ b/Doc/library/tarfile.rst
@@ -660,6 +660,7 @@ be finalized; only the internally used file object will be 
closed. See the
 
 
 .. attribute:: TarFile.pax_headers
+   :type: dict
 
A dictionary containing key-value pairs of pax global headers.
 
@@ -830,26 +831,31 @@ A ``TarInfo`` object has the following public data 
attributes:
   attribute.
 
 .. attribute:: TarInfo.chksum
+   :type: int
 
Header checksum.
 
 
 .. attribute:: TarInfo.devmajor
+   :type: int
 
Device major number.
 
 
 .. attribute:: TarInfo.devminor
+   :type: int
 
Device minor number.
 
 
 .. attribute:: TarInfo.offset
+   :type: int
 
The tar header starts here.
 
 
 .. attribute:: TarInfo.offset_data
+   :type: int
 
The file's data starts here.
 

___
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-101100: Fix datetime reference warnings (GH-114661)

2024-01-29 Thread serhiy-storchaka
https://github.com/python/cpython/commit/e8b8f5e9c2da6a436360ce648061c90bdfcba863
commit: e8b8f5e9c2da6a436360ce648061c90bdfcba863
branch: main
author: Skip Montanaro 
committer: serhiy-storchaka 
date: 2024-01-29T16:43:44+02:00
summary:

gh-101100: Fix datetime reference warnings (GH-114661)

Co-authored-by: Serhiy Storchaka 

files:
M Doc/conf.py
M Doc/library/datetime.rst
M Doc/tools/.nitignore

diff --git a/Doc/conf.py b/Doc/conf.py
index 458954370debe2..a96e7787d167a3 100644
--- a/Doc/conf.py
+++ b/Doc/conf.py
@@ -89,20 +89,25 @@
 nitpick_ignore = [
 # Standard C functions
 ('c:func', 'calloc'),
+('c:func', 'ctime'),
 ('c:func', 'dlopen'),
 ('c:func', 'exec'),
 ('c:func', 'fcntl'),
 ('c:func', 'fork'),
 ('c:func', 'free'),
+('c:func', 'gettimeofday'),
 ('c:func', 'gmtime'),
+('c:func', 'localeconv'),
 ('c:func', 'localtime'),
 ('c:func', 'main'),
 ('c:func', 'malloc'),
+('c:func', 'mktime'),
 ('c:func', 'printf'),
 ('c:func', 'realloc'),
 ('c:func', 'snprintf'),
 ('c:func', 'sprintf'),
 ('c:func', 'stat'),
+('c:func', 'strftime'),
 ('c:func', 'system'),
 ('c:func', 'time'),
 ('c:func', 'vsnprintf'),
diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst
index b36f8c19cd6040..47ecb0ba331bdc 100644
--- a/Doc/library/datetime.rst
+++ b/Doc/library/datetime.rst
@@ -14,7 +14,7 @@
 
 .. XXX what order should the types be discussed in?
 
-The :mod:`datetime` module supplies classes for manipulating dates and times.
+The :mod:`!datetime` module supplies classes for manipulating dates and times.
 
 While date and time arithmetic is supported, the focus of the implementation is
 on efficient attribute extraction for output formatting and manipulation.
@@ -70,7 +70,7 @@ These :class:`tzinfo` objects capture information about the 
offset from UTC
 time, the time zone name, and whether daylight saving time is in effect.
 
 Only one concrete :class:`tzinfo` class, the :class:`timezone` class, is
-supplied by the :mod:`datetime` module. The :class:`timezone` class can
+supplied by the :mod:`!datetime` module. The :class:`timezone` class can
 represent simple timezones with fixed offsets from UTC, such as UTC itself or
 North American EST and EDT timezones. Supporting timezones at deeper levels of
 detail is up to the application. The rules for time adjustment across the
@@ -80,7 +80,7 @@ standard suitable for every application aside from UTC.
 Constants
 -
 
-The :mod:`datetime` module exports the following constants:
+The :mod:`!datetime` module exports the following constants:
 
 .. data:: MINYEAR
 
@@ -631,7 +631,7 @@ Notes:
date2.toordinal()``. Date comparison raises :exc:`TypeError` if
the other comparand isn't also a :class:`date` object. However,
``NotImplemented`` is returned instead if the other comparand has a
-   :meth:`timetuple` attribute. This hook gives other kinds of date objects a
+   :attr:`~date.timetuple` attribute. This hook gives other kinds of date 
objects a
chance at implementing mixed-type comparison. If not, when a :class:`date`
object is compared to an object of a different type, :exc:`TypeError` is 
raised
unless the comparison is ``==`` or ``!=``. The latter cases return
@@ -1215,7 +1215,7 @@ Supported operations:
   object addresses, datetime comparison normally raises :exc:`TypeError` 
if the
   other comparand isn't also a :class:`.datetime` object. However,
   ``NotImplemented`` is returned instead if the other comparand has a
-  :meth:`timetuple` attribute. This hook gives other kinds of date objects 
a
+  :attr:`~.datetime.timetuple` attribute. This hook gives other kinds of 
date objects a
   chance at implementing mixed-type comparison. If not, when a 
:class:`.datetime`
   object is compared to an object of a different type, :exc:`TypeError` is 
raised
   unless the comparison is ``==`` or ``!=``. The latter cases return
@@ -1347,22 +1347,22 @@ Instance methods:
 
where ``yday = d.toordinal() - date(d.year, 1, 1).toordinal() + 1``
is the day number within the current year starting with ``1`` for January
-   1st. The :attr:`tm_isdst` flag of the result is set according to the
+   1st. The :attr:`~time.struct_time.tm_isdst` flag of the result is set 
according to the
:meth:`dst` method: :attr:`.tzinfo` is ``None`` or :meth:`dst` returns
-   ``None``, :attr:`tm_isdst` is set to ``-1``; else if :meth:`dst` returns a
-   non-zero value, :attr:`tm_isdst` is set to ``1``; else :attr:`tm_isdst` is
+   ``None``, :attr:`!tm_isdst` is set to ``-1``; else if :meth:`dst` returns a
+   non-zero value, :attr:`!tm_isdst` is set to ``1``; else :attr:`!tm_isdst` is
set to ``0``.
 
 
 .. method:: datetime.utctimetuple()
 
If :class:`.datetime` instance *d* is naive, this is the same as
-   ``d.timetuple()`` except that :attr:`tm_isdst` is forced to 0 regardless of 
what
+   ``d.timetuple()`` except that :attr:

[Python-checkins] gh-112050: Adapt collections.deque to Argument Clinic (#113963)

2024-01-29 Thread erlend-aasland
https://github.com/python/cpython/commit/c87233fd3fa77067013c35328f8c4884f0567a59
commit: c87233fd3fa77067013c35328f8c4884f0567a59
branch: main
author: mpage 
committer: erlend-aasland 
date: 2024-01-29T15:08:23Z
summary:

gh-112050: Adapt collections.deque to Argument Clinic (#113963)

files:
A Misc/NEWS.d/next/Core and 
Builtins/2024-01-11-22-58-45.gh-issue-112050.hDuvDW.rst
M Include/internal/pycore_global_objects_fini_generated.h
M Include/internal/pycore_global_strings.h
M Include/internal/pycore_runtime_init_generated.h
M Include/internal/pycore_unicodeobject_generated.h
M Modules/_collectionsmodule.c
M Modules/clinic/_collectionsmodule.c.h

diff --git a/Include/internal/pycore_global_objects_fini_generated.h 
b/Include/internal/pycore_global_objects_fini_generated.h
index e92707051c12b7..57505b5388fd6c 100644
--- a/Include/internal/pycore_global_objects_fini_generated.h
+++ b/Include/internal/pycore_global_objects_fini_generated.h
@@ -1049,6 +1049,7 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) {
 _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(max_length));
 _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(maxdigits));
 _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(maxevents));
+_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(maxlen));
 _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(maxmem));
 _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(maxsplit));
 _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(maxvalue));
diff --git a/Include/internal/pycore_global_strings.h 
b/Include/internal/pycore_global_strings.h
index eb60b80c964d42..0f4f3b61910241 100644
--- a/Include/internal/pycore_global_strings.h
+++ b/Include/internal/pycore_global_strings.h
@@ -538,6 +538,7 @@ struct _Py_global_strings {
 STRUCT_FOR_ID(max_length)
 STRUCT_FOR_ID(maxdigits)
 STRUCT_FOR_ID(maxevents)
+STRUCT_FOR_ID(maxlen)
 STRUCT_FOR_ID(maxmem)
 STRUCT_FOR_ID(maxsplit)
 STRUCT_FOR_ID(maxvalue)
diff --git a/Include/internal/pycore_runtime_init_generated.h 
b/Include/internal/pycore_runtime_init_generated.h
index 9b39de1d69c6c7..63a2b54c839a4b 100644
--- a/Include/internal/pycore_runtime_init_generated.h
+++ b/Include/internal/pycore_runtime_init_generated.h
@@ -1047,6 +1047,7 @@ extern "C" {
 INIT_ID(max_length), \
 INIT_ID(maxdigits), \
 INIT_ID(maxevents), \
+INIT_ID(maxlen), \
 INIT_ID(maxmem), \
 INIT_ID(maxsplit), \
 INIT_ID(maxvalue), \
diff --git a/Include/internal/pycore_unicodeobject_generated.h 
b/Include/internal/pycore_unicodeobject_generated.h
index 898d386f4cfd05..bf8cdd85e4be5c 100644
--- a/Include/internal/pycore_unicodeobject_generated.h
+++ b/Include/internal/pycore_unicodeobject_generated.h
@@ -1455,6 +1455,9 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp) {
 string = &_Py_ID(maxevents);
 assert(_PyUnicode_CheckConsistency(string, 1));
 _PyUnicode_InternInPlace(interp, &string);
+string = &_Py_ID(maxlen);
+assert(_PyUnicode_CheckConsistency(string, 1));
+_PyUnicode_InternInPlace(interp, &string);
 string = &_Py_ID(maxmem);
 assert(_PyUnicode_CheckConsistency(string, 1));
 _PyUnicode_InternInPlace(interp, &string);
diff --git a/Misc/NEWS.d/next/Core and 
Builtins/2024-01-11-22-58-45.gh-issue-112050.hDuvDW.rst b/Misc/NEWS.d/next/Core 
and Builtins/2024-01-11-22-58-45.gh-issue-112050.hDuvDW.rst
new file mode 100644
index 00..e5f3d5ea0cea25
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and 
Builtins/2024-01-11-22-58-45.gh-issue-112050.hDuvDW.rst 
@@ -0,0 +1 @@
+Convert :class:`collections.deque` to use Argument Clinic.
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index c8cd53de5e2262..ef77d34b10e47b 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -44,8 +44,11 @@ find_module_state_by_def(PyTypeObject *type)
 /*[clinic input]
 module _collections
 class _tuplegetter "_tuplegetterobject *" "clinic_state()->tuplegetter_type"
+class _collections.deque "dequeobject *" "clinic_state()->deque_type"
 [clinic start generated code]*/
-/*[clinic end generated code: output=da39a3ee5e6b4b0d input=7356042a89862e0e]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=a033cc2a8476b3f1]*/
+
+typedef struct dequeobject dequeobject;
 
 /* We can safely assume type to be the defining class,
  * since tuplegetter is not a base type */
@@ -53,6 +56,12 @@ class _tuplegetter "_tuplegetterobject *" 
"clinic_state()->tuplegetter_type"
 #include "clinic/_collectionsmodule.c.h"
 #undef clinic_state
 
+/*[python input]
+class dequeobject_converter(self_converter):
+type = "dequeobject *"
+[python start generated code]*/
+/*[python end generated code: output=da39a3ee5e6b4b0d input=b6ae4a3ff852be2f]*/
+
 /* collections module implementation of a deque() datatype
Written and maintained by Raymond D. Hettinger 
 */
@@ -121,7 +130,7 @@ typedef struct BLOCK {
 struct BLOCK *rightlink;
 } b

[Python-checkins] [3.12] gh-101100: Fix datetime reference warnings (GH-114661) (GH-114716)

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

[3.12] gh-101100: Fix datetime reference warnings (GH-114661) (GH-114716)

(cherry picked from commit e8b8f5e9c2da6a436360ce648061c90bdfcba863)

Co-authored-by: Skip Montanaro 
Co-authored-by: Serhiy Storchaka 

files:
M Doc/conf.py
M Doc/library/datetime.rst
M Doc/tools/.nitignore

diff --git a/Doc/conf.py b/Doc/conf.py
index 862820637a8a5a..e05741479dbf34 100644
--- a/Doc/conf.py
+++ b/Doc/conf.py
@@ -83,20 +83,25 @@
 nitpick_ignore = [
 # Standard C functions
 ('c:func', 'calloc'),
+('c:func', 'ctime'),
 ('c:func', 'dlopen'),
 ('c:func', 'exec'),
 ('c:func', 'fcntl'),
 ('c:func', 'fork'),
 ('c:func', 'free'),
+('c:func', 'gettimeofday'),
 ('c:func', 'gmtime'),
+('c:func', 'localeconv'),
 ('c:func', 'localtime'),
 ('c:func', 'main'),
 ('c:func', 'malloc'),
+('c:func', 'mktime'),
 ('c:func', 'printf'),
 ('c:func', 'realloc'),
 ('c:func', 'snprintf'),
 ('c:func', 'sprintf'),
 ('c:func', 'stat'),
+('c:func', 'strftime'),
 ('c:func', 'system'),
 ('c:func', 'time'),
 ('c:func', 'vsnprintf'),
diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst
index c74417e36eb402..0abb0d6f108cbd 100644
--- a/Doc/library/datetime.rst
+++ b/Doc/library/datetime.rst
@@ -14,7 +14,7 @@
 
 .. XXX what order should the types be discussed in?
 
-The :mod:`datetime` module supplies classes for manipulating dates and times.
+The :mod:`!datetime` module supplies classes for manipulating dates and times.
 
 While date and time arithmetic is supported, the focus of the implementation is
 on efficient attribute extraction for output formatting and manipulation.
@@ -70,7 +70,7 @@ These :class:`tzinfo` objects capture information about the 
offset from UTC
 time, the time zone name, and whether daylight saving time is in effect.
 
 Only one concrete :class:`tzinfo` class, the :class:`timezone` class, is
-supplied by the :mod:`datetime` module. The :class:`timezone` class can
+supplied by the :mod:`!datetime` module. The :class:`timezone` class can
 represent simple timezones with fixed offsets from UTC, such as UTC itself or
 North American EST and EDT timezones. Supporting timezones at deeper levels of
 detail is up to the application. The rules for time adjustment across the
@@ -80,7 +80,7 @@ standard suitable for every application aside from UTC.
 Constants
 -
 
-The :mod:`datetime` module exports the following constants:
+The :mod:`!datetime` module exports the following constants:
 
 .. data:: MINYEAR
 
@@ -631,7 +631,7 @@ Notes:
date2.toordinal()``. Date comparison raises :exc:`TypeError` if
the other comparand isn't also a :class:`date` object. However,
``NotImplemented`` is returned instead if the other comparand has a
-   :meth:`timetuple` attribute. This hook gives other kinds of date objects a
+   :attr:`~date.timetuple` attribute. This hook gives other kinds of date 
objects a
chance at implementing mixed-type comparison. If not, when a :class:`date`
object is compared to an object of a different type, :exc:`TypeError` is 
raised
unless the comparison is ``==`` or ``!=``. The latter cases return
@@ -1212,7 +1212,7 @@ Supported operations:
   object addresses, datetime comparison normally raises :exc:`TypeError` 
if the
   other comparand isn't also a :class:`.datetime` object. However,
   ``NotImplemented`` is returned instead if the other comparand has a
-  :meth:`timetuple` attribute. This hook gives other kinds of date objects 
a
+  :attr:`~.datetime.timetuple` attribute. This hook gives other kinds of 
date objects a
   chance at implementing mixed-type comparison. If not, when a 
:class:`.datetime`
   object is compared to an object of a different type, :exc:`TypeError` is 
raised
   unless the comparison is ``==`` or ``!=``. The latter cases return
@@ -1341,22 +1341,22 @@ Instance methods:
 
where ``yday = d.toordinal() - date(d.year, 1, 1).toordinal() + 1``
is the day number within the current year starting with ``1`` for January
-   1st. The :attr:`tm_isdst` flag of the result is set according to the
+   1st. The :attr:`~time.struct_time.tm_isdst` flag of the result is set 
according to the
:meth:`dst` method: :attr:`.tzinfo` is ``None`` or :meth:`dst` returns
-   ``None``, :attr:`tm_isdst` is set to ``-1``; else if :meth:`dst` returns a
-   non-zero value, :attr:`tm_isdst` is set to ``1``; else :attr:`tm_isdst` is
+   ``None``, :attr:`!tm_isdst` is set to ``-1``; else if :meth:`dst` returns a
+   non-zero value, :attr:`!tm_isdst` is set to ``1``; else :attr:`!tm_isdst` is
set to ``0``.
 
 
 .. method:: datetime.utctimetuple()
 
If :class:`.da

[Python-checkins] [3.11] gh-101100: Fix datetime reference warnings (GH-114661) (GH-114718)

2024-01-29 Thread serhiy-storchaka
https://github.com/python/cpython/commit/c67f94e385eed596de796ee950bfd246c038b0cf
commit: c67f94e385eed596de796ee950bfd246c038b0cf
branch: 3.11
author: Serhiy Storchaka 
committer: serhiy-storchaka 
date: 2024-01-29T15:20:05Z
summary:

[3.11] gh-101100: Fix datetime reference warnings (GH-114661) (GH-114718)

(cherry picked from commit e8b8f5e9c2da6a436360ce648061c90bdfcba863)

Co-authored-by: Skip Montanaro 

files:
M Doc/conf.py
M Doc/library/datetime.rst
M Doc/tools/.nitignore

diff --git a/Doc/conf.py b/Doc/conf.py
index e600c3d750af4a..c7f745b9db1d82 100644
--- a/Doc/conf.py
+++ b/Doc/conf.py
@@ -78,20 +78,25 @@
 nitpick_ignore = [
 # Standard C functions
 ('c:func', 'calloc'),
+('c:func', 'ctime'),
 ('c:func', 'dlopen'),
 ('c:func', 'exec'),
 ('c:func', 'fcntl'),
 ('c:func', 'fork'),
 ('c:func', 'free'),
+('c:func', 'gettimeofday'),
 ('c:func', 'gmtime'),
+('c:func', 'localeconv'),
 ('c:func', 'localtime'),
 ('c:func', 'main'),
 ('c:func', 'malloc'),
+('c:func', 'mktime'),
 ('c:func', 'printf'),
 ('c:func', 'realloc'),
 ('c:func', 'snprintf'),
 ('c:func', 'sprintf'),
 ('c:func', 'stat'),
+('c:func', 'strftime'),
 ('c:func', 'system'),
 ('c:func', 'vsnprintf'),
 # Standard C types
diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst
index 164836b0e1e49a..d97fa096730ec8 100644
--- a/Doc/library/datetime.rst
+++ b/Doc/library/datetime.rst
@@ -14,7 +14,7 @@
 
 .. XXX what order should the types be discussed in?
 
-The :mod:`datetime` module supplies classes for manipulating dates and times.
+The :mod:`!datetime` module supplies classes for manipulating dates and times.
 
 While date and time arithmetic is supported, the focus of the implementation is
 on efficient attribute extraction for output formatting and manipulation.
@@ -70,7 +70,7 @@ These :class:`tzinfo` objects capture information about the 
offset from UTC
 time, the time zone name, and whether daylight saving time is in effect.
 
 Only one concrete :class:`tzinfo` class, the :class:`timezone` class, is
-supplied by the :mod:`datetime` module. The :class:`timezone` class can
+supplied by the :mod:`!datetime` module. The :class:`timezone` class can
 represent simple timezones with fixed offsets from UTC, such as UTC itself or
 North American EST and EDT timezones. Supporting timezones at deeper levels of
 detail is up to the application. The rules for time adjustment across the
@@ -80,7 +80,7 @@ standard suitable for every application aside from UTC.
 Constants
 -
 
-The :mod:`datetime` module exports the following constants:
+The :mod:`!datetime` module exports the following constants:
 
 .. data:: MINYEAR
 
@@ -631,7 +631,7 @@ Notes:
date2.toordinal()``. Date comparison raises :exc:`TypeError` if
the other comparand isn't also a :class:`date` object. However,
``NotImplemented`` is returned instead if the other comparand has a
-   :meth:`timetuple` attribute. This hook gives other kinds of date objects a
+   :attr:`~date.timetuple` attribute. This hook gives other kinds of date 
objects a
chance at implementing mixed-type comparison. If not, when a :class:`date`
object is compared to an object of a different type, :exc:`TypeError` is 
raised
unless the comparison is ``==`` or ``!=``. The latter cases return
@@ -1204,7 +1204,7 @@ Supported operations:
   object addresses, datetime comparison normally raises :exc:`TypeError` 
if the
   other comparand isn't also a :class:`.datetime` object. However,
   ``NotImplemented`` is returned instead if the other comparand has a
-  :meth:`timetuple` attribute. This hook gives other kinds of date objects 
a
+  :attr:`~.datetime.timetuple` attribute. This hook gives other kinds of 
date objects a
   chance at implementing mixed-type comparison. If not, when a 
:class:`.datetime`
   object is compared to an object of a different type, :exc:`TypeError` is 
raised
   unless the comparison is ``==`` or ``!=``. The latter cases return
@@ -1333,22 +1333,22 @@ Instance methods:
 
where ``yday = d.toordinal() - date(d.year, 1, 1).toordinal() + 1``
is the day number within the current year starting with ``1`` for January
-   1st. The :attr:`tm_isdst` flag of the result is set according to the
+   1st. The :attr:`~time.struct_time.tm_isdst` flag of the result is set 
according to the
:meth:`dst` method: :attr:`.tzinfo` is ``None`` or :meth:`dst` returns
-   ``None``, :attr:`tm_isdst` is set to ``-1``; else if :meth:`dst` returns a
-   non-zero value, :attr:`tm_isdst` is set to ``1``; else :attr:`tm_isdst` is
+   ``None``, :attr:`!tm_isdst` is set to ``-1``; else if :meth:`dst` returns a
+   non-zero value, :attr:`!tm_isdst` is set to ``1``; else :attr:`!tm_isdst` is
set to ``0``.
 
 
 .. method:: datetime.utctimetuple()
 
If :class:`.datetime` instance *d* is naive, this is the same as
-   ``d.timetuple()`` except that :attr:`tm

[Python-checkins] gh-91325: Skip Stable ABI checks with Py_TRACE_REFS special build (GH-92046)

2024-01-29 Thread encukou
https://github.com/python/cpython/commit/15fe8cea174772060b24c96d335a498aba3b8ed4
commit: 15fe8cea174772060b24c96d335a498aba3b8ed4
branch: main
author: Petr Viktorin 
committer: encukou 
date: 2024-01-29T16:45:31+01:00
summary:

gh-91325: Skip Stable ABI checks with Py_TRACE_REFS special build (GH-92046)

Skip Stable ABI checks with Py_TRACE_REFS special build

This build is not compatible with Py_LIMITED_API nor with
the stable ABI.

files:
M Lib/test/test_stable_abi_ctypes.py
M Misc/stable_abi.toml
M Modules/_testcapi_feature_macros.inc
M Tools/build/stable_abi.py

diff --git a/Lib/test/test_stable_abi_ctypes.py 
b/Lib/test/test_stable_abi_ctypes.py
index 4976ac3642bbe4..90d45272838420 100644
--- a/Lib/test/test_stable_abi_ctypes.py
+++ b/Lib/test/test_stable_abi_ctypes.py
@@ -9,6 +9,13 @@
 from _testcapi import get_feature_macros
 
 feature_macros = get_feature_macros()
+
+# Stable ABI is incompatible with Py_TRACE_REFS builds due to PyObject
+# layout differences.
+# See https://github.com/python/cpython/issues/88299#issuecomment-1113366226
+if feature_macros['Py_TRACE_REFS']:
+raise unittest.SkipTest("incompatible with Py_TRACE_REFS.")
+
 ctypes_test = import_module('ctypes')
 
 class TestStableABIAvailability(unittest.TestCase):
@@ -441,7 +448,9 @@ def test_windows_feature_macros(self):
 "PyModule_AddObjectRef",
 "PyModule_AddStringConstant",
 "PyModule_AddType",
+"PyModule_Create2",
 "PyModule_ExecDef",
+"PyModule_FromDefAndSpec2",
 "PyModule_GetDef",
 "PyModule_GetDict",
 "PyModule_GetFilename",
@@ -911,6 +920,13 @@ def test_windows_feature_macros(self):
 "_Py_TrueStruct",
 "_Py_VaBuildValue_SizeT",
 )
+if feature_macros['HAVE_FORK']:
+SYMBOL_NAMES += (
+'PyOS_AfterFork',
+'PyOS_AfterFork_Child',
+'PyOS_AfterFork_Parent',
+'PyOS_BeforeFork',
+)
 if feature_macros['MS_WINDOWS']:
 SYMBOL_NAMES += (
 'PyErr_SetExcFromWindowsErr',
@@ -926,17 +942,6 @@ def test_windows_feature_macros(self):
 'PyUnicode_DecodeMBCSStateful',
 'PyUnicode_EncodeCodePage',
 )
-if feature_macros['HAVE_FORK']:
-SYMBOL_NAMES += (
-'PyOS_AfterFork',
-'PyOS_AfterFork_Child',
-'PyOS_AfterFork_Parent',
-'PyOS_BeforeFork',
-)
-if feature_macros['USE_STACKCHECK']:
-SYMBOL_NAMES += (
-'PyOS_CheckStack',
-)
 if feature_macros['PY_HAVE_THREAD_NATIVE_ID']:
 SYMBOL_NAMES += (
 'PyThread_get_thread_native_id',
@@ -946,14 +951,23 @@ def test_windows_feature_macros(self):
 '_Py_NegativeRefcount',
 '_Py_RefTotal',
 )
+if feature_macros['Py_TRACE_REFS']:
+SYMBOL_NAMES += (
+)
+if feature_macros['USE_STACKCHECK']:
+SYMBOL_NAMES += (
+'PyOS_CheckStack',
+)
 
 EXPECTED_FEATURE_MACROS = set(['HAVE_FORK',
  'MS_WINDOWS',
  'PY_HAVE_THREAD_NATIVE_ID',
  'Py_REF_DEBUG',
+ 'Py_TRACE_REFS',
  'USE_STACKCHECK'])
 WINDOWS_FEATURE_MACROS = {'HAVE_FORK': False,
  'MS_WINDOWS': True,
  'PY_HAVE_THREAD_NATIVE_ID': True,
  'Py_REF_DEBUG': 'maybe',
+ 'Py_TRACE_REFS': 'maybe',
  'USE_STACKCHECK': 'maybe'}
diff --git a/Misc/stable_abi.toml b/Misc/stable_abi.toml
index 22b25dd0ec141f..2e6b0fff9cd770 100644
--- a/Misc/stable_abi.toml
+++ b/Misc/stable_abi.toml
@@ -78,6 +78,10 @@
 [feature_macro.Py_REF_DEBUG]
 doc = 'when Python is compiled in debug mode (with Py_REF_DEBUG)'
 windows = 'maybe'
+[feature_macro.Py_TRACE_REFS]
+# nb. This mode is not compatible with Stable ABI/Limited API.
+doc = 'when Python is compiled with Py_TRACE_REFS'
+windows = 'maybe'
 
 
 # Mentioned in PEP 384:
diff --git a/Modules/_testcapi_feature_macros.inc 
b/Modules/_testcapi_feature_macros.inc
index a076e714980074..f5f3524f2c0177 100644
--- a/Modules/_testcapi_feature_macros.inc
+++ b/Modules/_testcapi_feature_macros.inc
@@ -38,6 +38,15 @@ if (res) {
 Py_DECREF(result); return NULL;
 }
 
+#ifdef Py_TRACE_REFS
+res = PyDict_SetItemString(result, "Py_TRACE_REFS", Py_True);
+#else
+res = PyDict_SetItemString(result, "Py_TRACE_REFS", Py_False);
+#endif
+if (res) {
+Py_DECREF(result); return NULL;
+}
+
 #ifdef USE_STACKCHECK
 res = PyDict_SetItemString(result, "USE_STACKCHECK", Py_True);
 #else
diff --git a/Tools/build/stable_abi.py b/Tools/build/stable_abi.py
index 85c437d521a15a..83146622c74f94 100644
--- a/Tools/build/stable_abi.py
+++ b/Tools/build/stable_abi.py
@@ -278,6 +278,13 @@ def gen_ctypes_test(manifest, args, outfile):
 from _testcapi import get_feature_macros
 
 feature_macros = get_feature_macros()
+
+# Stable ABI is incompatible with Py_TRACE_REFS builds due to PyObject
+# layout differences.
+# See 
https://github.com/python/cpython/issues/88299#issuecomment-1113366226
+if feature_macros['Py_TRACE_REFS']:
+raise unittest.SkipTest("incompatible with Py_TRACE_REFS.")
+
 ctypes_test = import_module('ctypes')
 
 class TestStableABIAvail

[Python-checkins] Remove limit in calendar CLI help message for year arg (GH-114719)

2024-01-29 Thread serhiy-storchaka
https://github.com/python/cpython/commit/0f54ee4c6cdba74492183eb2dd142393c7dba403
commit: 0f54ee4c6cdba74492183eb2dd142393c7dba403
branch: main
author: Steven Ward 
committer: serhiy-storchaka 
date: 2024-01-29T18:00:15+02:00
summary:

Remove limit in calendar CLI help message for year arg (GH-114719)

The limit was removed in 66c88ce30ca2b23daa37038e1a3c0de98f241f50 (GH-4109).

files:
M Lib/calendar.py

diff --git a/Lib/calendar.py b/Lib/calendar.py
index 03469d8ac96bcd..3c79540f986b63 100644
--- a/Lib/calendar.py
+++ b/Lib/calendar.py
@@ -737,7 +737,7 @@ def main(args=None):
 parser.add_argument(
 "year",
 nargs='?', type=int,
-help="year number (1-)"
+help="year number"
 )
 parser.add_argument(
 "month",

___
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-85984: Add POSIX pseudo-terminal functions. (GH-102413)

2024-01-29 Thread encukou
https://github.com/python/cpython/commit/e351ca3c205860e94cad5da25c74bd76933f5f11
commit: e351ca3c205860e94cad5da25c74bd76933f5f11
branch: main
author: Soumendra Ganguly <[email protected]>
committer: encukou 
date: 2024-01-29T16:10:28Z
summary:

gh-85984: Add POSIX pseudo-terminal functions. (GH-102413)


Signed-off-by: Soumendra Ganguly 
Co-authored-by: Gregory P. Smith 
Co-authored-by: Petr Viktorin 

files:
A Misc/NEWS.d/next/Library/2023-03-15-03-21-18.gh-issue-85984.Xaq6ZN.rst
M Doc/conf.py
M Doc/library/os.rst
M Lib/test/test_os.py
M Modules/clinic/posixmodule.c.h
M Modules/posixmodule.c
M configure
M configure.ac
M pyconfig.h.in

diff --git a/Doc/conf.py b/Doc/conf.py
index a96e7787d167a3..e12128ad356e1b 100644
--- a/Doc/conf.py
+++ b/Doc/conf.py
@@ -97,12 +97,16 @@
 ('c:func', 'free'),
 ('c:func', 'gettimeofday'),
 ('c:func', 'gmtime'),
+('c:func', 'grantpt'),
 ('c:func', 'localeconv'),
 ('c:func', 'localtime'),
 ('c:func', 'main'),
 ('c:func', 'malloc'),
 ('c:func', 'mktime'),
+('c:func', 'posix_openpt'),
 ('c:func', 'printf'),
+('c:func', 'ptsname'),
+('c:func', 'ptsname_r'),
 ('c:func', 'realloc'),
 ('c:func', 'snprintf'),
 ('c:func', 'sprintf'),
@@ -110,6 +114,7 @@
 ('c:func', 'strftime'),
 ('c:func', 'system'),
 ('c:func', 'time'),
+('c:func', 'unlockpt'),
 ('c:func', 'vsnprintf'),
 # Standard C types
 ('c:type', 'FILE'),
diff --git a/Doc/library/os.rst b/Doc/library/os.rst
index 0008ec6a40c76f..cc9f3e75a80c51 100644
--- a/Doc/library/os.rst
+++ b/Doc/library/os.rst
@@ -1122,6 +1122,20 @@ as internal buffering of data.
.. versionchanged:: 3.12
   Added support for pipes on Windows.
 
+
+.. function:: grantpt(fd, /)
+
+   Grant access to the slave pseudo-terminal device associated with the
+   master pseudo-terminal device to which the file descriptor *fd* refers.
+   The file descriptor *fd* is not closed upon failure.
+
+   Calls the C standard library function :c:func:`grantpt`.
+
+   .. availability:: Unix, not Emscripten, not WASI.
+
+   .. versionadded:: 3.13
+
+
 .. function:: isatty(fd, /)
 
Return ``True`` if the file descriptor *fd* is open and connected to a
@@ -1429,6 +1443,23 @@ or `the MSDN 
`_ on Windo
.. versionadded:: 3.3
 
 
+.. function:: posix_openpt(oflag, /)
+
+   Open and return a file descriptor for a master pseudo-terminal device.
+
+   Calls the C standard library function :c:func:`posix_openpt`. The *oflag*
+   argument is used to set file status flags and file access modes as
+   specified in the manual page of :c:func:`posix_openpt` of your system.
+
+   The returned file descriptor is :ref:`non-inheritable `.
+   If the value :data:`O_CLOEXEC` is available on the system, it is added to
+   *oflag*.
+
+   .. availability:: Unix, not Emscripten, not WASI.
+
+   .. versionadded:: 3.13
+
+
 .. function:: preadv(fd, buffers, offset, flags=0, /)
 
Read from a file descriptor *fd* at a position of *offset* into mutable
@@ -1486,6 +1517,21 @@ or `the MSDN 
`_ on Windo
.. versionadded:: 3.7
 
 
+.. function:: ptsname(fd, /)
+
+   Return the name of the slave pseudo-terminal device associated with the
+   master pseudo-terminal device to which the file descriptor *fd* refers.
+   The file descriptor *fd* is not closed upon failure.
+
+   Calls the reentrant C standard library function :c:func:`ptsname_r` if
+   it is available; otherwise, the C standard library function
+   :c:func:`ptsname`, which is not guaranteed to be thread-safe, is called.
+
+   .. availability:: Unix, not Emscripten, not WASI.
+
+   .. versionadded:: 3.13
+
+
 .. function:: pwrite(fd, str, offset, /)
 
Write the bytestring in *str* to file descriptor *fd* at position of
@@ -1738,6 +1784,19 @@ or `the MSDN 
`_ on Windo
.. availability:: Unix.
 
 
+.. function:: unlockpt(fd, /)
+
+   Unlock the slave pseudo-terminal device associated with the master
+   pseudo-terminal device to which the file descriptor *fd* refers.
+   The file descriptor *fd* is not closed upon failure.
+
+   Calls the C standard library function :c:func:`unlockpt`.
+
+   .. availability:: Unix, not Emscripten, not WASI.
+
+   .. versionadded:: 3.13
+
+
 .. function:: write(fd, str, /)
 
Write the bytestring in *str* to file descriptor *fd*.
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index e6f0dfde8cb4ae..ed79a2c24ef30b 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -4536,13 +4536,46 @@ def test_dup2(self):
 self.assertEqual(os.dup2(fd, fd3, inheritable=False), fd3)
 self.assertFalse(os.get_inheritable(fd3))
 
[email protected](hasattr(os, 'openpty'), "need os.openpty()")
[email protected](hasattr(os, 'openpty'), "need os.openpty()")
+class PseudoterminalTests(unitte

[Python-checkins] Fix more references to datetime and time classes (GH-114717)

2024-01-29 Thread serhiy-storchaka
https://github.com/python/cpython/commit/39c766b579cabc71a4a50773d299d4350221a70b
commit: 39c766b579cabc71a4a50773d299d4350221a70b
branch: main
author: Serhiy Storchaka 
committer: serhiy-storchaka 
date: 2024-01-29T18:20:13+02:00
summary:

Fix more references to datetime and time classes (GH-114717)

They could be confused with references to datetime and time modules.

files:
M Doc/library/datetime.rst
M Doc/library/mailbox.rst
M Doc/whatsnew/3.8.rst
M Misc/NEWS.d/3.13.0a1.rst

diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst
index 47ecb0ba331bdc..4ff049c8709289 100644
--- a/Doc/library/datetime.rst
+++ b/Doc/library/datetime.rst
@@ -1255,7 +1255,7 @@ Instance methods:
``tzinfo=None`` can be specified to create a naive datetime from an aware
datetime with no conversion of date and time data.
 
-   :class:`datetime` objects are also supported by generic function
+   :class:`.datetime` objects are also supported by generic function
:func:`copy.replace`.
 
.. versionchanged:: 3.6
@@ -1678,7 +1678,7 @@ Usage of ``KabulTz`` from above::
 :class:`.time` Objects
 --
 
-A :class:`time` object represents a (local) time of day, independent of any 
particular
+A :class:`.time` object represents a (local) time of day, independent of any 
particular
 day, and subject to adjustment via a :class:`tzinfo` object.
 
 .. class:: time(hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, 
fold=0)
@@ -1836,7 +1836,7 @@ Instance methods:
``tzinfo=None`` can be specified to create a naive :class:`.time` from an
aware :class:`.time`, without conversion of the time data.
 
-   :class:`time` objects are also supported by generic function
+   :class:`.time` objects are also supported by generic function
:func:`copy.replace`.
 
.. versionchanged:: 3.6
@@ -2522,7 +2522,7 @@ information, which are supported in ``datetime.strptime`` 
but are discarded by
 ``time.strptime``.
 
 For :class:`.time` objects, the format codes for year, month, and day should 
not
-be used, as :class:`time` objects have no such values. If they're used anyway,
+be used, as :class:`!time` objects have no such values. If they're used anyway,
 ``1900`` is substituted for the year, and ``1`` for the month and day.
 
 For :class:`date` objects, the format codes for hours, minutes, seconds, and
diff --git a/Doc/library/mailbox.rst b/Doc/library/mailbox.rst
index fa5b273093f583..a613548c9e518e 100644
--- a/Doc/library/mailbox.rst
+++ b/Doc/library/mailbox.rst
@@ -1136,8 +1136,8 @@ When a :class:`!MaildirMessage` instance is created based 
upon a
   leading "From " or trailing newline. For convenience, *time_* may be
   specified and will be formatted appropriately and appended to *from_*. If
   *time_* is specified, it should be a :class:`time.struct_time` instance, 
a
-  tuple suitable for passing to :meth:`time.strftime`, or ``True`` (to use
-  :meth:`time.gmtime`).
+  tuple suitable for passing to :func:`time.strftime`, or ``True`` (to use
+  :func:`time.gmtime`).
 
 
.. method:: get_flags()
@@ -1508,8 +1508,8 @@ When a :class:`!BabylMessage` instance is created based 
upon an
   leading "From " or trailing newline. For convenience, *time_* may be
   specified and will be formatted appropriately and appended to *from_*. If
   *time_* is specified, it should be a :class:`time.struct_time` instance, 
a
-  tuple suitable for passing to :meth:`time.strftime`, or ``True`` (to use
-  :meth:`time.gmtime`).
+  tuple suitable for passing to :func:`time.strftime`, or ``True`` (to use
+  :func:`time.gmtime`).
 
 
.. method:: get_flags()
diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst
index 304d1b4ef4efe8..b041e592d61ed1 100644
--- a/Doc/whatsnew/3.8.rst
+++ b/Doc/whatsnew/3.8.rst
@@ -754,8 +754,8 @@ datetime
 
 
 Added new alternate constructors :meth:`datetime.date.fromisocalendar` and
-:meth:`datetime.datetime.fromisocalendar`, which construct :class:`date` and
-:class:`datetime` objects respectively from ISO year, week number, and weekday;
+:meth:`datetime.datetime.fromisocalendar`, which construct 
:class:`~datetime.date` and
+:class:`~datetime.datetime` objects respectively from ISO year, week number, 
and weekday;
 these are the inverse of each class's ``isocalendar`` method.
 (Contributed by Paul Ganssle in :issue:`36004`.)
 
diff --git a/Misc/NEWS.d/3.13.0a1.rst b/Misc/NEWS.d/3.13.0a1.rst
index 102bddcee5c5c2..d385b6a4504f97 100644
--- a/Misc/NEWS.d/3.13.0a1.rst
+++ b/Misc/NEWS.d/3.13.0a1.rst
@@ -2276,7 +2276,7 @@ creation.
 .. nonce: m2H5Bk
 .. section: Library
 
-Remove unnecessary extra ``__slots__`` in :py:class:`datetime`\'s pure
+Remove unnecessary extra ``__slots__`` in :class:`~datetime.datetime`\'s pure
 python implementation to reduce memory size, as they are defined in the
 superclass. Patch by James Hilton-Balfe
 

___
Python-checkins mailing list -- python-ch

[Python-checkins] [3.12] Remove limit in calendar CLI help message for year arg (GH-114719) (GH-114722)

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

[3.12] Remove limit in calendar CLI help message for year arg (GH-114719) 
(GH-114722)

The limit was removed in 66c88ce30ca2b23daa37038e1a3c0de98f241f50 (GH-4109).
(cherry picked from commit 0f54ee4c6cdba74492183eb2dd142393c7dba403)

Co-authored-by: Steven Ward 

files:
M Lib/calendar.py

diff --git a/Lib/calendar.py b/Lib/calendar.py
index baab52a1578929..97d7cab3365220 100644
--- a/Lib/calendar.py
+++ b/Lib/calendar.py
@@ -739,7 +739,7 @@ def main(args):
 parser.add_argument(
 "year",
 nargs='?', type=int,
-help="year number (1-)"
+help="year number"
 )
 parser.add_argument(
 "month",

___
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] Remove limit in calendar CLI help message for year arg (GH-114719) (GH-114723)

2024-01-29 Thread serhiy-storchaka
https://github.com/python/cpython/commit/55bddca1338614e671101d1fd7f28fa7dc6bebc9
commit: 55bddca1338614e671101d1fd7f28fa7dc6bebc9
branch: 3.11
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka 
date: 2024-01-29T16:41:45Z
summary:

[3.11] Remove limit in calendar CLI help message for year arg (GH-114719) 
(GH-114723)

The limit was removed in 66c88ce30ca2b23daa37038e1a3c0de98f241f50 (GH-4109).
(cherry picked from commit 0f54ee4c6cdba74492183eb2dd142393c7dba403)

Co-authored-by: Steven Ward 

files:
M Lib/calendar.py

diff --git a/Lib/calendar.py b/Lib/calendar.py
index 7cdf9311b57ce2..27a1e093620c3c 100644
--- a/Lib/calendar.py
+++ b/Lib/calendar.py
@@ -709,7 +709,7 @@ def main(args):
 parser.add_argument(
 "year",
 nargs='?', type=int,
-help="year number (1-)"
+help="year number"
 )
 parser.add_argument(
 "month",

___
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-112240: Add option to calendar module CLI to specify the weekday to start each week (GH-112241)

2024-01-29 Thread serhiy-storchaka
https://github.com/python/cpython/commit/2c089b09ac0872e08d146c55ed60d754154761c3
commit: 2c089b09ac0872e08d146c55ed60d754154761c3
branch: main
author: Steven Ward 
committer: serhiy-storchaka 
date: 2024-01-29T16:58:21Z
summary:

gh-112240: Add option to calendar module CLI to specify the weekday to start 
each week (GH-112241)

files:
A Misc/NEWS.d/next/Library/2023-11-18-16-30-21.gh-issue-112240.YXS0tj.rst
M Doc/library/calendar.rst
M Lib/calendar.py

diff --git a/Doc/library/calendar.rst b/Doc/library/calendar.rst
index 6586f539a8da4f..c4dcf5641d6066 100644
--- a/Doc/library/calendar.rst
+++ b/Doc/library/calendar.rst
@@ -586,10 +586,16 @@ The following options are accepted:
or as an HTML document.
 
 
+.. option:: --first-weekday WEEKDAY, -f WEEKDAY
+
+   The weekday to start each week.
+   Must be a number between 0 (Monday) and 6 (Sunday).
+   Defaults to 0.
+
+
 .. option:: year
 
The year to print the calendar for.
-   Must be a number between 1 and .
Defaults to the current year.
 
 
diff --git a/Lib/calendar.py b/Lib/calendar.py
index 3c79540f986b63..833ce331b14a0c 100644
--- a/Lib/calendar.py
+++ b/Lib/calendar.py
@@ -734,6 +734,11 @@ def main(args=None):
 choices=("text", "html"),
 help="output type (text or html)"
 )
+parser.add_argument(
+"-f", "--first-weekday",
+type=int, default=0,
+help="weekday (0 is Monday, 6 is Sunday) to start each week (default 
0)"
+)
 parser.add_argument(
 "year",
 nargs='?', type=int,
@@ -761,6 +766,7 @@ def main(args=None):
 cal = LocaleHTMLCalendar(locale=locale)
 else:
 cal = HTMLCalendar()
+cal.setfirstweekday(options.first_weekday)
 encoding = options.encoding
 if encoding is None:
 encoding = sys.getdefaultencoding()
@@ -775,6 +781,7 @@ def main(args=None):
 cal = LocaleTextCalendar(locale=locale)
 else:
 cal = TextCalendar()
+cal.setfirstweekday(options.first_weekday)
 optdict = dict(w=options.width, l=options.lines)
 if options.month is None:
 optdict["c"] = options.spacing
diff --git 
a/Misc/NEWS.d/next/Library/2023-11-18-16-30-21.gh-issue-112240.YXS0tj.rst 
b/Misc/NEWS.d/next/Library/2023-11-18-16-30-21.gh-issue-112240.YXS0tj.rst
new file mode 100644
index 00..686f0311e80dcb
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-11-18-16-30-21.gh-issue-112240.YXS0tj.rst
@@ -0,0 +1,2 @@
+Add option to calendar module CLI to specify the weekday to start each week.
+Patch by Steven Ward.

___
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] Fix more references to datetime and time classes (GH-114717) (GH-114726)

2024-01-29 Thread serhiy-storchaka
https://github.com/python/cpython/commit/3dd3b301b6f6a9a18cfa07d965da15c4908b90dd
commit: 3dd3b301b6f6a9a18cfa07d965da15c4908b90dd
branch: 3.11
author: Serhiy Storchaka 
committer: serhiy-storchaka 
date: 2024-01-29T16:59:59Z
summary:

[3.11] Fix more references to datetime and time classes (GH-114717) (GH-114726)

They could be confused with references to datetime and time modules.
(cherry picked from commit 39c766b579cabc71a4a50773d299d4350221a70b)

files:
M Doc/library/datetime.rst
M Doc/library/mailbox.rst
M Doc/whatsnew/3.8.rst

diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst
index d97fa096730ec8..755f937f78a325 100644
--- a/Doc/library/datetime.rst
+++ b/Doc/library/datetime.rst
@@ -1664,7 +1664,7 @@ Usage of ``KabulTz`` from above::
 :class:`.time` Objects
 --
 
-A :class:`time` object represents a (local) time of day, independent of any 
particular
+A :class:`.time` object represents a (local) time of day, independent of any 
particular
 day, and subject to adjustment via a :class:`tzinfo` object.
 
 .. class:: time(hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, 
fold=0)
@@ -2497,7 +2497,7 @@ information, which are supported in ``datetime.strptime`` 
but are discarded by
 ``time.strptime``.
 
 For :class:`.time` objects, the format codes for year, month, and day should 
not
-be used, as :class:`time` objects have no such values. If they're used anyway,
+be used, as :class:`!time` objects have no such values. If they're used anyway,
 ``1900`` is substituted for the year, and ``1`` for the month and day.
 
 For :class:`date` objects, the format codes for hours, minutes, seconds, and
diff --git a/Doc/library/mailbox.rst b/Doc/library/mailbox.rst
index fab88bfc7e165a..9e737cd5ee449e 100644
--- a/Doc/library/mailbox.rst
+++ b/Doc/library/mailbox.rst
@@ -1027,8 +1027,8 @@ When a :class:`!MaildirMessage` instance is created based 
upon a
   leading "From " or trailing newline. For convenience, *time_* may be
   specified and will be formatted appropriately and appended to *from_*. If
   *time_* is specified, it should be a :class:`time.struct_time` instance, 
a
-  tuple suitable for passing to :meth:`time.strftime`, or ``True`` (to use
-  :meth:`time.gmtime`).
+  tuple suitable for passing to :func:`time.strftime`, or ``True`` (to use
+  :func:`time.gmtime`).
 
 
.. method:: get_flags()
@@ -1399,8 +1399,8 @@ When a :class:`!BabylMessage` instance is created based 
upon an
   leading "From " or trailing newline. For convenience, *time_* may be
   specified and will be formatted appropriately and appended to *from_*. If
   *time_* is specified, it should be a :class:`time.struct_time` instance, 
a
-  tuple suitable for passing to :meth:`time.strftime`, or ``True`` (to use
-  :meth:`time.gmtime`).
+  tuple suitable for passing to :func:`time.strftime`, or ``True`` (to use
+  :func:`time.gmtime`).
 
 
.. method:: get_flags()
diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst
index 4515010635fe08..b140e3bc6c5efa 100644
--- a/Doc/whatsnew/3.8.rst
+++ b/Doc/whatsnew/3.8.rst
@@ -754,8 +754,8 @@ datetime
 
 
 Added new alternate constructors :meth:`datetime.date.fromisocalendar` and
-:meth:`datetime.datetime.fromisocalendar`, which construct :class:`date` and
-:class:`datetime` objects respectively from ISO year, week number, and weekday;
+:meth:`datetime.datetime.fromisocalendar`, which construct 
:class:`~datetime.date` and
+:class:`~datetime.datetime` objects respectively from ISO year, week number, 
and weekday;
 these are the inverse of each class's ``isocalendar`` method.
 (Contributed by Paul Ganssle in :issue:`36004`.)
 

___
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] Fix more references to datetime and time classes (GH-114717) (GH-114725)

2024-01-29 Thread serhiy-storchaka
https://github.com/python/cpython/commit/eed05e271c517e1afbea9566e2259ef63105986e
commit: eed05e271c517e1afbea9566e2259ef63105986e
branch: 3.12
author: Serhiy Storchaka 
committer: serhiy-storchaka 
date: 2024-01-29T17:01:24Z
summary:

[3.12] Fix more references to datetime and time classes (GH-114717) (GH-114725)

They could be confused with references to datetime and time modules.
(cherry picked from commit 39c766b579cabc71a4a50773d299d4350221a70b)

Co-authored-by: Serhiy Storchaka 

files:
M Doc/library/datetime.rst
M Doc/library/mailbox.rst
M Doc/whatsnew/3.8.rst

diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst
index 0abb0d6f108cbd..decb7fe304b91a 100644
--- a/Doc/library/datetime.rst
+++ b/Doc/library/datetime.rst
@@ -1672,7 +1672,7 @@ Usage of ``KabulTz`` from above::
 :class:`.time` Objects
 --
 
-A :class:`time` object represents a (local) time of day, independent of any 
particular
+A :class:`.time` object represents a (local) time of day, independent of any 
particular
 day, and subject to adjustment via a :class:`tzinfo` object.
 
 .. class:: time(hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, 
fold=0)
@@ -2513,7 +2513,7 @@ information, which are supported in ``datetime.strptime`` 
but are discarded by
 ``time.strptime``.
 
 For :class:`.time` objects, the format codes for year, month, and day should 
not
-be used, as :class:`time` objects have no such values. If they're used anyway,
+be used, as :class:`!time` objects have no such values. If they're used anyway,
 ``1900`` is substituted for the year, and ``1`` for the month and day.
 
 For :class:`date` objects, the format codes for hours, minutes, seconds, and
diff --git a/Doc/library/mailbox.rst b/Doc/library/mailbox.rst
index fab88bfc7e165a..9e737cd5ee449e 100644
--- a/Doc/library/mailbox.rst
+++ b/Doc/library/mailbox.rst
@@ -1027,8 +1027,8 @@ When a :class:`!MaildirMessage` instance is created based 
upon a
   leading "From " or trailing newline. For convenience, *time_* may be
   specified and will be formatted appropriately and appended to *from_*. If
   *time_* is specified, it should be a :class:`time.struct_time` instance, 
a
-  tuple suitable for passing to :meth:`time.strftime`, or ``True`` (to use
-  :meth:`time.gmtime`).
+  tuple suitable for passing to :func:`time.strftime`, or ``True`` (to use
+  :func:`time.gmtime`).
 
 
.. method:: get_flags()
@@ -1399,8 +1399,8 @@ When a :class:`!BabylMessage` instance is created based 
upon an
   leading "From " or trailing newline. For convenience, *time_* may be
   specified and will be formatted appropriately and appended to *from_*. If
   *time_* is specified, it should be a :class:`time.struct_time` instance, 
a
-  tuple suitable for passing to :meth:`time.strftime`, or ``True`` (to use
-  :meth:`time.gmtime`).
+  tuple suitable for passing to :func:`time.strftime`, or ``True`` (to use
+  :func:`time.gmtime`).
 
 
.. method:: get_flags()
diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst
index eb7592cf3da2d4..bfe8f2b818b402 100644
--- a/Doc/whatsnew/3.8.rst
+++ b/Doc/whatsnew/3.8.rst
@@ -754,8 +754,8 @@ datetime
 
 
 Added new alternate constructors :meth:`datetime.date.fromisocalendar` and
-:meth:`datetime.datetime.fromisocalendar`, which construct :class:`date` and
-:class:`datetime` objects respectively from ISO year, week number, and weekday;
+:meth:`datetime.datetime.fromisocalendar`, which construct 
:class:`~datetime.date` and
+:class:`~datetime.datetime` objects respectively from ISO year, week number, 
and weekday;
 these are the inverse of each class's ``isocalendar`` method.
 (Contributed by Paul Ganssle in :issue:`36004`.)
 

___
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-112075: Use PyMem_* for allocating dict keys objects (#114543)

2024-01-29 Thread DinoV
https://github.com/python/cpython/commit/3d716655d22dc14e79ac0d30f33eef0a49efdac0
commit: 3d716655d22dc14e79ac0d30f33eef0a49efdac0
branch: main
author: Dino Viehland 
committer: DinoV 
date: 2024-01-29T09:38:03-08:00
summary:

gh-112075: Use PyMem_* for allocating dict keys objects (#114543)

Use PyMem_* for keys allocation

files:
M Objects/dictobject.c

diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index e608b91679b568..c5477ab15f8dc9 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -262,7 +262,7 @@ _PyDict_ClearFreeList(PyInterpreterState *interp)
 PyObject_GC_Del(op);
 }
 while (state->keys_numfree) {
-PyObject_Free(state->keys_free_list[--state->keys_numfree]);
+PyMem_Free(state->keys_free_list[--state->keys_numfree]);
 }
 #endif
 }
@@ -332,6 +332,22 @@ dictkeys_decref(PyInterpreterState *interp, 
PyDictKeysObject *dk)
 _Py_DecRefTotal(_PyInterpreterState_GET());
 #endif
 if (--dk->dk_refcnt == 0) {
+if (DK_IS_UNICODE(dk)) {
+PyDictUnicodeEntry *entries = DK_UNICODE_ENTRIES(dk);
+Py_ssize_t i, n;
+for (i = 0, n = dk->dk_nentries; i < n; i++) {
+Py_XDECREF(entries[i].me_key);
+Py_XDECREF(entries[i].me_value);
+}
+}
+else {
+PyDictKeyEntry *entries = DK_ENTRIES(dk);
+Py_ssize_t i, n;
+for (i = 0, n = dk->dk_nentries; i < n; i++) {
+Py_XDECREF(entries[i].me_key);
+Py_XDECREF(entries[i].me_value);
+}
+}
 free_keys_object(interp, dk);
 }
 }
@@ -640,9 +656,9 @@ new_keys_object(PyInterpreterState *interp, uint8_t 
log2_size, bool unicode)
 else
 #endif
 {
-dk = PyObject_Malloc(sizeof(PyDictKeysObject)
- + ((size_t)1 << log2_bytes)
- + entry_size * usable);
+dk = PyMem_Malloc(sizeof(PyDictKeysObject)
+  + ((size_t)1 << log2_bytes)
+  + entry_size * usable);
 if (dk == NULL) {
 PyErr_NoMemory();
 return NULL;
@@ -666,23 +682,6 @@ new_keys_object(PyInterpreterState *interp, uint8_t 
log2_size, bool unicode)
 static void
 free_keys_object(PyInterpreterState *interp, PyDictKeysObject *keys)
 {
-assert(keys != Py_EMPTY_KEYS);
-if (DK_IS_UNICODE(keys)) {
-PyDictUnicodeEntry *entries = DK_UNICODE_ENTRIES(keys);
-Py_ssize_t i, n;
-for (i = 0, n = keys->dk_nentries; i < n; i++) {
-Py_XDECREF(entries[i].me_key);
-Py_XDECREF(entries[i].me_value);
-}
-}
-else {
-PyDictKeyEntry *entries = DK_ENTRIES(keys);
-Py_ssize_t i, n;
-for (i = 0, n = keys->dk_nentries; i < n; i++) {
-Py_XDECREF(entries[i].me_key);
-Py_XDECREF(entries[i].me_value);
-}
-}
 #if PyDict_MAXFREELIST > 0
 struct _Py_dict_state *state = get_dict_state(interp);
 #ifdef Py_DEBUG
@@ -697,7 +696,7 @@ free_keys_object(PyInterpreterState *interp, 
PyDictKeysObject *keys)
 return;
 }
 #endif
-PyObject_Free(keys);
+PyMem_Free(keys);
 }
 
 static inline PyDictValues*
@@ -798,7 +797,7 @@ clone_combined_dict_keys(PyDictObject *orig)
 assert(orig->ma_keys->dk_refcnt == 1);
 
 size_t keys_size = _PyDict_KeysSize(orig->ma_keys);
-PyDictKeysObject *keys = PyObject_Malloc(keys_size);
+PyDictKeysObject *keys = PyMem_Malloc(keys_size);
 if (keys == NULL) {
 PyErr_NoMemory();
 return NULL;
@@ -1544,32 +1543,13 @@ dictresize(PyInterpreterState *interp, PyDictObject *mp,
 }
 }
 
-// We can not use free_keys_object here because key's reference
-// are moved already.
 if (oldkeys != Py_EMPTY_KEYS) {
 #ifdef Py_REF_DEBUG
 _Py_DecRefTotal(_PyInterpreterState_GET());
 #endif
 assert(oldkeys->dk_kind != DICT_KEYS_SPLIT);
 assert(oldkeys->dk_refcnt == 1);
-#if PyDict_MAXFREELIST > 0
-struct _Py_dict_state *state = get_dict_state(interp);
-#ifdef Py_DEBUG
-// dictresize() must not be called after _PyDict_Fini()
-assert(state->keys_numfree != -1);
-#endif
-if (DK_LOG_SIZE(oldkeys) == PyDict_LOG_MINSIZE &&
-DK_IS_UNICODE(oldkeys) &&
-state->keys_numfree < PyDict_MAXFREELIST)
-{
-state->keys_free_list[state->keys_numfree++] = oldkeys;
-OBJECT_STAT_INC(to_freelist);
-}
-else
-#endif
-{
-PyObject_Free(oldkeys);
-}
+free_keys_object(interp, oldkeys);
 }
 }
 

___
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.

[Python-checkins] gh-112075: Dictionary global version counter should use atomic increments (#114568)

2024-01-29 Thread DinoV
https://github.com/python/cpython/commit/0cd9bacb8ad41fe86f95b326e9199caa749539eb
commit: 0cd9bacb8ad41fe86f95b326e9199caa749539eb
branch: main
author: Dino Viehland 
committer: DinoV 
date: 2024-01-29T09:47:54-08:00
summary:

gh-112075: Dictionary global version counter should use atomic increments 
(#114568)

Dictionary global version counter should use atomic increments

files:
M Include/internal/pycore_dict.h

diff --git a/Include/internal/pycore_dict.h b/Include/internal/pycore_dict.h
index d96870e9197bbf..b4e1f8cf1e320b 100644
--- a/Include/internal/pycore_dict.h
+++ b/Include/internal/pycore_dict.h
@@ -209,8 +209,14 @@ static inline PyDictUnicodeEntry* 
DK_UNICODE_ENTRIES(PyDictKeysObject *dk) {
 #define DICT_VERSION_INCREMENT (1 << DICT_MAX_WATCHERS)
 #define DICT_VERSION_MASK (DICT_VERSION_INCREMENT - 1)
 
+#ifdef Py_GIL_DISABLED
+#define DICT_NEXT_VERSION(INTERP) \
+(_Py_atomic_add_uint64(&(INTERP)->dict_state.global_version, 
DICT_VERSION_INCREMENT) + DICT_VERSION_INCREMENT)
+
+#else
 #define DICT_NEXT_VERSION(INTERP) \
 ((INTERP)->dict_state.global_version += DICT_VERSION_INCREMENT)
+#endif
 
 void
 _PyDict_SendEvent(int watcher_bits,

___
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-114678: Fix incorrect deprecation warning for 'N' specifier in Decimal format (GH-114683)

2024-01-29 Thread serhiy-storchaka
https://github.com/python/cpython/commit/aa3402ad451777d8dd3ec560e14cb16dc8540c0e
commit: aa3402ad451777d8dd3ec560e14cb16dc8540c0e
branch: main
author: Serhiy Storchaka 
committer: serhiy-storchaka 
date: 2024-01-29T19:58:31+02:00
summary:

gh-114678: Fix incorrect deprecation warning for 'N' specifier in Decimal 
format (GH-114683)

Co-authored-by: Stefan Krah 

files:
A Misc/NEWS.d/next/Library/2024-01-28-19-40-40.gh-issue-114678.kYKcJw.rst
M Lib/test/test_decimal.py
M Modules/_decimal/_decimal.c

diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py
index 7a5fe62b467372..1423bc61c7f690 100644
--- a/Lib/test/test_decimal.py
+++ b/Lib/test/test_decimal.py
@@ -41,6 +41,7 @@
   darwin_malloc_err_warning, is_emscripten)
 from test.support.import_helper import import_fresh_module
 from test.support import threading_helper
+from test.support import warnings_helper
 import random
 import inspect
 import threading
@@ -1237,7 +1238,14 @@ def test_deprecated_N_format(self):
 else:
 self.assertRaises(ValueError, format, h, 'N')
 self.assertRaises(ValueError, format, h, '010.3N')
-
+with warnings_helper.check_no_warnings(self):
+self.assertEqual(format(h, 'N>10.3'), 'NN6.63E-34')
+self.assertEqual(format(h, 'N>10.3n'), 'NN6.63e-34')
+self.assertEqual(format(h, 'N>10.3e'), 'N6.626e-34')
+self.assertEqual(format(h, 'N>10.3f'), 'N0.000')
+self.assertRaises(ValueError, format, h, '>Nf')
+self.assertRaises(ValueError, format, h, '10Nf')
+self.assertRaises(ValueError, format, h, 'Nx')
 
 @run_with_locale('LC_ALL', 'ps_AF')
 def test_wide_char_separator_decimal_point(self):
diff --git 
a/Misc/NEWS.d/next/Library/2024-01-28-19-40-40.gh-issue-114678.kYKcJw.rst 
b/Misc/NEWS.d/next/Library/2024-01-28-19-40-40.gh-issue-114678.kYKcJw.rst
new file mode 100644
index 00..2306af4a39dcf6
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-01-28-19-40-40.gh-issue-114678.kYKcJw.rst
@@ -0,0 +1,3 @@
+Ensure that deprecation warning for 'N' specifier in :class:`~decimal.Decimal`
+format is not raised for cases where 'N' appears in other places
+in the format specifier. Based on patch by Stefan Krah.
diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c
index 8b93f8e2cbcf0b..127f5f2887d4cd 100644
--- a/Modules/_decimal/_decimal.c
+++ b/Modules/_decimal/_decimal.c
@@ -3446,6 +3446,14 @@ dec_format(PyObject *dec, PyObject *args)
 if (fmt == NULL) {
 return NULL;
 }
+
+if (size > 0 && fmt[size-1] == 'N') {
+if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "Format specifier 'N' is deprecated", 1) < 0) {
+return NULL;
+}
+}
+
 /* NOTE: If https://github.com/python/cpython/pull/29438 lands, the
  *   format string manipulation below can be eliminated by enhancing
  *   the forked mpd_parse_fmt_str(). */
@@ -3593,12 +3601,6 @@ dec_format(PyObject *dec, PyObject *args)
 if (replace_fillchar) {
 dec_replace_fillchar(decstring);
 }
-if (strchr(fmt, 'N') != NULL) {
-if (PyErr_WarnEx(PyExc_DeprecationWarning,
- "Format specifier 'N' is deprecated", 1) < 0) {
-goto finish;
-}
-}
 
 result = PyUnicode_DecodeUTF8(decstring, size, NULL);
 

___
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]


[Python-checkins] TaskGroup: Use explicit None check for cancellation error (#114708)

2024-01-29 Thread gvanrossum
https://github.com/python/cpython/commit/29952c86f3f8a972203a1ccd8381448efe145ada
commit: 29952c86f3f8a972203a1ccd8381448efe145ada
branch: main
author: Matan Perelman 
committer: gvanrossum 
date: 2024-01-29T11:12:33-08:00
summary:

TaskGroup: Use explicit None check for cancellation error (#114708)

files:
M Lib/asyncio/taskgroups.py

diff --git a/Lib/asyncio/taskgroups.py b/Lib/asyncio/taskgroups.py
index e1c56d140bef7d..f322b1f6653f6a 100644
--- a/Lib/asyncio/taskgroups.py
+++ b/Lib/asyncio/taskgroups.py
@@ -132,7 +132,7 @@ async def __aexit__(self, et, exc, tb):
 
 # Propagate CancelledError if there is one, except if there
 # are other errors -- those have priority.
-if propagate_cancellation_error and not self._errors:
+if propagate_cancellation_error is not None and not self._errors:
 raise propagate_cancellation_error
 
 if et is not None and not issubclass(et, exceptions.CancelledError):

___
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-114569: Use PyMem_* APIs for non-PyObjects in unicodeobject.c (#114690)

2024-01-29 Thread erlend-aasland
https://github.com/python/cpython/commit/53d921ed96e1c57b2e42f984d3a5ca8347fedb81
commit: 53d921ed96e1c57b2e42f984d3a5ca8347fedb81
branch: main
author: Erlend E. Aasland 
committer: erlend-aasland 
date: 2024-01-29T21:48:49+01:00
summary:

gh-114569: Use PyMem_* APIs for non-PyObjects in unicodeobject.c (#114690)

files:
M Objects/unicodeobject.c

diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 4b03cc3f4da5fa..b236ddba9cdc69 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -996,7 +996,7 @@ resize_compact(PyObject *unicode, Py_ssize_t length)
 new_size = (struct_size + (length + 1) * char_size);
 
 if (_PyUnicode_HAS_UTF8_MEMORY(unicode)) {
-PyObject_Free(_PyUnicode_UTF8(unicode));
+PyMem_Free(_PyUnicode_UTF8(unicode));
 _PyUnicode_UTF8(unicode) = NULL;
 _PyUnicode_UTF8_LENGTH(unicode) = 0;
 }
@@ -1049,7 +1049,7 @@ resize_inplace(PyObject *unicode, Py_ssize_t length)
 
 if (!share_utf8 && _PyUnicode_HAS_UTF8_MEMORY(unicode))
 {
-PyObject_Free(_PyUnicode_UTF8(unicode));
+PyMem_Free(_PyUnicode_UTF8(unicode));
 _PyUnicode_UTF8(unicode) = NULL;
 _PyUnicode_UTF8_LENGTH(unicode) = 0;
 }
@@ -1590,10 +1590,10 @@ unicode_dealloc(PyObject *unicode)
 return;
 }
 if (_PyUnicode_HAS_UTF8_MEMORY(unicode)) {
-PyObject_Free(_PyUnicode_UTF8(unicode));
+PyMem_Free(_PyUnicode_UTF8(unicode));
 }
 if (!PyUnicode_IS_COMPACT(unicode) && _PyUnicode_DATA_ANY(unicode)) {
-PyObject_Free(_PyUnicode_DATA_ANY(unicode));
+PyMem_Free(_PyUnicode_DATA_ANY(unicode));
 }
 
 Py_TYPE(unicode)->tp_free(unicode);
@@ -5203,7 +5203,7 @@ unicode_fill_utf8(PyObject *unicode)
 PyBytes_AS_STRING(writer.buffer);
 Py_ssize_t len = end - start;
 
-char *cache = PyObject_Malloc(len + 1);
+char *cache = PyMem_Malloc(len + 1);
 if (cache == NULL) {
 _PyBytesWriter_Dealloc(&writer);
 PyErr_NoMemory();
@@ -14674,7 +14674,7 @@ unicode_subtype_new(PyTypeObject *type, PyObject 
*unicode)
 PyErr_NoMemory();
 goto onError;
 }
-data = PyObject_Malloc((length + 1) * char_size);
+data = PyMem_Malloc((length + 1) * char_size);
 if (data == NULL) {
 PyErr_NoMemory();
 goto onError;

___
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] Set `hosted_on` for Read the Docs builds (#114697)

2024-01-29 Thread hugovk
https://github.com/python/cpython/commit/3996cbdd33a479b7e59757b81489cbb3370f85e5
commit: 3996cbdd33a479b7e59757b81489cbb3370f85e5
branch: main
author: Hugo van Kemenade <[email protected]>
committer: hugovk <[email protected]>
date: 2024-01-29T14:24:21-07:00
summary:

Set `hosted_on` for Read the Docs builds (#114697)

files:
M Doc/conf.py

diff --git a/Doc/conf.py b/Doc/conf.py
index e12128ad356e1b..c2d57696aeeaa3 100644
--- a/Doc/conf.py
+++ b/Doc/conf.py
@@ -6,7 +6,9 @@
 # The contents of this file are pickled, so don't put values in the namespace
 # that aren't pickleable (module imports are okay, they're removed 
automatically).
 
-import sys, os, time
+import os
+import sys
+import time
 sys.path.append(os.path.abspath('tools/extensions'))
 sys.path.append(os.path.abspath('includes'))
 
@@ -55,7 +57,7 @@
 
 # General substitutions.
 project = 'Python'
-copyright = '2001-%s, Python Software Foundation' % time.strftime('%Y')
+copyright = f"2001-{time.strftime('%Y')}, Python Software Foundation"
 
 # We look for the Include/patchlevel.h file in the current Python source tree
 # and replace the values accordingly.
@@ -302,6 +304,9 @@
 'root_include_title': False   # We use the version switcher instead.
 }
 
+if os.getenv("READTHEDOCS"):
+html_theme_options["hosted_on"] = 'https://about.readthedocs.com/";>Read the Docs'
+
 # Override stylesheet fingerprinting for Windows CHM htmlhelp to fix GH-91207
 # https://github.com/python/cpython/issues/91207
 if any('htmlhelp' in arg for arg in sys.argv):
@@ -310,7 +315,7 @@
 print("It may be removed in the future\n")
 
 # Short title used e.g. for  HTML tags.
-html_short_title = '%s Documentation' % release
+html_short_title = f'{release} Documentation'
 
 # Deployment preview information
 # (See .readthedocs.yml and 
https://docs.readthedocs.io/en/stable/reference/environment-variables.html)
@@ -359,12 +364,9 @@
 
 latex_engine = 'xelatex'
 
-# Get LaTeX to handle Unicode correctly
 latex_elements = {
-}
-
-# Additional stuff for the LaTeX preamble.
-latex_elements['preamble'] = r'''
+# For the LaTeX preamble.
+'preamble': r'''
 \authoraddress{
   \sphinxstrong{Python Software Foundation}\\
   Email: \sphinxemail{[email protected]}
@@ -372,13 +374,12 @@
 \let\Verbatim=\OriginalVerbatim
 \let\endVerbatim=\endOriginalVerbatim
 \setcounter{tocdepth}{2}
-'''
-
-# The paper size ('letter' or 'a4').
-latex_elements['papersize'] = 'a4'
-
-# The font size ('10pt', '11pt' or '12pt').
-latex_elements['pointsize'] = '10pt'
+''',
+# The paper size ('letter' or 'a4').
+'papersize': 'a4',
+# The font size ('10pt', '11pt' or '12pt').
+'pointsize': '10pt',
+}
 
 # Grouping the document tree into LaTeX files. List of tuples
 # (source start file, target name, title, author, document class 
[howto/manual]).
@@ -441,9 +442,9 @@
 
 # Regexes to find C items in the source files.
 coverage_c_regexes = {
-'cfunction': (r'^PyAPI_FUNC\(.*\)\s+([^_][\w_]+)'),
-'data': (r'^PyAPI_DATA\(.*\)\s+([^_][\w_]+)'),
-'macro': (r'^#define ([^_][\w_]+)\(.*\)[\s|\\]'),
+'cfunction': r'^PyAPI_FUNC\(.*\)\s+([^_][\w_]+)',
+'data': r'^PyAPI_DATA\(.*\)\s+([^_][\w_]+)',
+'macro': r'^#define ([^_][\w_]+)\(.*\)[\s|\\]',
 }
 
 # The coverage checker will ignore all C items whose names match these regexes

___
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] Set `hosted_on` for Read the Docs builds (GH-114697) (#114734)

2024-01-29 Thread hugovk
https://github.com/python/cpython/commit/424df31f00e2106eab6b8e747fc4695b00787fe5
commit: 424df31f00e2106eab6b8e747fc4695b00787fe5
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: hugovk <[email protected]>
date: 2024-01-29T21:30:22Z
summary:

[3.12] Set `hosted_on` for Read the Docs builds (GH-114697) (#114734)

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

files:
M Doc/conf.py

diff --git a/Doc/conf.py b/Doc/conf.py
index e05741479dbf34..5cc8f7e599af71 100644
--- a/Doc/conf.py
+++ b/Doc/conf.py
@@ -6,7 +6,9 @@
 # The contents of this file are pickled, so don't put values in the namespace
 # that aren't pickleable (module imports are okay, they're removed 
automatically).
 
-import sys, os, time
+import os
+import sys
+import time
 sys.path.append(os.path.abspath('tools/extensions'))
 sys.path.append(os.path.abspath('includes'))
 
@@ -49,7 +51,7 @@
 
 # General substitutions.
 project = 'Python'
-copyright = '2001-%s, Python Software Foundation' % time.strftime('%Y')
+copyright = f"2001-{time.strftime('%Y')}, Python Software Foundation"
 
 # We look for the Include/patchlevel.h file in the current Python source tree
 # and replace the values accordingly.
@@ -291,6 +293,9 @@
 'root_include_title': False   # We use the version switcher instead.
 }
 
+if os.getenv("READTHEDOCS"):
+html_theme_options["hosted_on"] = 'https://about.readthedocs.com/";>Read the Docs'
+
 # Override stylesheet fingerprinting for Windows CHM htmlhelp to fix GH-91207
 # https://github.com/python/cpython/issues/91207
 if any('htmlhelp' in arg for arg in sys.argv):
@@ -299,7 +304,7 @@
 print("It may be removed in the future\n")
 
 # Short title used e.g. for  HTML tags.
-html_short_title = '%s Documentation' % release
+html_short_title = f'{release} Documentation'
 
 # Deployment preview information
 # (See .readthedocs.yml and 
https://docs.readthedocs.io/en/stable/reference/environment-variables.html)
@@ -348,12 +353,9 @@
 
 latex_engine = 'xelatex'
 
-# Get LaTeX to handle Unicode correctly
 latex_elements = {
-}
-
-# Additional stuff for the LaTeX preamble.
-latex_elements['preamble'] = r'''
+# For the LaTeX preamble.
+'preamble': r'''
 \authoraddress{
   \sphinxstrong{Python Software Foundation}\\
   Email: \sphinxemail{[email protected]}
@@ -361,13 +363,12 @@
 \let\Verbatim=\OriginalVerbatim
 \let\endVerbatim=\endOriginalVerbatim
 \setcounter{tocdepth}{2}
-'''
-
-# The paper size ('letter' or 'a4').
-latex_elements['papersize'] = 'a4'
-
-# The font size ('10pt', '11pt' or '12pt').
-latex_elements['pointsize'] = '10pt'
+''',
+# The paper size ('letter' or 'a4').
+'papersize': 'a4',
+# The font size ('10pt', '11pt' or '12pt').
+'pointsize': '10pt',
+}
 
 # Grouping the document tree into LaTeX files. List of tuples
 # (source start file, target name, title, author, document class 
[howto/manual]).
@@ -431,9 +432,9 @@
 
 # Regexes to find C items in the source files.
 coverage_c_regexes = {
-'cfunction': (r'^PyAPI_FUNC\(.*\)\s+([^_][\w_]+)'),
-'data': (r'^PyAPI_DATA\(.*\)\s+([^_][\w_]+)'),
-'macro': (r'^#define ([^_][\w_]+)\(.*\)[\s|\\]'),
+'cfunction': r'^PyAPI_FUNC\(.*\)\s+([^_][\w_]+)',
+'data': r'^PyAPI_DATA\(.*\)\s+([^_][\w_]+)',
+'macro': r'^#define ([^_][\w_]+)\(.*\)[\s|\\]',
 }
 
 # The coverage checker will ignore all C items whose names match these regexes

___
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] Set `hosted_on` for Read the Docs builds (GH-114697) (#114735)

2024-01-29 Thread hugovk
https://github.com/python/cpython/commit/679fe04dc3a11148c32383eed60954e35699ad62
commit: 679fe04dc3a11148c32383eed60954e35699ad62
branch: 3.11
author: Miss Islington (bot) <[email protected]>
committer: hugovk <[email protected]>
date: 2024-01-29T21:30:27Z
summary:

[3.11] Set `hosted_on` for Read the Docs builds (GH-114697) (#114735)

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

files:
M Doc/conf.py

diff --git a/Doc/conf.py b/Doc/conf.py
index c7f745b9db1d82..1af8b94918f78b 100644
--- a/Doc/conf.py
+++ b/Doc/conf.py
@@ -6,7 +6,9 @@
 # The contents of this file are pickled, so don't put values in the namespace
 # that aren't pickleable (module imports are okay, they're removed 
automatically).
 
-import sys, os, time
+import os
+import sys
+import time
 sys.path.append(os.path.abspath('tools/extensions'))
 sys.path.append(os.path.abspath('includes'))
 
@@ -44,7 +46,7 @@
 
 # General substitutions.
 project = 'Python'
-copyright = '2001-%s, Python Software Foundation' % time.strftime('%Y')
+copyright = f"2001-{time.strftime('%Y')}, Python Software Foundation"
 
 # We look for the Include/patchlevel.h file in the current Python source tree
 # and replace the values accordingly.
@@ -283,6 +285,9 @@
 'root_include_title': False   # We use the version switcher instead.
 }
 
+if os.getenv("READTHEDOCS"):
+html_theme_options["hosted_on"] = 'https://about.readthedocs.com/";>Read the Docs'
+
 # Override stylesheet fingerprinting for Windows CHM htmlhelp to fix GH-91207
 # https://github.com/python/cpython/issues/91207
 if any('htmlhelp' in arg for arg in sys.argv):
@@ -291,7 +296,7 @@
 print("It may be removed in the future\n")
 
 # Short title used e.g. for  HTML tags.
-html_short_title = '%s Documentation' % release
+html_short_title = f'{release} Documentation'
 
 # Deployment preview information
 # (See .readthedocs.yml and 
https://docs.readthedocs.io/en/stable/reference/environment-variables.html)
@@ -340,12 +345,9 @@
 
 latex_engine = 'xelatex'
 
-# Get LaTeX to handle Unicode correctly
 latex_elements = {
-}
-
-# Additional stuff for the LaTeX preamble.
-latex_elements['preamble'] = r'''
+# For the LaTeX preamble.
+'preamble': r'''
 \authoraddress{
   \sphinxstrong{Python Software Foundation}\\
   Email: \sphinxemail{[email protected]}
@@ -353,13 +355,12 @@
 \let\Verbatim=\OriginalVerbatim
 \let\endVerbatim=\endOriginalVerbatim
 \setcounter{tocdepth}{2}
-'''
-
-# The paper size ('letter' or 'a4').
-latex_elements['papersize'] = 'a4'
-
-# The font size ('10pt', '11pt' or '12pt').
-latex_elements['pointsize'] = '10pt'
+''',
+# The paper size ('letter' or 'a4').
+'papersize': 'a4',
+# The font size ('10pt', '11pt' or '12pt').
+'pointsize': '10pt',
+}
 
 # Grouping the document tree into LaTeX files. List of tuples
 # (source start file, target name, title, author, document class 
[howto/manual]).
@@ -424,9 +425,9 @@
 
 # Regexes to find C items in the source files.
 coverage_c_regexes = {
-'cfunction': (r'^PyAPI_FUNC\(.*\)\s+([^_][\w_]+)'),
-'data': (r'^PyAPI_DATA\(.*\)\s+([^_][\w_]+)'),
-'macro': (r'^#define ([^_][\w_]+)\(.*\)[\s|\\]'),
+'cfunction': r'^PyAPI_FUNC\(.*\)\s+([^_][\w_]+)',
+'data': r'^PyAPI_DATA\(.*\)\s+([^_][\w_]+)',
+'macro': r'^#define ([^_][\w_]+)\(.*\)[\s|\\]',
 }
 
 # The coverage checker will ignore all C items whose names match these regexes

___
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-114569: Use PyMem_* APIs for non-PyObjects in compiler (#114587)

2024-01-29 Thread erlend-aasland
https://github.com/python/cpython/commit/8612230c1cacab6d48bfbeb9e17d04ef5a9acf21
commit: 8612230c1cacab6d48bfbeb9e17d04ef5a9acf21
branch: main
author: Erlend E. Aasland 
committer: erlend-aasland 
date: 2024-01-30T00:04:34+01:00
summary:

gh-114569: Use PyMem_* APIs for non-PyObjects in compiler (#114587)

files:
M Python/compile.c
M Python/flowgraph.c

diff --git a/Python/compile.c b/Python/compile.c
index 7cf05dd0683119..4c1d3bb2d2b475 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -160,7 +160,7 @@ _PyCompile_EnsureArrayLargeEnough(int idx, void **array, 
int *alloc,
 if (idx >= new_alloc) {
 new_alloc = idx + default_alloc;
 }
-arr = PyObject_Calloc(new_alloc, item_size);
+arr = PyMem_Calloc(new_alloc, item_size);
 if (arr == NULL) {
 PyErr_NoMemory();
 return ERROR;
@@ -181,7 +181,7 @@ _PyCompile_EnsureArrayLargeEnough(int idx, void **array, 
int *alloc,
 }
 
 assert(newsize > 0);
-void *tmp = PyObject_Realloc(arr, newsize);
+void *tmp = PyMem_Realloc(arr, newsize);
 if (tmp == NULL) {
 PyErr_NoMemory();
 return ERROR;
@@ -282,10 +282,10 @@ instr_sequence_insert_instruction(instr_sequence *seq, 
int pos,
 
 static void
 instr_sequence_fini(instr_sequence *seq) {
-PyObject_Free(seq->s_labelmap);
+PyMem_Free(seq->s_labelmap);
 seq->s_labelmap = NULL;
 
-PyObject_Free(seq->s_instrs);
+PyMem_Free(seq->s_instrs);
 seq->s_instrs = NULL;
 }
 
@@ -690,7 +690,7 @@ compiler_unit_free(struct compiler_unit *u)
 Py_CLEAR(u->u_metadata.u_cellvars);
 Py_CLEAR(u->u_metadata.u_fasthidden);
 Py_CLEAR(u->u_private);
-PyObject_Free(u);
+PyMem_Free(u);
 }
 
 static int
@@ -1262,8 +1262,7 @@ compiler_enter_scope(struct compiler *c, identifier name,
 
 struct compiler_unit *u;
 
-u = (struct compiler_unit *)PyObject_Calloc(1, sizeof(
-struct compiler_unit));
+u = (struct compiler_unit *)PyMem_Calloc(1, sizeof(struct compiler_unit));
 if (!u) {
 PyErr_NoMemory();
 return ERROR;
@@ -6657,7 +6656,7 @@ ensure_fail_pop(struct compiler *c, pattern_context *pc, 
Py_ssize_t n)
 return SUCCESS;
 }
 Py_ssize_t needed = sizeof(jump_target_label) * size;
-jump_target_label *resized = PyObject_Realloc(pc->fail_pop, needed);
+jump_target_label *resized = PyMem_Realloc(pc->fail_pop, needed);
 if (resized == NULL) {
 PyErr_NoMemory();
 return ERROR;
@@ -6696,13 +6695,13 @@ emit_and_reset_fail_pop(struct compiler *c, location 
loc,
 USE_LABEL(c, pc->fail_pop[pc->fail_pop_size]);
 if (codegen_addop_noarg(INSTR_SEQUENCE(c), POP_TOP, loc) < 0) {
 pc->fail_pop_size = 0;
-PyObject_Free(pc->fail_pop);
+PyMem_Free(pc->fail_pop);
 pc->fail_pop = NULL;
 return ERROR;
 }
 }
 USE_LABEL(c, pc->fail_pop[0]);
-PyObject_Free(pc->fail_pop);
+PyMem_Free(pc->fail_pop);
 pc->fail_pop = NULL;
 return SUCCESS;
 }
@@ -7206,7 +7205,7 @@ compiler_pattern_or(struct compiler *c, pattern_ty p, 
pattern_context *pc)
 Py_DECREF(pc->stores);
 *pc = old_pc;
 Py_INCREF(pc->stores);
-// Need to NULL this for the PyObject_Free call in the error block.
+// Need to NULL this for the PyMem_Free call in the error block.
 old_pc.fail_pop = NULL;
 // No match. Pop the remaining copy of the subject and fail:
 if (codegen_addop_noarg(INSTR_SEQUENCE(c), POP_TOP, LOC(p)) < 0 ||
@@ -7252,7 +7251,7 @@ compiler_pattern_or(struct compiler *c, pattern_ty p, 
pattern_context *pc)
 diff:
 compiler_error(c, LOC(p), "alternative patterns bind different names");
 error:
-PyObject_Free(old_pc.fail_pop);
+PyMem_Free(old_pc.fail_pop);
 Py_DECREF(old_pc.stores);
 Py_XDECREF(control);
 return ERROR;
@@ -7453,7 +7452,7 @@ compiler_match(struct compiler *c, stmt_ty s)
 pattern_context pc;
 pc.fail_pop = NULL;
 int result = compiler_match_inner(c, s, &pc);
-PyObject_Free(pc.fail_pop);
+PyMem_Free(pc.fail_pop);
 return result;
 }
 
diff --git a/Python/flowgraph.c b/Python/flowgraph.c
index 96610b3cb11a43..bfc23a298ff492 100644
--- a/Python/flowgraph.c
+++ b/Python/flowgraph.c
@@ -162,7 +162,7 @@ basicblock_last_instr(const basicblock *b) {
 static basicblock *
 cfg_builder_new_block(cfg_builder *g)
 {
-basicblock *b = (basicblock *)PyObject_Calloc(1, sizeof(basicblock));
+basicblock *b = (basicblock *)PyMem_Calloc(1, sizeof(basicblock));
 if (b == NULL) {
 PyErr_NoMemory();
 return NULL;
@@ -437,10 +437,10 @@ _PyCfgBuilder_Free(cfg_builder *g)
 basicblock *b = g->g_block_list;
 while (b != NULL) {
 if (b->b_instr) {
-PyObject_Free((void *)b->b_instr);
+PyMem_Free((void *)b->b_instr);
 }
 basicblock *next = b->b_list;
-Py

[Python-checkins] GH-113464: Make Brandt a codeowner for JIT stuff (GH-114739)

2024-01-29 Thread brandtbucher
https://github.com/python/cpython/commit/742ba6081c92744ba30f16a0bb17ef9d9e809611
commit: 742ba6081c92744ba30f16a0bb17ef9d9e809611
branch: main
author: Brandt Bucher 
committer: brandtbucher 
date: 2024-01-29T16:29:54-08:00
summary:

GH-113464: Make Brandt a codeowner for JIT stuff (GH-114739)

files:
M .github/CODEOWNERS

diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index ae915423ece955..f4d0411504a832 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -21,6 +21,7 @@ configure*@erlend-aasland @corona10
 **/*context*  @1st1
 **/*genobject*@markshannon
 **/*hamt* @1st1
+**/*jit*  @brandtbucher
 Objects/set*  @rhettinger
 Objects/dict* @methane @markshannon
 Objects/typevarobject.c   @JelleZijlstra
@@ -37,7 +38,6 @@ Python/ast_opt.c  @isidentical
 Python/bytecodes.c@markshannon @gvanrossum
 Python/optimizer*.c   @markshannon @gvanrossum
 Lib/test/test_patma.py@brandtbucher
-Lib/test/test_peepholer.py@brandtbucher
 Lib/test/test_type_*.py   @JelleZijlstra
 Lib/test/test_capi/test_misc.py  @markshannon @gvanrossum
 Tools/c-analyzer/ @ericsnowcurrently

___
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-80789: Get rid of the ``ensurepip`` infra for many wheels (#109245)

2024-01-29 Thread pradyunsg
https://github.com/python/cpython/commit/963904335e579bfe39101adf3fd6a0cf705975ff
commit: 963904335e579bfe39101adf3fd6a0cf705975ff
branch: main
author: Sviatoslav Sydorenko (Святослав Сидоренко) 
committer: pradyunsg 
date: 2024-01-30T01:25:31Z
summary:

GH-80789: Get rid of the ``ensurepip`` infra for many wheels (#109245)

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

files:
M Lib/ensurepip/__init__.py
M Lib/test/test_ensurepip.py
M Tools/build/verify_ensurepip_wheels.py

diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py
index a09bf3201e1fb7..80ee125cfd4ed3 100644
--- a/Lib/ensurepip/__init__.py
+++ b/Lib/ensurepip/__init__.py
@@ -1,78 +1,64 @@
-import collections
 import os
-import os.path
 import subprocess
 import sys
 import sysconfig
 import tempfile
+from contextlib import nullcontext
 from importlib import resources
+from pathlib import Path
+from shutil import copy2
 
 
 __all__ = ["version", "bootstrap"]
-_PACKAGE_NAMES = ('pip',)
 _PIP_VERSION = "23.3.2"
-_PROJECTS = [
-("pip", _PIP_VERSION, "py3"),
-]
-
-# Packages bundled in ensurepip._bundled have wheel_name set.
-# Packages from WHEEL_PKG_DIR have wheel_path set.
-_Package = collections.namedtuple('Package',
-  ('version', 'wheel_name', 'wheel_path'))
 
 # Directory of system wheel packages. Some Linux distribution packaging
 # policies recommend against bundling dependencies. For example, Fedora
 # installs wheel packages in the /usr/share/python-wheels/ directory and don't
 # install the ensurepip._bundled package.
-_WHEEL_PKG_DIR = sysconfig.get_config_var('WHEEL_PKG_DIR')
+if (_pkg_dir := sysconfig.get_config_var('WHEEL_PKG_DIR')) is not None:
+_WHEEL_PKG_DIR = Path(_pkg_dir).resolve()
+else:
+_WHEEL_PKG_DIR = None
+
 
+def _find_wheel_pkg_dir_pip():
+if _WHEEL_PKG_DIR is None:
+# NOTE: The compile-time `WHEEL_PKG_DIR` is unset so there is no place
+# NOTE: for looking up the wheels.
+return None
 
-def _find_packages(path):
-packages = {}
+dist_matching_wheels = _WHEEL_PKG_DIR.glob('pip-*.whl')
 try:
-filenames = os.listdir(path)
-except OSError:
-# Ignore: path doesn't exist or permission error
-filenames = ()
-# Make the code deterministic if a directory contains multiple wheel files
-# of the same package, but don't attempt to implement correct version
-# comparison since this case should not happen.
-filenames = sorted(filenames)
-for filename in filenames:
-# filename is like 'pip-21.2.4-py3-none-any.whl'
-if not filename.endswith(".whl"):
-continue
-for name in _PACKAGE_NAMES:
-prefix = name + '-'
-if filename.startswith(prefix):
-break
-else:
-continue
-
-# Extract '21.2.4' from 'pip-21.2.4-py3-none-any.whl'
-version = filename.removeprefix(prefix).partition('-')[0]
-wheel_path = os.path.join(path, filename)
-packages[name] = _Package(version, None, wheel_path)
-return packages
-
-
-def _get_packages():
-global _PACKAGES, _WHEEL_PKG_DIR
-if _PACKAGES is not None:
-return _PACKAGES
-
-packages = {}
-for name, version, py_tag in _PROJECTS:
-wheel_name = f"{name}-{version}-{py_tag}-none-any.whl"
-packages[name] = _Package(version, wheel_name, None)
-if _WHEEL_PKG_DIR:
-dir_packages = _find_packages(_WHEEL_PKG_DIR)
-# only used the wheel package directory if all packages are found there
-if all(name in dir_packages for name in _PACKAGE_NAMES):
-packages = dir_packages
-_PACKAGES = packages
-return packages
-_PACKAGES = None
+last_matching_dist_wheel = sorted(dist_matching_wheels)[-1]
+except IndexError:
+# NOTE: `WHEEL_PKG_DIR` does not contain any wheel files for `pip`.
+return None
+
+return nullcontext(last_matching_dist_wheel)
+
+
+def _get_pip_whl_path_ctx():
+# Prefer pip from the wheel package directory, if present.
+if (alternative_pip_wheel_path := _find_wheel_pkg_dir_pip()) is not None:
+return alternative_pip_wheel_path
+
+return resources.as_file(
+resources.files('ensurepip')
+/ '_bundled'
+/ f'pip-{_PIP_VERSION}-py3-none-any.whl'
+)
+
+
+def _get_pip_version():
+with _get_pip_whl_path_ctx() as bundled_wheel_path:
+wheel_name = bundled_wheel_path.name
+return (
+# Extract '21.2.4' from 'pip-21.2.4-py3-none-any.whl'
+wheel_name.
+removeprefix('pip-').
+partition('-')[0]
+)
 
 
 def _run_pip(args, additional_paths=None):
@@ -105,7 +91,7 @@ def version():
 """
 Returns a string specifying the bundled version of pip.
 """
-return _get_packages()['pip'].version
+return _get_pip_version()
 
 
 def