Skip to content

Commit ad345e0

Browse files
author
Erlend E. Aasland
committed
Merge branch 'main' into bpo-40956/finale
2 parents e59af3b + 1cd3d85 commit ad345e0

File tree

183 files changed

+10948
-8908
lines changed

Some content is hidden

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

183 files changed

+10948
-8908
lines changed

.github/workflows/build.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,46 @@ jobs:
218218
run: make pythoninfo
219219
- name: SSL tests
220220
run: ./python Lib/test/ssltests.py
221+
222+
223+
build_asan:
224+
name: 'Address sanitizer'
225+
runs-on: ubuntu-20.04
226+
needs: check_source
227+
if: needs.check_source.outputs.run_tests == 'true'
228+
env:
229+
OPENSSL_VER: 1.1.1k
230+
ASAN_OPTIONS: detect_leaks=0:allocator_may_return_null=1:handle_segv=0
231+
steps:
232+
- uses: actions/checkout@v2
233+
- name: Register gcc problem matcher
234+
run: echo "::add-matcher::.github/problem-matchers/gcc.json"
235+
- name: Install Dependencies
236+
run: sudo ./.github/workflows/posix-deps-apt.sh
237+
- name: Configure OpenSSL env vars
238+
run: |
239+
echo "MULTISSL_DIR=${GITHUB_WORKSPACE}/multissl" >> $GITHUB_ENV
240+
echo "OPENSSL_DIR=${GITHUB_WORKSPACE}/multissl/openssl/${OPENSSL_VER}" >> $GITHUB_ENV
241+
echo "LD_LIBRARY_PATH=${GITHUB_WORKSPACE}/multissl/openssl/${OPENSSL_VER}/lib" >> $GITHUB_ENV
242+
- name: 'Restore OpenSSL build'
243+
id: cache-openssl
244+
uses: actions/[email protected]
245+
with:
246+
path: ./multissl/openssl/${{ env.OPENSSL_VER }}
247+
key: ${{ runner.os }}-multissl-openssl-${{ env.OPENSSL_VER }}
248+
- name: Install OpenSSL
249+
if: steps.cache-openssl.outputs.cache-hit != 'true'
250+
run: python3 Tools/ssl/multissltests.py --steps=library --base-directory $MULTISSL_DIR --openssl $OPENSSL_VER --system Linux
251+
- name: Add ccache to PATH
252+
run: |
253+
echo "PATH=/usr/lib/ccache:$PATH" >> $GITHUB_ENV
254+
- name: Configure ccache action
255+
uses: hendrikmuhs/ccache-action@v1
256+
- name: Configure CPython
257+
run: ./configure --with-address-sanitizer --without-pymalloc
258+
- name: Build CPython
259+
run: make -j4
260+
- name: Display build info
261+
run: make pythoninfo
262+
- name: Tests
263+
run: xvfb-run make buildbottest TESTOPTS="-j4 -uall,-cpu -x test_ctypes test_crypt test_decimal test_faulthandler test_interpreters test___all__ test_idle test_tix test_tk test_ttk_guionly test_ttk_textonly"

.github/workflows/doc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- name: 'Install build dependencies'
3939
run: make -C Doc/ PYTHON=../python venv
4040
- name: 'Build documentation'
41-
run: xvfb-run make -C Doc/ PYTHON=../python SPHINXOPTS="-q -W --keep-going -j4" doctest html suspicious
41+
run: xvfb-run make -C Doc/ PYTHON=../python SPHINXOPTS="-q -W --keep-going -j4" doctest html
4242
- name: 'Upload'
4343
uses: actions/[email protected]
4444
with:

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ matrix:
5353
- cd Doc
5454
- make venv PYTHON=python
5555
script:
56-
- make check html suspicious SPHINXOPTS="-q -W -j4"
56+
- make check html SPHINXOPTS="-q -W -j4"
5757
- name: "Documentation tests"
5858
os: linux
5959
language: c

Doc/c-api/structures.rst

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,7 @@ the definition of all other Python objects.
9999
100100
Return a :term:`borrowed reference`.
101101
102-
Use the :c:func:`Py_SET_TYPE` function to set an object type.
103-
104-
.. versionchanged:: 3.11
105-
:c:func:`Py_TYPE()` is changed to an inline static function.
102+
The :c:func:`Py_SET_TYPE` function must be used to set an object type.
106103
107104
108105
.. c:function:: int Py_IS_TYPE(PyObject *o, PyTypeObject *type)
@@ -124,10 +121,9 @@ the definition of all other Python objects.
124121
125122
Get the reference count of the Python object *o*.
126123
127-
Use the :c:func:`Py_SET_REFCNT()` function to set an object reference count.
128-
129124
.. versionchanged:: 3.10
130125
:c:func:`Py_REFCNT()` is changed to the inline static function.
126+
Use :c:func:`Py_SET_REFCNT()` to set an object reference count.
131127
132128
133129
.. c:function:: void Py_SET_REFCNT(PyObject *o, Py_ssize_t refcnt)
@@ -141,10 +137,7 @@ the definition of all other Python objects.
141137
142138
Get the size of the Python object *o*.
143139
144-
Use the :c:func:`Py_SET_SIZE` function to set an object size.
145-
146-
.. versionchanged:: 3.11
147-
:c:func:`Py_SIZE()` is changed to an inline static function.
140+
The :c:func:`Py_SET_SIZE` function must be used to set an object size.
148141
149142
150143
.. c:function:: void Py_SET_SIZE(PyVarObject *o, Py_ssize_t size)

Doc/library/dis.rst

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,19 +1056,34 @@ All of the following opcodes use their arguments.
10561056
Deletes local ``co_varnames[var_num]``.
10571057

10581058

1059+
.. opcode:: MAKE_CELL (i)
1060+
1061+
Creates a new cell in slot ``i``. If that slot is empty then
1062+
that value is stored into the new cell.
1063+
1064+
.. versionadded:: 3.11
1065+
1066+
10591067
.. opcode:: LOAD_CLOSURE (i)
10601068

1061-
Pushes a reference to the cell contained in slot *i* of the cell and free
1062-
variable storage. The name of the variable is ``co_cellvars[i]`` if *i* is
1063-
less than the length of *co_cellvars*. Otherwise it is ``co_freevars[i -
1064-
len(co_cellvars)]``.
1069+
Pushes a reference to the cell contained in slot ``i`` of the "fast locals"
1070+
storage. The name of the variable is ``co_fastlocalnames[i]``.
1071+
1072+
Note that ``LOAD_CLOSURE`` is effectively an alias for ``LOAD_FAST``.
1073+
It exists to keep bytecode a little more readable.
1074+
1075+
.. versionchanged:: 3.11
1076+
``i`` is no longer offset by the length of ``co_varnames``.
10651077

10661078

10671079
.. opcode:: LOAD_DEREF (i)
10681080

1069-
Loads the cell contained in slot *i* of the cell and free variable storage.
1081+
Loads the cell contained in slot ``i`` of the "fast locals" storage.
10701082
Pushes a reference to the object the cell contains on the stack.
10711083

1084+
.. versionchanged:: 3.11
1085+
``i`` is no longer offset by the length of ``co_varnames``.
1086+
10721087

10731088
.. opcode:: LOAD_CLASSDEREF (i)
10741089

@@ -1078,20 +1093,29 @@ All of the following opcodes use their arguments.
10781093

10791094
.. versionadded:: 3.4
10801095

1096+
.. versionchanged:: 3.11
1097+
``i`` is no longer offset by the length of ``co_varnames``.
1098+
10811099

10821100
.. opcode:: STORE_DEREF (i)
10831101

1084-
Stores TOS into the cell contained in slot *i* of the cell and free variable
1102+
Stores TOS into the cell contained in slot ``i`` of the "fast locals"
10851103
storage.
10861104

1105+
.. versionchanged:: 3.11
1106+
``i`` is no longer offset by the length of ``co_varnames``.
1107+
10871108

10881109
.. opcode:: DELETE_DEREF (i)
10891110

1090-
Empties the cell contained in slot *i* of the cell and free variable storage.
1111+
Empties the cell contained in slot ``i`` of the "fast locals" storage.
10911112
Used by the :keyword:`del` statement.
10921113

10931114
.. versionadded:: 3.2
10941115

1116+
.. versionchanged:: 3.11
1117+
``i`` is no longer offset by the length of ``co_varnames``.
1118+
10951119

10961120
.. opcode:: RAISE_VARARGS (argc)
10971121

Doc/library/enum.rst

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ An enumeration:
2828

2929
* is a set of symbolic names (members) bound to unique values
3030
* can be iterated over to return its members in definition order
31-
* uses :meth:`call` syntax to return members by value
32-
* uses :meth:`index` syntax to return members by name
31+
* uses *call* syntax to return members by value
32+
* uses *index* syntax to return members by name
3333

3434
Enumerations are created either by using the :keyword:`class` syntax, or by
3535
using function-call syntax::
@@ -91,6 +91,12 @@ Module Contents
9191
the bitwise operators without losing their :class:`IntFlag` membership.
9292
:class:`IntFlag` members are also subclasses of :class:`int`.
9393

94+
:class:`EnumCheck`
95+
96+
An enumeration with the values ``CONTINUOUS``, ``NAMED_FLAGS``, and
97+
``UNIQUE``, for use with :func:`verify` to ensure various constraints
98+
are met by a given enumeration.
99+
94100
:class:`FlagBoundary`
95101

96102
An enumeration with the values ``STRICT``, ``CONFORM``, ``EJECT``, and
@@ -117,9 +123,14 @@ Module Contents
117123

118124
Enum class decorator that ensures only one name is bound to any one value.
119125

126+
:func:`verify`
127+
128+
Enum class decorator that checks user-selectable constraints on an
129+
enumeration.
130+
120131

121132
.. versionadded:: 3.6 ``Flag``, ``IntFlag``, ``auto``
122-
.. versionadded:: 3.10 ``StrEnum``
133+
.. versionadded:: 3.10 ``StrEnum``, ``EnumCheck``, ``FlagBoundary``
123134

124135

125136
Data Types
@@ -514,6 +525,65 @@ Data Types
514525
Using :class:`auto` with :class:`IntFlag` results in integers that are powers
515526
of two, starting with ``1``.
516527

528+
.. class:: EnumCheck
529+
530+
*EnumCheck* contains the options used by the :func:`verify` decorator to ensure
531+
various constraints; failed constraints result in a :exc:`TypeError`.
532+
533+
.. attribute:: UNIQUE
534+
535+
Ensure that each value has only one name::
536+
537+
>>> from enum import Enum, verify, UNIQUE
538+
>>> @verify(UNIQUE)
539+
... class Color(Enum):
540+
... RED = 1
541+
... GREEN = 2
542+
... BLUE = 3
543+
... CRIMSON = 1
544+
Traceback (most recent call last):
545+
...
546+
ValueError: aliases found in <enum 'Color'>: CRIMSON -> RED
547+
548+
549+
.. attribute:: CONTINUOUS
550+
551+
Ensure that there are no missing values between the lowest-valued member
552+
and the highest-valued member::
553+
554+
>>> from enum import Enum, verify, CONTINUOUS
555+
>>> @verify(CONTINUOUS)
556+
... class Color(Enum):
557+
... RED = 1
558+
... GREEN = 2
559+
... BLUE = 5
560+
Traceback (most recent call last):
561+
...
562+
ValueError: invalid enum 'Color': missing values 3, 4
563+
564+
.. attribute:: NAMED_FLAGS
565+
566+
Ensure that any flag groups/masks contain only named flags -- useful when
567+
values are specified instead of being generated by :func:`auto`
568+
569+
>>> from enum import Flag, verify, NAMED_FLAGS
570+
>>> @verify(NAMED_FLAGS)
571+
... class Color(Flag):
572+
... RED = 1
573+
... GREEN = 2
574+
... BLUE = 4
575+
... WHITE = 15
576+
... NEON = 31
577+
Traceback (most recent call last):
578+
...
579+
ValueError: invalid Flag 'Color': 'WHITE' is missing a named flag for value 8; 'NEON' is missing named flags for values 8, 16
580+
581+
.. note::
582+
583+
CONTINUOUS and NAMED_FLAGS are designed to work with integer-valued members.
584+
585+
.. versionadded:: 3.10
586+
517587
.. class:: FlagBoundary
518588

519589
*FlagBoundary* controls how out-of-range values are handled in *Flag* and its
@@ -575,7 +645,7 @@ Data Types
575645
>>> KeepFlag(2**2 + 2**4)
576646
KeepFlag.BLUE|0x10
577647

578-
.. versionadded:: 3.10 ``FlagBoundary``
648+
.. versionadded:: 3.10
579649

580650

581651
Utilites and Decorators
@@ -632,3 +702,11 @@ Utilites and Decorators
632702
Traceback (most recent call last):
633703
...
634704
ValueError: duplicate values found in <enum 'Mistake'>: FOUR -> THREE
705+
706+
.. decorator:: verify
707+
708+
A :keyword:`class` decorator specifically for enumerations. Members from
709+
:class:`EnumCheck` are used to specify which constraints should be checked
710+
on the decorated enumeration.
711+
712+
.. versionadded:: 3.10

Doc/library/exceptions.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,14 +409,16 @@ The following exceptions are the exceptions that are usually raised.
409409

410410
.. versionadded:: 3.5
411411

412-
.. exception:: SyntaxError
412+
.. exception:: SyntaxError(message, details)
413413

414414
Raised when the parser encounters a syntax error. This may occur in an
415-
:keyword:`import` statement, in a call to the built-in functions :func:`exec`
415+
:keyword:`import` statement, in a call to the built-in functions
416+
:func:`compile`, :func:`exec`,
416417
or :func:`eval`, or when reading the initial script or standard input
417418
(also interactively).
418419

419420
The :func:`str` of the exception instance returns only the error message.
421+
Details is a tuple whose members are also available as separate attributes.
420422

421423
.. attribute:: filename
422424

@@ -446,6 +448,11 @@ The following exceptions are the exceptions that are usually raised.
446448
The column in the end line where the error occurred finishes. This is
447449
1-indexed: the first character in the line has an ``offset`` of 1.
448450

451+
For errors in f-string fields, the message is prefixed by "f-string: "
452+
and the offsets are offsets in a text constructed from the replacement
453+
expression. For example, compiling f'Bad {a b} field' results in this
454+
args attribute: ('f-string: ...', ('', 1, 2, '(a b)\n', 1, 5)).
455+
449456
.. versionchanged:: 3.10
450457
Added the :attr:`end_lineno` and :attr:`end_offset` attributes.
451458

@@ -814,3 +821,4 @@ Exception hierarchy
814821
The class hierarchy for built-in exceptions is:
815822

816823
.. literalinclude:: ../../Lib/test/exception_hierarchy.txt
824+
:language: text

Doc/library/fractions.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ another rational number, or from a string.
4242

4343
where the optional ``sign`` may be either '+' or '-' and
4444
``numerator`` and ``denominator`` (if present) are strings of
45-
decimal digits. In addition, any string that represents a finite
45+
decimal digits (underscores may be used to delimit digits as with
46+
integral literals in code). In addition, any string that represents a finite
4647
value and is accepted by the :class:`float` constructor is also
4748
accepted by the :class:`Fraction` constructor. In either form the
4849
input string may also have leading and/or trailing whitespace.
@@ -89,6 +90,10 @@ another rational number, or from a string.
8990
and *denominator*. :func:`math.gcd` always return a :class:`int` type.
9091
Previously, the GCD type depended on *numerator* and *denominator*.
9192

93+
.. versionchanged:: 3.11
94+
Underscores are now permitted when creating a :class:`Fraction` instance
95+
from a string, following :PEP:`515` rules.
96+
9297
.. attribute:: numerator
9398

9499
Numerator of the Fraction in lowest term.

Doc/library/functools.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,16 @@ The :mod:`functools` module defines the following functions:
154154

155155
@lru_cache
156156
def count_vowels(sentence):
157-
sentence = sentence.casefold()
158-
return sum(sentence.count(vowel) for vowel in 'aeiou')
157+
return sum(sentence.count(vowel) for vowel in 'AEIOUaeiou')
159158

160159
If *maxsize* is set to ``None``, the LRU feature is disabled and the cache can
161160
grow without bound.
162161

163162
If *typed* is set to true, function arguments of different types will be
164-
cached separately. For example, ``f(3)`` and ``f(3.0)`` will be treated
165-
as distinct calls with distinct results.
163+
cached separately. For example, ``f(3)`` and ``f(3.0)`` will always be
164+
treated as distinct calls with distinct results. If *typed* is false,
165+
the implementation will usually but not always regard them as equivalent
166+
calls and only cache a single result.
166167

167168
The wrapped function is instrumented with a :func:`cache_parameters`
168169
function that returns a new :class:`dict` showing the values for *maxsize*
@@ -172,8 +173,7 @@ The :mod:`functools` module defines the following functions:
172173
To help measure the effectiveness of the cache and tune the *maxsize*
173174
parameter, the wrapped function is instrumented with a :func:`cache_info`
174175
function that returns a :term:`named tuple` showing *hits*, *misses*,
175-
*maxsize* and *currsize*. In a multi-threaded environment, the hits
176-
and misses are approximate.
176+
*maxsize* and *currsize*.
177177

178178
The decorator also provides a :func:`cache_clear` function for clearing or
179179
invalidating the cache.
@@ -182,6 +182,9 @@ The :mod:`functools` module defines the following functions:
182182
:attr:`__wrapped__` attribute. This is useful for introspection, for
183183
bypassing the cache, or for rewrapping the function with a different cache.
184184

185+
The cache keeps references to the arguments and return values until they age
186+
out of the cache or until the cache is cleared.
187+
185188
An `LRU (least recently used) cache
186189
<https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU)>`_
187190
works best when the most recent calls are the best predictors of upcoming

0 commit comments

Comments
 (0)