Skip to content

Commit 1972ca4

Browse files
committed
Merge branch 'superopt' into superopt_spec
* superopt: (82 commits) pythongh-101517: fix line number propagation in code generated for except* (python#103550) pythongh-103780: Use patch instead of mock in asyncio unix events test (python#103782) pythongh-102498 Clean up unused variables and imports in the email module (python#102482) pythongh-99184: Bypass instance attribute access in `repr` of `weakref.ref` (python#99244) pythongh-99032: datetime docs: Encoding is no longer relevant (python#93365) pythongh-94300: Update datetime.strptime documentation (python#95318) pythongh-103776: Remove explicit uses of $(SHELL) from Makefile (pythonGH-103778) pythongh-87092: fix a few cases of incorrect error handling in compiler (python#103456) pythonGH-103727: Avoid advancing tokenizer too far in f-string mode (pythonGH-103775) Revert "Add tests for empty range equality (python#103751)" (python#103770) pythongh-94518: Port 23-argument `_posixsubprocess.fork_exec` to Argument Clinic (python#94519) pythonGH-65022: Fix description of copyreg.pickle function (python#102656) pythongh-103323: Get the "Current" Thread State from a Thread-Local Variable (pythongh-103324) pythongh-91687: modernize dataclass example typing (python#103773) pythongh-103746: Test `types.UnionType` and `Literal` types together (python#103747) pythongh-103765: Fix 'Warning: py:class reference target not found: ModuleSpec' (pythonGH-103769) pythongh-87452: Improve the Popen.returncode docs Removed unnecessary escaping of asterisks (python#103714) pythonGH-102973: Slim down Fedora packages in the dev container (python#103283) pythongh-103091: Add PyUnstable_Type_AssignVersionTag (python#103095) ...
2 parents 079c65a + 0de5bc6 commit 1972ca4

File tree

238 files changed

+12273
-6299
lines changed

Some content is hidden

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

238 files changed

+12273
-6299
lines changed

.devcontainer/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ ENV WASMTIME_HOME=/opt/wasmtime
99
ENV WASMTIME_VERSION=7.0.0
1010
ENV WASMTIME_CPU_ARCH=x86_64
1111

12-
RUN dnf -y --nodocs install git clang xz python3-blurb dnf-plugins-core && \
13-
dnf -y --nodocs builddep python3 && \
12+
RUN dnf -y --nodocs --setopt=install_weak_deps=False install /usr/bin/{blurb,clang,curl,git,ln,tar,xz} 'dnf-command(builddep)' && \
13+
dnf -y --nodocs --setopt=install_weak_deps=False builddep python3 && \
1414
dnf -y clean all
1515

1616
RUN mkdir ${WASI_SDK_PATH} && \

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Lib/test/xmltestdata/* noeol
3434

3535
# Shell scripts should have LF even on Windows because of Cygwin
3636
Lib/venv/scripts/common/activate text eol=lf
37+
Lib/venv/scripts/posix/* text eol=lf
3738

3839
# CRLF files
3940
[attr]dos text eol=crlf

.github/workflows/verify-ensurepip-wheels.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Verify bundled pip and setuptools
1+
name: Verify bundled wheels
22

33
on:
44
workflow_dispatch:
@@ -29,5 +29,5 @@ jobs:
2929
- uses: actions/setup-python@v4
3030
with:
3131
python-version: '3'
32-
- name: Compare checksums of bundled pip and setuptools to ones published on PyPI
32+
- name: Compare checksum of bundled wheels to the ones published on PyPI
3333
run: ./Tools/build/verify_ensurepip_wheels.py

Doc/c-api/type.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,15 @@ Type Objects
232232
233233
.. versionadded:: 3.11
234234
235+
.. c:function:: int PyUnstable_Type_AssignVersionTag(PyTypeObject *type)
236+
237+
Attempt to assign a version tag to the given type.
238+
239+
Returns 1 if the type already had a valid version tag or a new one was
240+
assigned, or 0 if a new tag could not be assigned.
241+
242+
.. versionadded:: 3.12
243+
235244
236245
Creating Heap-Allocated Types
237246
.............................

Doc/conf.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,31 @@
254254
# Options for the link checker
255255
# ----------------------------
256256

257-
# Ignore certain URLs.
258-
linkcheck_ignore = [r'https://bugs.python.org/(issue)?\d+']
257+
linkcheck_allowed_redirects = {
258+
# bpo-NNNN -> BPO -> GH Issues
259+
r'https://bugs.python.org/issue\?@action=redirect&bpo=\d+': 'https://github.com/python/cpython/issues/\d+',
260+
# GH-NNNN used to refer to pull requests
261+
r'https://github.com/python/cpython/issues/\d+': 'https://github.com/python/cpython/pull/\d+',
262+
# :source:`something` linking files in the repository
263+
r'https://github.com/python/cpython/tree/.*': 'https://github.com/python/cpython/blob/.*'
264+
}
265+
266+
linkcheck_anchors_ignore = [
267+
# ignore anchors that start with a '/', e.g. Wikipedia media files:
268+
# https://en.wikipedia.org/wiki/Walrus#/media/File:Pacific_Walrus_-_Bull_(8247646168).jpg
269+
r'\/.*',
270+
]
271+
272+
linkcheck_ignore = [
273+
# The crawler gets "Anchor not found"
274+
r'https://developer.apple.com/documentation/.+?#.*',
275+
r'https://devguide.python.org.+?/#.*',
276+
r'https://github.com.+?#.*',
277+
# Robot crawlers not allowed: "403 Client Error: Forbidden"
278+
r'https://support.enthought.com/hc/.*',
279+
# SSLError CertificateError, even though it is valid
280+
r'https://unix.org/version2/whatsnew/lp64_wp.html',
281+
]
259282

260283

261284
# Options for extensions

Doc/distributing/index.rst

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,10 @@ involved in creating and publishing a project:
129129
* `Uploading the project to the Python Package Index`_
130130
* `The .pypirc file`_
131131

132-
.. _Project structure: \
133-
https://packaging.python.org/tutorials/packaging-projects/#packaging-python-projects
134-
.. _Building and packaging the project: \
135-
https://packaging.python.org/tutorials/packaging-projects/#creating-the-package-files
136-
.. _Uploading the project to the Python Package Index: \
137-
https://packaging.python.org/tutorials/packaging-projects/#uploading-the-distribution-archives
138-
.. _The .pypirc file: \
139-
https://packaging.python.org/specifications/pypirc/
132+
.. _Project structure: https://packaging.python.org/tutorials/packaging-projects/#packaging-python-projects
133+
.. _Building and packaging the project: https://packaging.python.org/tutorials/packaging-projects/#creating-the-package-files
134+
.. _Uploading the project to the Python Package Index: https://packaging.python.org/tutorials/packaging-projects/#uploading-the-distribution-archives
135+
.. _The .pypirc file: https://packaging.python.org/specifications/pypirc/
140136

141137

142138
How do I...?

Doc/extending/newtypes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ Here is an example::
337337
}
338338

339339
PyErr_Format(PyExc_AttributeError,
340-
"'%.50s' object has no attribute '%.400s'",
340+
"'%.100s' object has no attribute '%.400s'",
341341
tp->tp_name, name);
342342
return NULL;
343343
}

Doc/faq/library.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ socket to :meth:`select.select` to check if it's writable.
780780
The :mod:`asyncio` module provides a general purpose single-threaded and
781781
concurrent asynchronous library, which can be used for writing non-blocking
782782
network code.
783-
The third-party `Twisted <https://twistedmatrix.com/trac/>`_ library is
783+
The third-party `Twisted <https://twisted.org/>`_ library is
784784
a popular and feature-rich alternative.
785785
786786

Doc/howto/descriptor.rst

Lines changed: 90 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,37 +1273,86 @@ Using the non-data descriptor protocol, a pure Python version of
12731273

12741274
.. testcode::
12751275

1276+
import functools
1277+
12761278
class StaticMethod:
12771279
"Emulate PyStaticMethod_Type() in Objects/funcobject.c"
12781280

12791281
def __init__(self, f):
12801282
self.f = f
1283+
functools.update_wrapper(self, f)
12811284

12821285
def __get__(self, obj, objtype=None):
12831286
return self.f
12841287

12851288
def __call__(self, *args, **kwds):
12861289
return self.f(*args, **kwds)
12871290
1291+
The :func:`functools.update_wrapper` call adds a ``__wrapped__`` attribute
1292+
that refers to the underlying function. Also it carries forward
1293+
the attributes necessary to make the wrapper look like the wrapped
1294+
function: ``__name__``, ``__qualname__``, ``__doc__``, and ``__annotations__``.
1295+
12881296
.. testcode::
12891297
:hide:
12901298

12911299
class E_sim:
12921300
@StaticMethod
1293-
def f(x):
1294-
return x * 10
1301+
def f(x: int) -> str:
1302+
"Simple function example"
1303+
return "!" * x
12951304

12961305
wrapped_ord = StaticMethod(ord)
12971306

12981307
.. doctest::
12991308
:hide:
13001309

13011310
>>> E_sim.f(3)
1302-
30
1311+
'!!!'
13031312
>>> E_sim().f(3)
1304-
30
1313+
'!!!'
1314+
1315+
>>> sm = vars(E_sim)['f']
1316+
>>> type(sm).__name__
1317+
'StaticMethod'
1318+
>>> f = E_sim.f
1319+
>>> type(f).__name__
1320+
'function'
1321+
>>> sm.__name__
1322+
'f'
1323+
>>> f.__name__
1324+
'f'
1325+
>>> sm.__qualname__
1326+
'E_sim.f'
1327+
>>> f.__qualname__
1328+
'E_sim.f'
1329+
>>> sm.__doc__
1330+
'Simple function example'
1331+
>>> f.__doc__
1332+
'Simple function example'
1333+
>>> sm.__annotations__
1334+
{'x': <class 'int'>, 'return': <class 'str'>}
1335+
>>> f.__annotations__
1336+
{'x': <class 'int'>, 'return': <class 'str'>}
1337+
>>> sm.__module__ == f.__module__
1338+
True
1339+
>>> sm(3)
1340+
'!!!'
1341+
>>> f(3)
1342+
'!!!'
1343+
13051344
>>> wrapped_ord('A')
13061345
65
1346+
>>> wrapped_ord.__module__ == ord.__module__
1347+
True
1348+
>>> wrapped_ord.__wrapped__ == ord
1349+
True
1350+
>>> wrapped_ord.__name__ == ord.__name__
1351+
True
1352+
>>> wrapped_ord.__qualname__ == ord.__qualname__
1353+
True
1354+
>>> wrapped_ord.__doc__ == ord.__doc__
1355+
True
13071356

13081357

13091358
Class methods
@@ -1359,11 +1408,14 @@ Using the non-data descriptor protocol, a pure Python version of
13591408

13601409
.. testcode::
13611410

1411+
import functools
1412+
13621413
class ClassMethod:
13631414
"Emulate PyClassMethod_Type() in Objects/funcobject.c"
13641415

13651416
def __init__(self, f):
13661417
self.f = f
1418+
functools.update_wrapper(self, f)
13671419

13681420
def __get__(self, obj, cls=None):
13691421
if cls is None:
@@ -1380,8 +1432,9 @@ Using the non-data descriptor protocol, a pure Python version of
13801432
# Verify the emulation works
13811433
class T:
13821434
@ClassMethod
1383-
def cm(cls, x, y):
1384-
return (cls, x, y)
1435+
def cm(cls, x: int, y: str) -> tuple[str, int, str]:
1436+
"Class method that returns a tuple"
1437+
return (cls.__name__, x, y)
13851438

13861439
@ClassMethod
13871440
@property
@@ -1393,17 +1446,40 @@ Using the non-data descriptor protocol, a pure Python version of
13931446
:hide:
13941447

13951448
>>> T.cm(11, 22)
1396-
(<class 'T'>, 11, 22)
1449+
('T', 11, 22)
13971450

13981451
# Also call it from an instance
13991452
>>> t = T()
14001453
>>> t.cm(11, 22)
1401-
(<class 'T'>, 11, 22)
1454+
('T', 11, 22)
14021455

14031456
# Check the alternate path for chained descriptors
14041457
>>> T.__doc__
14051458
"A doc for 'T'"
14061459

1460+
# Verify that T uses our emulation
1461+
>>> type(vars(T)['cm']).__name__
1462+
'ClassMethod'
1463+
1464+
# Verify that update_wrapper() correctly copied attributes
1465+
>>> T.cm.__name__
1466+
'cm'
1467+
>>> T.cm.__qualname__
1468+
'T.cm'
1469+
>>> T.cm.__doc__
1470+
'Class method that returns a tuple'
1471+
>>> T.cm.__annotations__
1472+
{'x': <class 'int'>, 'y': <class 'str'>, 'return': tuple[str, int, str]}
1473+
1474+
# Verify that __wrapped__ was added and works correctly
1475+
>>> f = vars(T)['cm'].__wrapped__
1476+
>>> type(f).__name__
1477+
'function'
1478+
>>> f.__name__
1479+
'cm'
1480+
>>> f(T, 11, 22)
1481+
('T', 11, 22)
1482+
14071483

14081484
The code path for ``hasattr(type(self.f), '__get__')`` was added in
14091485
Python 3.9 and makes it possible for :func:`classmethod` to support
@@ -1423,6 +1499,12 @@ chained together. In Python 3.11, this functionality was deprecated.
14231499
>>> G.__doc__
14241500
"A doc for 'G'"
14251501

1502+
The :func:`functools.update_wrapper` call in ``ClassMethod`` adds a
1503+
``__wrapped__`` attribute that refers to the underlying function. Also
1504+
it carries forward the attributes necessary to make the wrapper look
1505+
like the wrapped function: ``__name__``, ``__qualname__``, ``__doc__``,
1506+
and ``__annotations__``.
1507+
14261508

14271509
Member objects and __slots__
14281510
----------------------------

Doc/howto/enum.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ inherits from :class:`Enum` itself.
3636

3737
.. note:: Case of Enum Members
3838

39-
Because Enums are used to represent constants we recommend using
40-
UPPER_CASE names for members, and will be using that style in our examples.
39+
Because Enums are used to represent constants, and to help avoid issues
40+
with name clashes between mixin-class methods/attributes and enum names,
41+
we strongly recommend using UPPER_CASE names for members, and will be using
42+
that style in our examples.
4143

4244
Depending on the nature of the enum a member's value may or may not be
4345
important, but either way that value can be used to get the corresponding
@@ -490,6 +492,10 @@ the :meth:`~Enum.__repr__` omits the inherited class' name. For example::
490492
Use the :func:`!dataclass` argument ``repr=False``
491493
to use the standard :func:`repr`.
492494

495+
.. versionchanged:: 3.12
496+
Only the dataclass fields are shown in the value area, not the dataclass'
497+
name.
498+
493499

494500
Pickling
495501
--------
@@ -992,7 +998,9 @@ but remain normal attributes.
992998
Enum members are instances of their enum class, and are normally accessed as
993999
``EnumClass.member``. In certain situations, such as writing custom enum
9941000
behavior, being able to access one member directly from another is useful,
995-
and is supported.
1001+
and is supported; however, in order to avoid name clashes between member names
1002+
and attributes/methods from mixed-in classes, upper-case names are strongly
1003+
recommended.
9961004

9971005
.. versionchanged:: 3.5
9981006

Doc/howto/functional.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,8 +1208,8 @@ General
12081208
-------
12091209

12101210
**Structure and Interpretation of Computer Programs**, by Harold Abelson and
1211-
Gerald Jay Sussman with Julie Sussman. Full text at
1212-
https://mitpress.mit.edu/sicp/. In this classic textbook of computer science,
1211+
Gerald Jay Sussman with Julie Sussman. The book can be found at
1212+
https://mitpress.mit.edu/sicp. In this classic textbook of computer science,
12131213
chapters 2 and 3 discuss the use of sequences and streams to organize the data
12141214
flow inside a program. The book uses Scheme for its examples, but many of the
12151215
design approaches described in these chapters are applicable to functional-style

Doc/howto/urllib2.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ response::
8686

8787
import urllib.request
8888

89-
req = urllib.request.Request('http://www.voidspace.org.uk')
89+
req = urllib.request.Request('http://python.org/')
9090
with urllib.request.urlopen(req) as response:
9191
the_page = response.read()
9292

@@ -458,7 +458,7 @@ To illustrate creating and installing a handler we will use the
458458
``HTTPBasicAuthHandler``. For a more detailed discussion of this subject --
459459
including an explanation of how Basic Authentication works - see the `Basic
460460
Authentication Tutorial
461-
<http://www.voidspace.org.uk/python/articles/authentication.shtml>`_.
461+
<https://web.archive.org/web/20201215133350/http://www.voidspace.org.uk/python/articles/authentication.shtml>`__.
462462

463463
When authentication is required, the server sends a header (as well as the 401
464464
error code) requesting authentication. This specifies the authentication scheme

Doc/library/argparse.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ default_ Default value used when an argument is not provided
6767
dest_ Specify the attribute name used in the result namespace
6868
help_ Help message for an argument
6969
metavar_ Alternate display name for the argument as shown in help
70-
nargs_ Number of times the argument can be used :class:`int`, ``'?'``, ``'*'``, ``'+'``, or ``argparse.REMAINDER``
70+
nargs_ Number of times the argument can be used :class:`int`, ``'?'``, ``'*'``, or ``'+'``
7171
required_ Indicate whether an argument is required or optional ``True`` or ``False``
7272
type_ Automatically convert an argument to the given type :class:`int`, :class:`float`, ``argparse.FileType('w')``, or callable function
7373
====================== =========================================================== ==========================================================================================================================
@@ -2218,7 +2218,7 @@ support this parsing style.
22182218

22192219
These parsers do not support all the argparse features, and will raise
22202220
exceptions if unsupported features are used. In particular, subparsers,
2221-
``argparse.REMAINDER``, and mutually exclusive groups that include both
2221+
and mutually exclusive groups that include both
22222222
optionals and positionals are not supported.
22232223

22242224
The following example shows the difference between

0 commit comments

Comments
 (0)