Skip to content

Commit cbd17a2

Browse files
committed
Merge branch 'main' into gh-148871/load-common-constant
2 parents 724e285 + 3a1df78 commit cbd17a2

87 files changed

Lines changed: 3727 additions & 947 deletions

File tree

Some content is hidden

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

Doc/c-api/perfmaps.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Note that holding an :term:`attached thread state` is not required for these API
3131
or ``-2`` on failure to create a lock. Check ``errno`` for more information
3232
about the cause of a failure.
3333

34-
.. c:function:: int PyUnstable_WritePerfMapEntry(const void *code_addr, unsigned int code_size, const char *entry_name)
34+
.. c:function:: int PyUnstable_WritePerfMapEntry(const void *code_addr, size_t code_size, const char *entry_name)
3535
3636
Write one single entry to the ``/tmp/perf-$pid.map`` file. This function is
3737
thread safe. Here is what an example entry looks like::

Doc/deprecations/pending-removal-in-3.20.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@ Pending removal in Python 3.20
3838
- :mod:`zlib`
3939

4040
(Contributed by Hugo van Kemenade and Stan Ulbrych in :gh:`76007`.)
41+
42+
* :mod:`ast`:
43+
44+
* Creating instances of abstract AST nodes (such as :class:`ast.AST`
45+
or :class:`!ast.expr`) is deprecated and will raise an error in Python 3.20.

Doc/library/ast.rst

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Node classes
4242

4343
.. class:: AST
4444

45-
This is the base of all AST node classes. The actual node classes are
45+
This is the abstract base of all AST node classes. The actual node classes are
4646
derived from the :file:`Parser/Python.asdl` file, which is reproduced
4747
:ref:`above <abstract-grammar>`. They are defined in the :mod:`!_ast` C
4848
module and re-exported in :mod:`!ast`.
@@ -168,6 +168,15 @@ Node classes
168168
arguments that were set as attributes of the AST node, even if they did not
169169
match any of the fields of the AST node. These cases now raise a :exc:`TypeError`.
170170

171+
.. deprecated-removed:: next 3.20
172+
173+
In the :ref:`grammar above <abstract-grammar>`, the AST node classes that
174+
correspond to production rules with variants (aka "sums") are abstract
175+
classes. Previous versions of Python allowed for the creation of direct
176+
instances of these abstract node classes. This behavior is deprecated and
177+
will be removed in Python 3.20.
178+
179+
171180
.. note::
172181
The descriptions of the specific node classes displayed here
173182
were initially adapted from the fantastic `Green Tree
@@ -271,18 +280,25 @@ Root nodes
271280
Literals
272281
^^^^^^^^
273282

274-
.. class:: Constant(value)
283+
.. class:: Constant(value, kind)
275284

276285
A constant value. The ``value`` attribute of the ``Constant`` literal contains the
277286
Python object it represents. The values represented can be instances of :class:`str`,
278287
:class:`bytes`, :class:`int`, :class:`float`, :class:`complex`, and :class:`bool`,
279288
and the constants :data:`None` and :data:`Ellipsis`.
280289

290+
The ``kind`` attribute is an optional string. For string literals with a
291+
``u`` prefix, ``kind`` is set to ``'u'``. For all other
292+
constants, ``kind`` is ``None``.
293+
281294
.. doctest::
282295

283296
>>> print(ast.dump(ast.parse('123', mode='eval'), indent=4))
284297
Expression(
285298
body=Constant(value=123))
299+
>>> print(ast.dump(ast.parse("u'hello'", mode='eval'), indent=4))
300+
Expression(
301+
body=Constant(value='hello', kind='u'))
286302

287303

288304
.. class:: FormattedValue(value, conversion, format_spec)
@@ -2536,6 +2552,20 @@ and classes for traversing abstract syntax trees:
25362552
Added the *color* parameter.
25372553

25382554

2555+
.. function:: compare(a, b, /, *, compare_attributes=False)
2556+
2557+
Recursively compares two ASTs.
2558+
2559+
*compare_attributes* affects whether AST attributes are considered
2560+
in the comparison. If *compare_attributes* is ``False`` (default), then
2561+
attributes are ignored. Otherwise they must all be equal. This
2562+
option is useful to check whether the ASTs are structurally equal but
2563+
differ in whitespace or similar details. Attributes include line numbers
2564+
and column offsets.
2565+
2566+
.. versionadded:: 3.14
2567+
2568+
25392569
.. _ast-compiler-flags:
25402570

25412571
Compiler flags
@@ -2571,20 +2601,6 @@ effects on the compilation of a program:
25712601
.. versionadded:: 3.8
25722602

25732603

2574-
.. function:: compare(a, b, /, *, compare_attributes=False)
2575-
2576-
Recursively compares two ASTs.
2577-
2578-
*compare_attributes* affects whether AST attributes are considered
2579-
in the comparison. If *compare_attributes* is ``False`` (default), then
2580-
attributes are ignored. Otherwise they must all be equal. This
2581-
option is useful to check whether the ASTs are structurally equal but
2582-
differ in whitespace or similar details. Attributes include line numbers
2583-
and column offsets.
2584-
2585-
.. versionadded:: 3.14
2586-
2587-
25882604
.. _ast-cli:
25892605

25902606
Command-line usage

Doc/library/statistics.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ However, for reading convenience, most of the examples show sorted sequences.
713713

714714
.. function:: covariance(x, y, /)
715715

716-
Return the sample covariance of two inputs *x* and *y*. Covariance
716+
Return the sample covariance of two sequence inputs *x* and *y*. Covariance
717717
is a measure of the joint variability of two inputs.
718718

719719
Both inputs must be of the same length (no less than two), otherwise
@@ -739,7 +739,7 @@ However, for reading convenience, most of the examples show sorted sequences.
739739

740740
Return the `Pearson's correlation coefficient
741741
<https://en.wikipedia.org/wiki/Pearson_correlation_coefficient>`_
742-
for two inputs. Pearson's correlation coefficient *r* takes values
742+
for two sequence inputs. Pearson's correlation coefficient *r* takes values
743743
between -1 and +1. It measures the strength and direction of a linear
744744
relationship.
745745

@@ -802,7 +802,7 @@ However, for reading convenience, most of the examples show sorted sequences.
802802
(it is equal to the difference between predicted and actual values
803803
of the dependent variable).
804804

805-
Both inputs must be of the same length (no less than two), and
805+
Both inputs must be sequences of the same length (no less than two), and
806806
the independent variable *x* cannot be constant;
807807
otherwise a :exc:`StatisticsError` is raised.
808808

Doc/whatsnew/3.15.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,13 @@ Deprecated
18461846
New deprecations
18471847
----------------
18481848

1849+
* :mod:`ast`
1850+
1851+
* Creating instances of abstract AST nodes (such as :class:`ast.AST`
1852+
or :class:`!ast.expr`) is deprecated and will raise an error in Python 3.20.
1853+
1854+
(Contributed by Brian Schubert in :gh:`116021`.)
1855+
18491856
* :mod:`base64`:
18501857

18511858
* Accepting the ``+`` and ``/`` characters with an alternative alphabet in

Include/cpython/ceval.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ typedef struct {
3838
PyAPI_FUNC(int) PyUnstable_PerfMapState_Init(void);
3939
PyAPI_FUNC(int) PyUnstable_WritePerfMapEntry(
4040
const void *code_addr,
41-
unsigned int code_size,
41+
size_t code_size,
4242
const char *entry_name);
4343
PyAPI_FUNC(void) PyUnstable_PerfMapState_Fini(void);
4444
PyAPI_FUNC(int) PyUnstable_CopyPerfMapFile(const char* parent_filename);

Include/internal/pycore_ast_state.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_ceval.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ typedef struct {
9494
void* (*init_state)(void);
9595
// Callback to register every trampoline being created
9696
void (*write_state)(void* state, const void *code_addr,
97-
unsigned int code_size, PyCodeObject* code);
97+
size_t code_size, PyCodeObject* code);
9898
// Callback to free the trampoline state
9999
int (*free_state)(void* state);
100100
} _PyPerf_Callbacks;
@@ -108,6 +108,10 @@ extern PyStatus _PyPerfTrampoline_AfterFork_Child(void);
108108
#ifdef PY_HAVE_PERF_TRAMPOLINE
109109
extern _PyPerf_Callbacks _Py_perfmap_callbacks;
110110
extern _PyPerf_Callbacks _Py_perfmap_jit_callbacks;
111+
extern void _PyPerfJit_WriteNamedCode(const void *code_addr,
112+
size_t code_size,
113+
const char *entry,
114+
const char *filename);
111115
#endif
112116

113117
static inline PyObject*

Include/internal/pycore_debug_offsets.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ typedef struct _Py_DebugOffsets {
215215
uint64_t state;
216216
uint64_t length;
217217
uint64_t asciiobject_size;
218+
uint64_t compactunicodeobject_size;
218219
} unicode_object;
219220

220221
// GC runtime state offset;
@@ -370,6 +371,7 @@ typedef struct _Py_DebugOffsets {
370371
.state = offsetof(PyUnicodeObject, _base._base.state), \
371372
.length = offsetof(PyUnicodeObject, _base._base.length), \
372373
.asciiobject_size = sizeof(PyASCIIObject), \
374+
.compactunicodeobject_size = sizeof(PyCompactUnicodeObject), \
373375
}, \
374376
.gc = { \
375377
.size = sizeof(struct _gc_runtime_state), \

Include/internal/pycore_global_objects_fini_generated.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)