Skip to content

Commit

Permalink
Merge branch 'main' into fix/codecs/replace-errors-126004
Browse files Browse the repository at this point in the history
  • Loading branch information
picnixz authored Jan 22, 2025
2 parents 7626ceb + 9012fa7 commit fbe1930
Show file tree
Hide file tree
Showing 93 changed files with 13,815 additions and 18,050 deletions.
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,7 @@ Lib/test/test_configparser.py @jaraco
Doc/reference/ @willingc @AA-Turner

**/*weakref* @kumaraditya303

# Colorize
Lib/_colorize.py @hugovk
Lib/test/test__colorize.py @hugovk
1 change: 1 addition & 0 deletions Doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
'changes',
'glossary_search',
'lexers',
'pydoc_topics',
'pyspecific',
'sphinx.ext.coverage',
'sphinx.ext.doctest',
Expand Down
16 changes: 16 additions & 0 deletions Doc/deprecations/c-api-pending-removal-in-3.18.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Pending removal in Python 3.18
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

* Deprecated private functions (:gh:`128863`):

* :c:func:`!_PyBytes_Join`: use :c:func:`PyBytes_Join`.
* :c:func:`!_PyDict_GetItemStringWithError`: use :c:func:`PyDict_GetItemStringRef`.
* :c:func:`!_PyDict_Pop()`: :c:func:`PyDict_Pop`.
* :c:func:`!_PyThreadState_UncheckedGet`: use :c:func:`PyThreadState_GetUnchecked`.
* :c:func:`!_PyUnicode_AsString`: use :c:func:`PyUnicode_AsUTF8`.
* :c:func:`!_Py_HashPointer`: use :c:func:`Py_HashPointer`.
* :c:func:`!_Py_fopen_obj`: use :c:func:`Py_fopen`.

The `pythoncapi-compat project
<https://github.com/python/pythoncapi-compat/>`__ can be used to get these
new public functions on Python 3.13 and older.
2 changes: 1 addition & 1 deletion Doc/deprecations/pending-removal-in-3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Pending removal in Python 3.16

* :mod:`sysconfig`:

* The ``~sysconfig.expand_makefile_vars`` function
* The :func:`!sysconfig.expand_makefile_vars` function
has been deprecated since Python 3.14.
Use the ``vars`` argument of :func:`sysconfig.get_paths` instead.

Expand Down
10 changes: 2 additions & 8 deletions Doc/library/__main__.rst
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,7 @@ Here is an example module that consumes the ``__main__`` namespace::
if not did_user_define_their_name():
raise ValueError('Define the variable `my_name`!')

if '__file__' in dir(__main__):
print(__main__.my_name, "found in file", __main__.__file__)
else:
print(__main__.my_name)
print(__main__.my_name)

Example usage of this module could be as follows::

Expand Down Expand Up @@ -330,7 +327,7 @@ status code 0, indicating success:
.. code-block:: shell-session
$ python start.py
Dinsdale found in file /path/to/start.py
Dinsdale
Note that importing ``__main__`` doesn't cause any issues with unintentionally
running top-level code meant for script use which is put in the
Expand Down Expand Up @@ -361,8 +358,5 @@ defined in the REPL becomes part of the ``__main__`` scope::
>>> namely.print_user_name()
Jabberwocky

Note that in this case the ``__main__`` scope doesn't contain a ``__file__``
attribute as it's interactive.

The ``__main__`` scope is used in the implementation of :mod:`pdb` and
:mod:`rlcompleter`.
6 changes: 4 additions & 2 deletions Doc/reference/compound_stmts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1217,8 +1217,10 @@ A function definition defines a user-defined function object (see section
: | `parameter_list_no_posonly`
parameter_list_no_posonly: `defparameter` ("," `defparameter`)* ["," [`parameter_list_starargs`]]
: | `parameter_list_starargs`
parameter_list_starargs: "*" [`star_parameter`] ("," `defparameter`)* ["," ["**" `parameter` [","]]]
: | "**" `parameter` [","]
parameter_list_starargs: "*" [`star_parameter`] ("," `defparameter`)* ["," [`parameter_star_kwargs`]]
: "*" ("," `defparameter`)+ ["," [`parameter_star_kwargs`]]
: | `parameter_star_kwargs`
parameter_star_kwargs: "**" `parameter` [","]
parameter: `identifier` [":" `expression`]
star_parameter: `identifier` [":" ["*"] `expression`]
defparameter: `parameter` ["=" `expression`]
Expand Down
187 changes: 187 additions & 0 deletions Doc/tools/extensions/pydoc_topics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
"""Support for building "topic help" for pydoc."""

from __future__ import annotations

from time import asctime
from typing import TYPE_CHECKING

from sphinx.builders.text import TextBuilder
from sphinx.util import logging
from sphinx.util.display import status_iterator
from sphinx.util.docutils import new_document
from sphinx.writers.text import TextTranslator

if TYPE_CHECKING:
from collections.abc import Sequence, Set

from sphinx.application import Sphinx
from sphinx.util.typing import ExtensionMetadata

logger = logging.getLogger(__name__)

_PYDOC_TOPIC_LABELS: Sequence[str] = sorted({
"assert",
"assignment",
"assignment-expressions",
"async",
"atom-identifiers",
"atom-literals",
"attribute-access",
"attribute-references",
"augassign",
"await",
"binary",
"bitwise",
"bltin-code-objects",
"bltin-ellipsis-object",
"bltin-null-object",
"bltin-type-objects",
"booleans",
"break",
"callable-types",
"calls",
"class",
"comparisons",
"compound",
"context-managers",
"continue",
"conversions",
"customization",
"debugger",
"del",
"dict",
"dynamic-features",
"else",
"exceptions",
"execmodel",
"exprlists",
"floating",
"for",
"formatstrings",
"function",
"global",
"id-classes",
"identifiers",
"if",
"imaginary",
"import",
"in",
"integers",
"lambda",
"lists",
"naming",
"nonlocal",
"numbers",
"numeric-types",
"objects",
"operator-summary",
"pass",
"power",
"raise",
"return",
"sequence-types",
"shifting",
"slicings",
"specialattrs",
"specialnames",
"string-methods",
"strings",
"subscriptions",
"truth",
"try",
"types",
"typesfunctions",
"typesmapping",
"typesmethods",
"typesmodules",
"typesseq",
"typesseq-mutable",
"unary",
"while",
"with",
"yield",
})


class PydocTopicsBuilder(TextBuilder):
name = "pydoc-topics"

def init(self) -> None:
super().init()
self.topics: dict[str, str] = {}

def get_outdated_docs(self) -> str:
# Return a string describing what an update build will build.
return "all pydoc topics"

def write_documents(self, _docnames: Set[str]) -> None:
env = self.env

labels: dict[str, tuple[str, str, str]]
labels = env.domains.standard_domain.labels

# docname -> list of (topic_label, label_id) pairs
doc_labels: dict[str, list[tuple[str, str]]] = {}
for topic_label in _PYDOC_TOPIC_LABELS:
try:
docname, label_id, _section_name = labels[topic_label]
except KeyError:
logger.warning("label %r not in documentation", topic_label)
continue
doc_labels.setdefault(docname, []).append((topic_label, label_id))

for docname, label_ids in status_iterator(
doc_labels.items(),
"building topics... ",
length=len(doc_labels),
stringify_func=_display_labels,
):
doctree = env.get_and_resolve_doctree(docname, builder=self)
doc_ids = doctree.ids
for topic_label, label_id in label_ids:
document = new_document("<section node>")
document.append(doc_ids[label_id])
visitor = TextTranslator(document, builder=self)
document.walkabout(visitor)
self.topics[topic_label] = visitor.body

def finish(self) -> None:
topics_repr = "\n".join(
f" '{topic}': {_repr(self.topics[topic])},"
for topic in sorted(self.topics)
)
topics = f"""\
# Autogenerated by Sphinx on {asctime()}
# as part of the release process.
topics = {{
{topics_repr}
}}
"""
self.outdir.joinpath("topics.py").write_text(topics, encoding="utf-8")


def _display_labels(item: tuple[str, Sequence[tuple[str, str]]]) -> str:
_docname, label_ids = item
labels = [name for name, _id in label_ids]
if len(labels) > 4:
return f"{labels[0]}, {labels[1]}, ..., {labels[-2]}, {labels[-1]}"
return ", ".join(labels)


def _repr(text: str, /) -> str:
"""Return a triple-single-quoted representation of text."""
if "'''" not in text:
return f"r'''{text}'''"
text = text.replace("\\", "\\\\").replace("'''", r"\'\'\'")
return f"'''{text}'''"


def setup(app: Sphinx) -> ExtensionMetadata:
app.add_builder(PydocTopicsBuilder)

return {
"version": "1.0",
"parallel_read_safe": True,
"parallel_write_safe": True,
}
72 changes: 1 addition & 71 deletions Doc/tools/extensions/pyspecific.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,14 @@
import re
import io
from os import getenv, path
from time import asctime
from pprint import pformat

from docutils import nodes
from docutils.io import StringOutput
from docutils.parsers.rst import directives
from docutils.utils import new_document, unescape
from docutils.utils import unescape
from sphinx import addnodes
from sphinx.builders import Builder
from sphinx.domains.python import PyFunction, PyMethod, PyModule
from sphinx.locale import _ as sphinx_gettext
from sphinx.util.docutils import SphinxDirective
from sphinx.writers.text import TextWriter, TextTranslator
from sphinx.util.display import status_iterator


ISSUE_URI = 'https://bugs.python.org/issue?@action=redirect&bpo=%s'
Expand Down Expand Up @@ -223,69 +217,6 @@ def run(self):
return []


# Support for building "topic help" for pydoc

pydoc_topic_labels = [
'assert', 'assignment', 'assignment-expressions', 'async', 'atom-identifiers',
'atom-literals', 'attribute-access', 'attribute-references', 'augassign', 'await',
'binary', 'bitwise', 'bltin-code-objects', 'bltin-ellipsis-object',
'bltin-null-object', 'bltin-type-objects', 'booleans',
'break', 'callable-types', 'calls', 'class', 'comparisons', 'compound',
'context-managers', 'continue', 'conversions', 'customization', 'debugger',
'del', 'dict', 'dynamic-features', 'else', 'exceptions', 'execmodel',
'exprlists', 'floating', 'for', 'formatstrings', 'function', 'global',
'id-classes', 'identifiers', 'if', 'imaginary', 'import', 'in', 'integers',
'lambda', 'lists', 'naming', 'nonlocal', 'numbers', 'numeric-types',
'objects', 'operator-summary', 'pass', 'power', 'raise', 'return',
'sequence-types', 'shifting', 'slicings', 'specialattrs', 'specialnames',
'string-methods', 'strings', 'subscriptions', 'truth', 'try', 'types',
'typesfunctions', 'typesmapping', 'typesmethods', 'typesmodules',
'typesseq', 'typesseq-mutable', 'unary', 'while', 'with', 'yield'
]


class PydocTopicsBuilder(Builder):
name = 'pydoc-topics'

default_translator_class = TextTranslator

def init(self):
self.topics = {}
self.secnumbers = {}

def get_outdated_docs(self):
return 'all pydoc topics'

def get_target_uri(self, docname, typ=None):
return '' # no URIs

def write(self, *ignored):
writer = TextWriter(self)
for label in status_iterator(pydoc_topic_labels,
'building topics... ',
length=len(pydoc_topic_labels)):
if label not in self.env.domaindata['std']['labels']:
self.env.logger.warning(f'label {label!r} not in documentation')
continue
docname, labelid, sectname = self.env.domaindata['std']['labels'][label]
doctree = self.env.get_and_resolve_doctree(docname, self)
document = new_document('<section node>')
document.append(doctree.ids[labelid])
destination = StringOutput(encoding='utf-8')
writer.write(document, destination)
self.topics[label] = writer.output

def finish(self):
f = open(path.join(self.outdir, 'topics.py'), 'wb')
try:
f.write('# -*- coding: utf-8 -*-\n'.encode('utf-8'))
f.write(('# Autogenerated by Sphinx on %s\n' % asctime()).encode('utf-8'))
f.write('# as part of the release process.\n'.encode('utf-8'))
f.write(('topics = ' + pformat(self.topics) + '\n').encode('utf-8'))
finally:
f.close()


# Support for documenting Opcodes

opcode_sig_re = re.compile(r'(\w+(?:\+\d)?)(?:\s*\((.*)\))?')
Expand Down Expand Up @@ -365,7 +296,6 @@ def setup(app):
app.add_role('issue', issue_role)
app.add_role('gh', gh_issue_role)
app.add_directive('impl-detail', ImplementationDetail)
app.add_builder(PydocTopicsBuilder)
app.add_object_type('opcode', 'opcode', '%s (opcode)', parse_opcode_signature)
app.add_object_type('pdbcommand', 'pdbcmd', '%s (pdb command)', parse_pdb_command)
app.add_object_type('monitoring-event', 'monitoring-event', '%s (monitoring event)', parse_monitoring_event)
Expand Down
2 changes: 1 addition & 1 deletion Doc/using/cmdline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ conflict.

.. envvar:: PYTHON_BASIC_REPL

If this variable is set to ``1``, the interpreter will not attempt to
If this variable is set to any value, the interpreter will not attempt to
load the Python-based :term:`REPL` that requires :mod:`curses` and
:mod:`readline`, and will instead use the traditional parser-based
:term:`REPL`.
Expand Down
Loading

0 comments on commit fbe1930

Please sign in to comment.