Skip to content

Commit 4afca4f

Browse files
authored
Merge branch 'python:main' into configparser_perf
2 parents cff9f44 + a29a9c0 commit 4afca4f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2303
-1683
lines changed

Doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
'changes',
2929
'glossary_search',
3030
'lexers',
31+
'misc_news',
3132
'pydoc_topics',
3233
'pyspecific',
3334
'sphinx.ext.coverage',

Doc/data/stable_abi.dat

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Doc/glossary.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,9 @@ Glossary
658658
and therefore it is never deallocated while the interpreter is running.
659659
For example, :const:`True` and :const:`None` are immortal in CPython.
660660

661+
Immortal objects can be identified via :func:`sys._is_immortal`, or
662+
via :c:func:`PyUnstable_IsImmortal` in the C API.
663+
661664
immutable
662665
An object with a fixed value. Immutable objects include numbers, strings and
663666
tuples. Such an object cannot be altered. A new object has to

Doc/library/sys.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,11 @@ always available. Unless explicitly noted otherwise, all variables are read-only
855855
reflect the actual number of references. Consequently, do not rely
856856
on the returned value to be accurate, other than a value of 0 or 1.
857857

858+
.. impl-detail::
859+
860+
:term:`Immortal <immortal>` objects with a large reference count can be
861+
identified via :func:`_is_immortal`.
862+
858863
.. versionchanged:: 3.12
859864
Immortal objects have very large refcounts that do not match
860865
the actual number of references to the object.
@@ -1264,6 +1269,24 @@ always available. Unless explicitly noted otherwise, all variables are read-only
12641269

12651270
.. versionadded:: 3.12
12661271

1272+
.. function:: _is_immortal(op)
1273+
1274+
Return :const:`True` if the given object is :term:`immortal`, :const:`False`
1275+
otherwise.
1276+
1277+
.. note::
1278+
1279+
Objects that are immortal (and thus return ``True`` upon being passed
1280+
to this function) are not guaranteed to be immortal in future versions,
1281+
and vice versa for mortal objects.
1282+
1283+
.. versionadded:: next
1284+
1285+
.. impl-detail::
1286+
1287+
This function should be used for specialized purposes only.
1288+
It is not guaranteed to exist in all implementations of Python.
1289+
12671290
.. function:: _is_interned(string)
12681291

12691292
Return :const:`True` if the given string is "interned", :const:`False`

Doc/license.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ Project, https://www.wide.ad.jp/. ::
374374
may be used to endorse or promote products derived from this software
375375
without specific prior written permission.
376376

377-
THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
377+
THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS "AS IS" AND
378378
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
379379
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
380380
ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
@@ -583,7 +583,7 @@ interface::
583583
notice, this list of conditions and the following disclaimer in the
584584
documentation and/or other materials provided with the distribution.
585585

586-
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
586+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
587587
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
588588
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
589589
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
@@ -884,7 +884,7 @@ sources unless the build is configured ``--with-system-libffi``::
884884

885885
Permission is hereby granted, free of charge, to any person obtaining
886886
a copy of this software and associated documentation files (the
887-
``Software''), to deal in the Software without restriction, including
887+
"Software"), to deal in the Software without restriction, including
888888
without limitation the rights to use, copy, modify, merge, publish,
889889
distribute, sublicense, and/or sell copies of the Software, and to
890890
permit persons to whom the Software is furnished to do so, subject to
@@ -893,7 +893,7 @@ sources unless the build is configured ``--with-system-libffi``::
893893
The above copyright notice and this permission notice shall be included
894894
in all copies or substantial portions of the Software.
895895

896-
THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
896+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
897897
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
898898
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
899899
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
@@ -1122,7 +1122,7 @@ The file is distributed under the 2-Clause BSD License::
11221122
notice, this list of conditions and the following disclaimer in the
11231123
documentation and/or other materials provided with the distribution.
11241124

1125-
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1125+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
11261126
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
11271127
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11281128
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,

Doc/make.bat

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,14 @@ goto end
127127
:build
128128
if not exist "%BUILDDIR%" mkdir "%BUILDDIR%"
129129

130-
rem PY_MISC_NEWS_DIR is also used by our Sphinx extension in tools/extensions/pyspecific.py
131-
if not defined PY_MISC_NEWS_DIR set PY_MISC_NEWS_DIR=%BUILDDIR%\%1
132-
if not exist "%PY_MISC_NEWS_DIR%" mkdir "%PY_MISC_NEWS_DIR%"
130+
if not exist build mkdir build
133131
if exist ..\Misc\NEWS (
134-
echo.Copying Misc\NEWS to %PY_MISC_NEWS_DIR%\NEWS
135-
copy ..\Misc\NEWS "%PY_MISC_NEWS_DIR%\NEWS" > nul
132+
echo.Copying existing Misc\NEWS file to Doc\build\NEWS
133+
copy ..\Misc\NEWS build\NEWS > nul
136134
) else if exist ..\Misc\NEWS.D (
137135
if defined BLURB (
138136
echo.Merging Misc/NEWS with %BLURB%
139-
%BLURB% merge -f "%PY_MISC_NEWS_DIR%\NEWS"
137+
%BLURB% merge -f build\NEWS
140138
) else (
141139
echo.No Misc/NEWS file and Blurb is not available.
142140
exit /B 1

Doc/tools/extensions/availability.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from docutils import nodes
88
from sphinx import addnodes
9+
from sphinx.locale import _ as sphinx_gettext
910
from sphinx.util import logging
1011
from sphinx.util.docutils import SphinxDirective
1112

@@ -55,7 +56,7 @@ class Availability(SphinxDirective):
5556
final_argument_whitespace = True
5657

5758
def run(self) -> list[nodes.container]:
58-
title = "Availability"
59+
title = sphinx_gettext("Availability")
5960
refnode = addnodes.pending_xref(
6061
title,
6162
nodes.inline(title, title, classes=["xref", "std", "std-ref"]),

Doc/tools/extensions/misc_news.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
"""Support for including Misc/NEWS."""
2+
3+
from __future__ import annotations
4+
5+
import re
6+
from pathlib import Path
7+
from typing import TYPE_CHECKING
8+
9+
from docutils import nodes
10+
from sphinx.locale import _ as sphinx_gettext
11+
from sphinx.util.docutils import SphinxDirective
12+
13+
if TYPE_CHECKING:
14+
from typing import Final
15+
16+
from docutils.nodes import Node
17+
from sphinx.application import Sphinx
18+
from sphinx.util.typing import ExtensionMetadata
19+
20+
21+
BLURB_HEADER = """\
22+
+++++++++++
23+
Python News
24+
+++++++++++
25+
"""
26+
27+
bpo_issue_re: Final[re.Pattern[str]] = re.compile(
28+
"(?:issue #|bpo-)([0-9]+)", re.ASCII
29+
)
30+
gh_issue_re: Final[re.Pattern[str]] = re.compile(
31+
"gh-(?:issue-)?([0-9]+)", re.ASCII | re.IGNORECASE
32+
)
33+
whatsnew_re: Final[re.Pattern[str]] = re.compile(
34+
r"^what's new in (.*?)\??$", re.ASCII | re.IGNORECASE | re.MULTILINE
35+
)
36+
37+
38+
class MiscNews(SphinxDirective):
39+
has_content = False
40+
required_arguments = 1
41+
optional_arguments = 0
42+
final_argument_whitespace = False
43+
option_spec = {}
44+
45+
def run(self) -> list[Node]:
46+
# Get content of NEWS file
47+
source, _ = self.get_source_info()
48+
news_file = Path(source).resolve().parent / self.arguments[0]
49+
self.env.note_dependency(news_file)
50+
try:
51+
news_text = news_file.read_text(encoding="utf-8")
52+
except (OSError, UnicodeError):
53+
text = sphinx_gettext("The NEWS file is not available.")
54+
return [nodes.strong(text, text)]
55+
56+
# remove first 3 lines as they are the main heading
57+
news_text = news_text.removeprefix(BLURB_HEADER)
58+
59+
news_text = bpo_issue_re.sub(r":issue:`\1`", news_text)
60+
# Fallback handling for GitHub issues
61+
news_text = gh_issue_re.sub(r":gh:`\1`", news_text)
62+
news_text = whatsnew_re.sub(r"\1", news_text)
63+
64+
self.state_machine.insert_input(news_text.splitlines(), str(news_file))
65+
return []
66+
67+
68+
def setup(app: Sphinx) -> ExtensionMetadata:
69+
app.add_directive("miscnews", MiscNews)
70+
71+
return {
72+
"version": "1.0",
73+
"parallel_read_safe": True,
74+
"parallel_write_safe": True,
75+
}

Doc/tools/extensions/pyspecific.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -141,46 +141,6 @@ def run(self):
141141
return PyMethod.run(self)
142142

143143

144-
# Support for including Misc/NEWS
145-
146-
issue_re = re.compile('(?:[Ii]ssue #|bpo-)([0-9]+)', re.I)
147-
gh_issue_re = re.compile('(?:gh-issue-|gh-)([0-9]+)', re.I)
148-
whatsnew_re = re.compile(r"(?im)^what's new in (.*?)\??$")
149-
150-
151-
class MiscNews(SphinxDirective):
152-
has_content = False
153-
required_arguments = 1
154-
optional_arguments = 0
155-
final_argument_whitespace = False
156-
option_spec = {}
157-
158-
def run(self):
159-
fname = self.arguments[0]
160-
source = self.state_machine.input_lines.source(
161-
self.lineno - self.state_machine.input_offset - 1)
162-
source_dir = getenv('PY_MISC_NEWS_DIR')
163-
if not source_dir:
164-
source_dir = path.dirname(path.abspath(source))
165-
fpath = path.join(source_dir, fname)
166-
self.env.note_dependency(path.abspath(fpath))
167-
try:
168-
with io.open(fpath, encoding='utf-8') as fp:
169-
content = fp.read()
170-
except Exception:
171-
text = 'The NEWS file is not available.'
172-
node = nodes.strong(text, text)
173-
return [node]
174-
content = issue_re.sub(r':issue:`\1`', content)
175-
# Fallback handling for the GitHub issue
176-
content = gh_issue_re.sub(r':gh:`\1`', content)
177-
content = whatsnew_re.sub(r'\1', content)
178-
# remove first 3 lines as they are the main heading
179-
lines = ['.. default-role:: obj', ''] + content.splitlines()[3:]
180-
self.state_machine.insert_input(lines, fname)
181-
return []
182-
183-
184144
# Support for documenting Opcodes
185145

186146
opcode_sig_re = re.compile(r'(\w+(?:\+\d)?)(?:\s*\((.*)\))?')
@@ -268,6 +228,5 @@ def setup(app):
268228
app.add_directive_to_domain('py', 'awaitablefunction', PyAwaitableFunction)
269229
app.add_directive_to_domain('py', 'awaitablemethod', PyAwaitableMethod)
270230
app.add_directive_to_domain('py', 'abstractmethod', PyAbstractMethod)
271-
app.add_directive('miscnews', MiscNews)
272231
app.connect('env-check-consistency', patch_pairindextypes)
273232
return {'version': '1.0', 'parallel_read_safe': True}

Doc/tools/templates/dummy.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
{% trans %}Deprecated since version {deprecated}, will be removed in version {removed}{% endtrans %}
88
{% trans %}Deprecated since version {deprecated}, removed in version {removed}{% endtrans %}
99

10+
In extensions/availability.py:
11+
12+
{% trans %}Availability{% endtrans %}
13+
1014
In extensions/c_annotations.py:
1115

1216
{% trans %}Part of the{% endtrans %}

0 commit comments

Comments
 (0)