Skip to content

Commit 3de752b

Browse files
authored
Merge branch 'main' into fix-docfile-typos
2 parents 6ac14f6 + 62173cc commit 3de752b

33 files changed

+622
-469
lines changed

.github/actionlint.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
self-hosted-runner:
2-
labels: ["windows-aarch64"]
2+
# Pending https://github.com/rhysd/actionlint/issues/533
3+
labels: ["windows-11-arm"]
34

45
config-variables: null
56

.github/workflows/build.yml

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -156,28 +156,18 @@ jobs:
156156
strategy:
157157
fail-fast: false
158158
matrix:
159-
os:
160-
- windows-latest
161159
arch:
162160
- x64
161+
- Win32
162+
- arm64
163163
free-threading:
164164
- false
165165
- true
166-
include:
167-
# Forks don't have access to Windows on Arm runners. These jobs are skipped below:
168-
- os: ${{ github.repository_owner == 'python' && 'windows-aarch64' || 'windows-latest' }}
169-
arch: arm64
170-
free-threading: false
171-
# Forks don't have access to Windows on Arm runners. These jobs are skipped below:
172-
- os: ${{ github.repository_owner == 'python' && 'windows-aarch64' || 'windows-latest' }}
173-
arch: arm64
174-
free-threading: true
175-
- os: windows-latest
176-
arch: Win32
177-
free-threading: false
166+
exclude:
167+
# Skip Win32 on free-threaded builds
168+
- { arch: Win32, free-threading: true }
178169
uses: ./.github/workflows/reusable-windows.yml
179170
with:
180-
os: ${{ matrix.os }}
181171
arch: ${{ matrix.arch }}
182172
free-threading: ${{ matrix.free-threading }}
183173

@@ -189,18 +179,12 @@ jobs:
189179
strategy:
190180
fail-fast: false
191181
matrix:
192-
os:
193-
- windows-latest
194182
arch:
195183
- x86
196184
- x64
197-
include:
198-
# Forks don't have access to Windows on Arm runners. These jobs are skipped below:
199-
- os: ${{ github.repository_owner == 'python' && 'windows-aarch64' || 'windows-latest' }}
200-
arch: arm64
185+
- arm64
201186
uses: ./.github/workflows/reusable-windows-msi.yml
202187
with:
203-
os: ${{ matrix.os }}
204188
arch: ${{ matrix.arch }}
205189

206190
build-macos:

.github/workflows/jit.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ jobs:
7474
runner: windows-latest
7575
- target: aarch64-pc-windows-msvc/msvc
7676
architecture: ARM64
77-
# Forks don't have access to Windows on Arm runners. These jobs are skipped below:
78-
runner: ${{ github.repository_owner == 'python' && 'windows-aarch64' || 'windows-latest' }}
77+
runner: windows-11-arm
7978
- target: x86_64-apple-darwin/clang
8079
architecture: x86_64
8180
runner: macos-13
@@ -97,8 +96,7 @@ jobs:
9796
python-version: '3.11'
9897

9998
- name: Windows
100-
# Forks don't have access to Windows on Arm runners. Skip those:
101-
if: runner.os == 'Windows' && (matrix.architecture != 'ARM64' || github.repository_owner == 'python')
99+
if: runner.os == 'Windows'
102100
run: |
103101
choco install llvm --allow-downgrade --no-progress --version ${{ matrix.llvm }}.1.0
104102
./PCbuild/build.bat --experimental-jit ${{ matrix.debug && '-d' || '' }} -p ${{ matrix.architecture }}

.github/workflows/reusable-windows-msi.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ name: Reusable Windows MSI
33
on:
44
workflow_call:
55
inputs:
6-
os:
7-
description: OS to run on
8-
required: true
9-
type: string
106
arch:
117
description: CPU architecture
128
required: true
@@ -21,7 +17,7 @@ env:
2117
jobs:
2218
build:
2319
name: installer for ${{ inputs.arch }}
24-
runs-on: ${{ inputs.os }}
20+
runs-on: ${{ inputs.arch == 'arm64' && 'windows-11-arm' || 'windows-latest' }}
2521
timeout-minutes: 60
2622
env:
2723
ARCH: ${{ inputs.arch }}
@@ -31,7 +27,5 @@ jobs:
3127
with:
3228
persist-credentials: false
3329
- name: Build CPython installer
34-
# Forks don't have access to Windows on Arm runners. Skip those:
35-
if: inputs.arch != 'arm64' || github.repository_owner == 'python'
3630
run: ./Tools/msi/build.bat --doc -"${ARCH}"
3731
shell: bash

.github/workflows/reusable-windows.yml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ name: Reusable Windows
33
on:
44
workflow_call:
55
inputs:
6-
os:
7-
description: OS to run on
8-
required: true
9-
type: string
106
arch:
117
description: CPU architecture
128
required: true
@@ -25,7 +21,7 @@ env:
2521
jobs:
2622
build:
2723
name: Build and test (${{ inputs.arch }})
28-
runs-on: ${{ inputs.os }}
24+
runs-on: ${{ inputs.arch == 'arm64' && 'windows-11-arm' || 'windows-latest' }}
2925
timeout-minutes: 60
3026
env:
3127
ARCH: ${{ inputs.arch }}
@@ -37,21 +33,15 @@ jobs:
3733
if: inputs.arch != 'Win32'
3834
run: echo "::add-matcher::.github/problem-matchers/msvc.json"
3935
- name: Build CPython
40-
# Forks don't have access to Windows on Arm runners. Skip those:
41-
if: inputs.arch != 'arm64' || github.repository_owner == 'python'
4236
run: >-
4337
.\\PCbuild\\build.bat
4438
-e -d -v
4539
-p "${ARCH}"
4640
${{ fromJSON(inputs.free-threading) && '--disable-gil' || '' }}
4741
shell: bash
4842
- name: Display build info
49-
# Forks don't have access to Windows on Arm runners. Skip those:
50-
if: inputs.arch != 'arm64' || github.repository_owner == 'python'
5143
run: .\\python.bat -m test.pythoninfo
5244
- name: Tests
53-
# Forks don't have access to Windows on Arm runners. Skip those:
54-
if: inputs.arch != 'arm64' || github.repository_owner == 'python'
5545
run: >-
5646
.\\PCbuild\\rt.bat
5747
-p "${ARCH}"

Doc/library/typing.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2455,7 +2455,8 @@ types.
24552455
See :pep:`544` for more details. Protocol classes decorated with
24562456
:func:`runtime_checkable` (described later) act as simple-minded runtime
24572457
protocols that check only the presence of given attributes, ignoring their
2458-
type signatures.
2458+
type signatures. Protocol classes without this decorator cannot be used
2459+
as the second argument to :func:`isinstance` or :func:`issubclass`.
24592460

24602461
Protocol classes can be generic, for example::
24612462

@@ -2479,8 +2480,7 @@ types.
24792480
Mark a protocol class as a runtime protocol.
24802481

24812482
Such a protocol can be used with :func:`isinstance` and :func:`issubclass`.
2482-
This raises :exc:`TypeError` when applied to a non-protocol class. This
2483-
allows a simple-minded structural check, very similar to "one trick ponies"
2483+
This allows a simple-minded structural check, very similar to "one trick ponies"
24842484
in :mod:`collections.abc` such as :class:`~collections.abc.Iterable`. For example::
24852485

24862486
@runtime_checkable
@@ -2496,6 +2496,8 @@ types.
24962496
import threading
24972497
assert isinstance(threading.Thread(name='Bob'), Named)
24982498

2499+
This decorator raises :exc:`TypeError` when applied to a non-protocol class.
2500+
24992501
.. note::
25002502

25012503
:func:`!runtime_checkable` will check only the presence of the required

Doc/reference/datamodel.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3319,7 +3319,7 @@ left undefined.
33193319
:meth:`__divmod__` method should be the equivalent to using
33203320
:meth:`__floordiv__` and :meth:`__mod__`; it should not be related to
33213321
:meth:`__truediv__`. Note that :meth:`__pow__` should be defined to accept
3322-
an optional third argument if the ternary version of the built-in :func:`pow`
3322+
an optional third argument if the three-argument version of the built-in :func:`pow`
33233323
function is to be supported.
33243324

33253325
If one of those methods does not support the operation with the supplied
@@ -3356,10 +3356,15 @@ left undefined.
33563356
is called if ``type(x).__sub__(x, y)`` returns :data:`NotImplemented` or ``type(y)``
33573357
is a subclass of ``type(x)``. [#]_
33583358

3359-
.. index:: pair: built-in function; pow
3359+
Note that :meth:`__rpow__` should be defined to accept an optional third
3360+
argument if the three-argument version of the built-in :func:`pow` function
3361+
is to be supported.
33603362

3361-
Note that ternary :func:`pow` will not try calling :meth:`__rpow__` (the
3362-
coercion rules would become too complicated).
3363+
.. versionchanged:: next
3364+
3365+
Three-argument :func:`pow` now try calling :meth:`~object.__rpow__` if necessary.
3366+
Previously it was only called in two-argument :func:`!pow` and the binary
3367+
power operator.
33633368

33643369
.. note::
33653370

Doc/whatsnew/3.14.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,11 @@ Other language changes
458458
The testbed can also be used to run the test suite of projects other than
459459
CPython itself. (Contributed by Russell Keith-Magee in :gh:`127592`.)
460460

461+
* Three-argument :func:`pow` now try calling :meth:`~object.__rpow__` if necessary.
462+
Previously it was only called in two-argument :func:`!pow` and the binary
463+
power operator.
464+
(Contributed by Serhiy Storchaka in :gh:`130104`.)
465+
461466
* Add a built-in implementation for HMAC (:rfc:`2104`) using formally verified
462467
code from the `HACL* <https://github.com/hacl-star/hacl-star/>`__ project.
463468
This implementation is used as a fallback when the OpenSSL implementation

Lib/_pydecimal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,12 +2440,12 @@ def __pow__(self, other, modulo=None, context=None):
24402440

24412441
return ans
24422442

2443-
def __rpow__(self, other, context=None):
2443+
def __rpow__(self, other, modulo=None, context=None):
24442444
"""Swaps self/other and returns __pow__."""
24452445
other = _convert_other(other)
24462446
if other is NotImplemented:
24472447
return other
2448-
return other.__pow__(self, context=context)
2448+
return other.__pow__(self, modulo, context=context)
24492449

24502450
def normalize(self, context=None):
24512451
"""Normalize- strip trailing 0s, change anything equal to 0 to 0e0"""

Lib/annotationlib.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,15 @@ def __init__(
7777
self.__forward_is_argument__ = is_argument
7878
self.__forward_is_class__ = is_class
7979
self.__forward_module__ = module
80+
self.__owner__ = owner
81+
# These are always set to None here but may be non-None if a ForwardRef
82+
# is created through __class__ assignment on a _Stringifier object.
8083
self.__globals__ = None
84+
self.__cell__ = None
85+
# These are initially None but serve as a cache and may be set to a non-None
86+
# value later.
8187
self.__code__ = None
8288
self.__ast_node__ = None
83-
self.__cell__ = None
84-
self.__owner__ = owner
8589

8690
def __init_subclass__(cls, /, *args, **kwds):
8791
raise TypeError("Cannot subclass ForwardRef")
@@ -716,11 +720,11 @@ def get_annotations(
716720
# For STRING, we try to call __annotate__
717721
ann = _get_and_call_annotate(obj, format)
718722
if ann is not None:
719-
return ann
723+
return dict(ann)
720724
# But if we didn't get it, we use __annotations__ instead.
721725
ann = _get_dunder_annotations(obj)
722726
if ann is not None:
723-
ann = annotations_to_string(ann)
727+
return annotations_to_string(ann)
724728
case Format.VALUE_WITH_FAKE_GLOBALS:
725729
raise ValueError("The VALUE_WITH_FAKE_GLOBALS format is for internal use only")
726730
case _:
@@ -813,35 +817,39 @@ def type_repr(value):
813817

814818

815819
def annotations_to_string(annotations):
816-
"""Convert an annotation dict containing values to approximately the STRING format."""
820+
"""Convert an annotation dict containing values to approximately the STRING format.
821+
822+
Always returns a fresh a dictionary.
823+
"""
817824
return {
818825
n: t if isinstance(t, str) else type_repr(t)
819826
for n, t in annotations.items()
820827
}
821828

822829

823830
def _get_and_call_annotate(obj, format):
831+
"""Get the __annotate__ function and call it.
832+
833+
May not return a fresh dictionary.
834+
"""
824835
annotate = get_annotate_function(obj)
825836
if annotate is not None:
826837
ann = call_annotate_function(annotate, format, owner=obj)
827838
if not isinstance(ann, dict):
828839
raise ValueError(f"{obj!r}.__annotate__ returned a non-dict")
829-
return dict(ann)
840+
return ann
830841
return None
831842

832843

833844
def _get_dunder_annotations(obj):
834-
if isinstance(obj, type):
835-
try:
836-
ann = obj.__annotations__
837-
except AttributeError:
838-
# For static types, the descriptor raises AttributeError.
839-
return None
840-
else:
841-
ann = getattr(obj, "__annotations__", None)
842-
if ann is None:
843-
return None
845+
"""Return the annotations for an object, checking that it is a dictionary.
846+
847+
Does not return a fresh dictionary.
848+
"""
849+
ann = getattr(obj, "__annotations__", None)
850+
if ann is None:
851+
return None
844852

845853
if not isinstance(ann, dict):
846854
raise ValueError(f"{obj!r}.__annotations__ is neither a dict nor None")
847-
return dict(ann)
855+
return ann

0 commit comments

Comments
 (0)