Skip to content

Commit dac0309

Browse files
authored
Merge branch 'python:main' into master
2 parents 59dd6ae + 9a5dec4 commit dac0309

20 files changed

Lines changed: 263 additions & 64 deletions

‎Doc/library/dataclasses.rst‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,10 @@ Module contents
324324
Converts the dataclass ``instance`` to a dict (by using the
325325
factory function ``dict_factory``). Each dataclass is converted
326326
to a dict of its fields, as ``name: value`` pairs. dataclasses, dicts,
327-
lists, and tuples are recursed into. For example::
327+
lists, and tuples are recursed into. Other objects are copied with
328+
:func:`copy.deepcopy`.
329+
330+
Example of using :func:`asdict` on nested dataclasses::
328331

329332
@dataclass
330333
class Point:
@@ -341,21 +344,32 @@ Module contents
341344
c = C([Point(0, 0), Point(10, 4)])
342345
assert asdict(c) == {'mylist': [{'x': 0, 'y': 0}, {'x': 10, 'y': 4}]}
343346

344-
Raises :exc:`TypeError` if ``instance`` is not a dataclass instance.
347+
To create a shallow copy, the following workaround may be used::
348+
349+
dict((field.name, getattr(instance, field.name)) for field in fields(instance))
350+
351+
:func:`asdict` raises :exc:`TypeError` if ``instance`` is not a dataclass
352+
instance.
345353

346354
.. function:: astuple(instance, *, tuple_factory=tuple)
347355

348356
Converts the dataclass ``instance`` to a tuple (by using the
349357
factory function ``tuple_factory``). Each dataclass is converted
350358
to a tuple of its field values. dataclasses, dicts, lists, and
351-
tuples are recursed into.
359+
tuples are recursed into. Other objects are copied with
360+
:func:`copy.deepcopy`.
352361

353362
Continuing from the previous example::
354363

355364
assert astuple(p) == (10, 20)
356365
assert astuple(c) == ([(0, 0), (10, 4)],)
357366

358-
Raises :exc:`TypeError` if ``instance`` is not a dataclass instance.
367+
To create a shallow copy, the following workaround may be used::
368+
369+
tuple(getattr(instance, field.name) for field in dataclasses.fields(instance))
370+
371+
:func:`astuple` raises :exc:`TypeError` if ``instance`` is not a dataclass
372+
instance.
359373

360374
.. function:: make_dataclass(cls_name, fields, *, bases=(), namespace=None, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, match_args=True, kw_only=False, slots=False)
361375

‎Doc/library/math.rst‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,13 @@ Power and logarithmic functions
356356
or ``pow(math.e, x)``.
357357

358358

359+
.. function:: exp2(x)
360+
361+
Return *2* raised to the power *x*.
362+
363+
.. versionadded:: 3.11
364+
365+
359366
.. function:: expm1(x)
360367

361368
Return *e* raised to the power *x*, minus 1. Here *e* is the base of natural

‎Doc/using/configure.rst‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,56 @@ See ``Mac/README.rst``.
513513
:option:`--enable-framework` is set (default: ``Python``).
514514

515515

516+
Cross Compiling Options
517+
-----------------------
518+
519+
Cross compiling, also known as cross building, can be used to build Python
520+
for another CPU architecture or platform. Cross compiling requires a Python
521+
interpreter and the :program:`_freeze_module` binary from another build. The
522+
version of the build Python and :program:`_freeze_module` command must be
523+
the same as the cross compiled host Python.
524+
525+
.. cmdoption:: --build=BUILD
526+
527+
configure for building on BUILD, usually guessed by :program:`config.guess`.
528+
529+
.. cmdoption:: --host=HOST
530+
531+
cross-compile to build programs to run on HOST (target platform)
532+
533+
.. cmdoption:: --with-freeze-module=Programs/_freeze_module
534+
535+
path to ``_freeze_module`` binary for cross compiling.
536+
537+
.. versionadded:: 3.11
538+
539+
.. cmdoption:: --with-build-python=python3.xx
540+
541+
path to build ``python`` binary for cross compiling
542+
543+
.. versionadded:: 3.11
544+
545+
.. cmdoption:: CONFIG_SITE=file
546+
547+
An environment variable that points to a file with configure overrides.
548+
549+
Example *config.site* file::
550+
551+
# config.site-aarch64
552+
ac_cv_buggy_getaddrinfo=no
553+
ac_cv_file__dev_ptmx=yes
554+
ac_cv_file__dev_ptc=no
555+
556+
557+
Cross compiling example::
558+
559+
CONFIG_SITE=config.site-aarch64 ../configure \
560+
--build=x86_64-pc-linux-gnu \
561+
--host=aarch64-unknown-linux-gnu \
562+
--with-freeze-module=../x86_64/Programs/_freeze_module \
563+
--with-build-python=../x86_64/python
564+
565+
516566
Python Build System
517567
===================
518568

‎Doc/whatsnew/3.11.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ fractions
203203

204204
math
205205
----
206+
* Add :func:`math.exp2`: return 2 raised to the power of x.
207+
(Contributed by Gideon Mitchell in :issue:`45917`.)
206208

207209
* Add :func:`math.cbrt`: return the cube root of x.
208210
(Contributed by Ajith Ramachandran in :issue:`44357`.)

‎Lib/test/test_embed.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def setUp(self):
6565
ext = ("_d" if debug_build(sys.executable) else "") + ".exe"
6666
exename += ext
6767
exepath = builddir
68-
expecteddir = support.REPO_ROOT
68+
expecteddir = os.path.join(support.REPO_ROOT, builddir)
6969
else:
7070
exepath = os.path.join(builddir, 'Programs')
7171
expecteddir = os.path.join(support.REPO_ROOT, 'Programs')

‎Lib/test/test_graphlib.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from itertools import chain
21
import graphlib
32
import os
43
import unittest
@@ -34,7 +33,7 @@ def _assert_cycle(self, graph, cycle):
3433
try:
3534
ts.prepare()
3635
except graphlib.CycleError as e:
37-
msg, seq = e.args
36+
_, seq = e.args
3837
self.assertIn(" ".join(map(str, cycle)), " ".join(map(str, seq * 2)))
3938
else:
4039
raise

‎Lib/test/test_math.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,17 @@ def testExp(self):
501501
self.assertTrue(math.isnan(math.exp(NAN)))
502502
self.assertRaises(OverflowError, math.exp, 1000000)
503503

504+
def testExp2(self):
505+
self.assertRaises(TypeError, math.exp2)
506+
self.ftest('exp2(-1)', math.exp2(-1), 0.5)
507+
self.ftest('exp2(0)', math.exp2(0), 1)
508+
self.ftest('exp2(1)', math.exp2(1), 2)
509+
self.ftest('exp2(2.3)', math.exp2(2.3), 4.924577653379665)
510+
self.assertEqual(math.exp2(INF), INF)
511+
self.assertEqual(math.exp2(NINF), 0.)
512+
self.assertTrue(math.isnan(math.exp2(NAN)))
513+
self.assertRaises(OverflowError, math.exp2, 1000000)
514+
504515
def testFabs(self):
505516
self.assertRaises(TypeError, math.fabs)
506517
self.ftest('fabs(-1)', math.fabs(-1), 1)

‎Makefile.pre.in‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@
282282
_PYTHON_HOST_PLATFORM=@_PYTHON_HOST_PLATFORM@
283283
BUILD_GNU_TYPE= @build@
284284
HOST_GNU_TYPE= @host@
285+
# Allow developers to override freeze_module command for cross building (bpo-45886)
286+
FREEZE_MODULE?=@FREEZE_MODULE@
285287

286288
# Tcl and Tk config info from --with-tcltk-includes and -libs options
287289
TCLTK_INCLUDES= @TCLTK_INCLUDES@
@@ -1011,9 +1013,6 @@ Python/deepfreeze/frozen_only.c: Python/frozen_modules/frozen_only.h $(DEEPFREEZ
10111013
############################################################################
10121014
# frozen modules (including importlib)
10131015

1014-
# Allow developers to override freeze_module command for cross building (bpo-45886)
1015-
FREEZE_MODULE?=Programs/_freeze_module
1016-
10171016
# FROZEN_FILES_* are auto-generated by Tools/scripts/freeze_modules.py.
10181017
FROZEN_FILES_IN = \
10191018
Lib/importlib/_bootstrap.py \

‎Misc/ACKS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,7 @@ Julien Miotte
11911191
Andrii V. Mishkovskyi
11921192
Dom Mitchell
11931193
Dustin J. Mitchell
1194+
Gideon Mitchell
11941195
Tim Mitchell
11951196
Zubin Mithra
11961197
Florian Mladitsch
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The :program:`configure` script now accepts ``--with-build-python`` and
2+
``--with-freeze-module`` options to make cross compiling easier.

0 commit comments

Comments
 (0)