Skip to content

Commit b609279

Browse files
committed
Merge branch 'main' into target-generator
2 parents 1ed8cd7 + e96f260 commit b609279

28 files changed

+399
-114
lines changed

Doc/library/ast.rst

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Node classes
4545

4646
This is the base of all AST node classes. The actual node classes are
4747
derived from the :file:`Parser/Python.asdl` file, which is reproduced
48-
:ref:`above <abstract-grammar>`. They are defined in the :mod:`_ast` C
48+
:ref:`above <abstract-grammar>`. They are defined in the :mod:`!_ast` C
4949
module and re-exported in :mod:`ast`.
5050

5151
There is one class defined for each left-hand side symbol in the abstract
@@ -128,14 +128,14 @@ Node classes
128128

129129
.. deprecated:: 3.8
130130

131-
Old classes :class:`ast.Num`, :class:`ast.Str`, :class:`ast.Bytes`,
132-
:class:`ast.NameConstant` and :class:`ast.Ellipsis` are still available,
131+
Old classes :class:`!ast.Num`, :class:`!ast.Str`, :class:`!ast.Bytes`,
132+
:class:`!ast.NameConstant` and :class:`!ast.Ellipsis` are still available,
133133
but they will be removed in future Python releases. In the meantime,
134134
instantiating them will return an instance of a different class.
135135

136136
.. deprecated:: 3.9
137137

138-
Old classes :class:`ast.Index` and :class:`ast.ExtSlice` are still
138+
Old classes :class:`!ast.Index` and :class:`!ast.ExtSlice` are still
139139
available, but they will be removed in future Python releases.
140140
In the meantime, instantiating them will return an instance of
141141
a different class.
@@ -1935,8 +1935,7 @@ Function and class definitions
19351935
.. class:: arg(arg, annotation, type_comment)
19361936

19371937
A single argument in a list. ``arg`` is a raw string of the argument
1938-
name, ``annotation`` is its annotation, such as a :class:`Str` or
1939-
:class:`Name` node.
1938+
name; ``annotation`` is its annotation, such as a :class:`Name` node.
19401939

19411940
.. attribute:: type_comment
19421941

@@ -2210,7 +2209,7 @@ and classes for traversing abstract syntax trees:
22102209
Added ``type_comments``, ``mode='func_type'`` and ``feature_version``.
22112210

22122211
.. versionchanged:: 3.13
2213-
The minimum supported version for feature_version is now (3,7)
2212+
The minimum supported version for ``feature_version`` is now ``(3, 7)``.
22142213
The ``optimize`` argument was added.
22152214

22162215

@@ -2286,8 +2285,8 @@ and classes for traversing abstract syntax trees:
22862285
.. function:: get_source_segment(source, node, *, padded=False)
22872286

22882287
Get source code segment of the *source* that generated *node*.
2289-
If some location information (:attr:`lineno`, :attr:`end_lineno`,
2290-
:attr:`col_offset`, or :attr:`end_col_offset`) is missing, return ``None``.
2288+
If some location information (:attr:`~ast.AST.lineno`, :attr:`~ast.AST.end_lineno`,
2289+
:attr:`~ast.AST.col_offset`, or :attr:`~ast.AST.end_col_offset`) is missing, return ``None``.
22912290

22922291
If *padded* is ``True``, the first line of a multi-line statement will
22932292
be padded with spaces to match its original position.
@@ -2298,7 +2297,7 @@ and classes for traversing abstract syntax trees:
22982297
.. function:: fix_missing_locations(node)
22992298

23002299
When you compile a node tree with :func:`compile`, the compiler expects
2301-
:attr:`lineno` and :attr:`col_offset` attributes for every node that supports
2300+
:attr:`~ast.AST.lineno` and :attr:`~ast.AST.col_offset` attributes for every node that supports
23022301
them. This is rather tedious to fill in for generated nodes, so this helper
23032302
adds these attributes recursively where not already set, by setting them to
23042303
the values of the parent node. It works recursively starting at *node*.
@@ -2313,8 +2312,8 @@ and classes for traversing abstract syntax trees:
23132312

23142313
.. function:: copy_location(new_node, old_node)
23152314

2316-
Copy source location (:attr:`lineno`, :attr:`col_offset`, :attr:`end_lineno`,
2317-
and :attr:`end_col_offset`) from *old_node* to *new_node* if possible,
2315+
Copy source location (:attr:`~ast.AST.lineno`, :attr:`~ast.AST.col_offset`, :attr:`~ast.AST.end_lineno`,
2316+
and :attr:`~ast.AST.end_col_offset`) from *old_node* to *new_node* if possible,
23182317
and return *new_node*.
23192318

23202319

@@ -2360,14 +2359,18 @@ and classes for traversing abstract syntax trees:
23602359
visited unless the visitor calls :meth:`generic_visit` or visits them
23612360
itself.
23622361

2362+
.. method:: visit_Constant(node)
2363+
2364+
Handles all constant nodes.
2365+
23632366
Don't use the :class:`NodeVisitor` if you want to apply changes to nodes
23642367
during traversal. For this a special visitor exists
23652368
(:class:`NodeTransformer`) that allows modifications.
23662369

23672370
.. deprecated:: 3.8
23682371

2369-
Methods :meth:`visit_Num`, :meth:`visit_Str`, :meth:`visit_Bytes`,
2370-
:meth:`visit_NameConstant` and :meth:`visit_Ellipsis` are deprecated
2372+
Methods :meth:`!visit_Num`, :meth:`!visit_Str`, :meth:`!visit_Bytes`,
2373+
:meth:`!visit_NameConstant` and :meth:`!visit_Ellipsis` are deprecated
23712374
now and will not be called in future Python versions. Add the
23722375
:meth:`visit_Constant` method to handle all constant nodes.
23732376

@@ -2396,7 +2399,7 @@ and classes for traversing abstract syntax trees:
23962399
)
23972400

23982401
Keep in mind that if the node you're operating on has child nodes you must
2399-
either transform the child nodes yourself or call the :meth:`generic_visit`
2402+
either transform the child nodes yourself or call the :meth:`~ast.NodeVisitor.generic_visit`
24002403
method for the node first.
24012404

24022405
For nodes that were part of a collection of statements (that applies to all
@@ -2405,7 +2408,7 @@ and classes for traversing abstract syntax trees:
24052408

24062409
If :class:`NodeTransformer` introduces new nodes (that weren't part of
24072410
original tree) without giving them location information (such as
2408-
:attr:`lineno`), :func:`fix_missing_locations` should be called with
2411+
:attr:`~ast.AST.lineno`), :func:`fix_missing_locations` should be called with
24092412
the new sub-tree to recalculate the location information::
24102413

24112414
tree = ast.parse('foo', mode='eval')

Doc/library/collections.abc.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ the required methods (unless those methods have been set to
8787

8888
class E:
8989
def __iter__(self): ...
90-
def __next__(next): ...
90+
def __next__(self): ...
9191

9292
.. doctest::
9393

Doc/library/tomllib.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Conversion Table
9595
+------------------+--------------------------------------------------------------------------------------+
9696
| TOML | Python |
9797
+==================+======================================================================================+
98-
| table | dict |
98+
| TOML document | dict |
9999
+------------------+--------------------------------------------------------------------------------------+
100100
| string | str |
101101
+------------------+--------------------------------------------------------------------------------------+
@@ -115,3 +115,9 @@ Conversion Table
115115
+------------------+--------------------------------------------------------------------------------------+
116116
| array | list |
117117
+------------------+--------------------------------------------------------------------------------------+
118+
| table | dict |
119+
+------------------+--------------------------------------------------------------------------------------+
120+
| inline table | dict |
121+
+------------------+--------------------------------------------------------------------------------------+
122+
| array of tables | list of dicts |
123+
+------------------+--------------------------------------------------------------------------------------+

Doc/reference/datamodel.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2811,7 +2811,7 @@ through the object's keys; for sequences, it should iterate through the values.
28112811
the accepted keys should be integers and slice objects. Note that the
28122812
special interpretation of negative indexes (if the class wishes to emulate a
28132813
:term:`sequence` type) is up to the :meth:`__getitem__` method. If *key* is
2814-
of an inappropriate type, :exc:`TypeError` may be raised; if of a value
2814+
of an inappropriate type, :exc:`TypeError` may be raised; if *key* is a value
28152815
outside the set of indexes for the sequence (after any special
28162816
interpretation of negative values), :exc:`IndexError` should be raised. For
28172817
:term:`mapping` types, if *key* is missing (not in the container),

Include/internal/pycore_typeobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ _PyType_IsReady(PyTypeObject *type)
133133

134134
extern PyObject* _Py_type_getattro_impl(PyTypeObject *type, PyObject *name,
135135
int *suppress_missing_attribute);
136-
extern PyObject* _Py_type_getattro(PyTypeObject *type, PyObject *name);
136+
extern PyObject* _Py_type_getattro(PyObject *type, PyObject *name);
137137

138138
extern PyObject* _Py_BaseObject_RichCompare(PyObject* self, PyObject* other, int op);
139139

Lib/tarfile.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2106,6 +2106,10 @@ def list(self, verbose=True, *, members=None):
21062106
output is produced. `members' is optional and must be a subset of the
21072107
list returned by getmembers().
21082108
"""
2109+
# Convert tarinfo type to stat type.
2110+
type2mode = {REGTYPE: stat.S_IFREG, SYMTYPE: stat.S_IFLNK,
2111+
FIFOTYPE: stat.S_IFIFO, CHRTYPE: stat.S_IFCHR,
2112+
DIRTYPE: stat.S_IFDIR, BLKTYPE: stat.S_IFBLK}
21092113
self._check()
21102114

21112115
if members is None:
@@ -2115,7 +2119,8 @@ def list(self, verbose=True, *, members=None):
21152119
if tarinfo.mode is None:
21162120
_safe_print("??????????")
21172121
else:
2118-
_safe_print(stat.filemode(tarinfo.mode))
2122+
modetype = type2mode.get(tarinfo.type, 0)
2123+
_safe_print(stat.filemode(modetype | tarinfo.mode))
21192124
_safe_print("%s/%s" % (tarinfo.uname or tarinfo.uid,
21202125
tarinfo.gname or tarinfo.gid))
21212126
if tarinfo.ischr() or tarinfo.isblk():

Lib/test/clinic.test.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4956,11 +4956,16 @@ Test_meth_coexist_impl(TestObj *self)
49564956
Test.property
49574957
[clinic start generated code]*/
49584958

4959+
#if defined(Test_property_HAS_DOCSTR)
4960+
# define Test_property_DOCSTR Test_property__doc__
4961+
#else
4962+
# define Test_property_DOCSTR NULL
4963+
#endif
49594964
#if defined(TEST_PROPERTY_GETSETDEF)
49604965
# undef TEST_PROPERTY_GETSETDEF
4961-
# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, (setter)Test_property_set, NULL},
4966+
# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, (setter)Test_property_set, Test_property_DOCSTR},
49624967
#else
4963-
# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, NULL, NULL},
4968+
# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, NULL, Test_property_DOCSTR},
49644969
#endif
49654970

49664971
static PyObject *
@@ -4974,16 +4979,21 @@ Test_property_get(TestObj *self, void *Py_UNUSED(context))
49744979

49754980
static PyObject *
49764981
Test_property_get_impl(TestObj *self)
4977-
/*[clinic end generated code: output=af8140b692e0e2f1 input=2d92b3449fbc7d2b]*/
4982+
/*[clinic end generated code: output=27b519719d992e03 input=2d92b3449fbc7d2b]*/
49784983

49794984
/*[clinic input]
49804985
@setter
49814986
Test.property
49824987
[clinic start generated code]*/
49834988

4989+
#if defined(TEST_PROPERTY_HAS_DOCSTR)
4990+
# define Test_property_DOCSTR Test_property__doc__
4991+
#else
4992+
# define Test_property_DOCSTR NULL
4993+
#endif
49844994
#if defined(TEST_PROPERTY_GETSETDEF)
49854995
# undef TEST_PROPERTY_GETSETDEF
4986-
# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, (setter)Test_property_set, NULL},
4996+
# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, (setter)Test_property_set, Test_property_DOCSTR},
49874997
#else
49884998
# define TEST_PROPERTY_GETSETDEF {"property", NULL, (setter)Test_property_set, NULL},
49894999
#endif
@@ -4999,7 +5009,7 @@ Test_property_set(TestObj *self, PyObject *value, void *Py_UNUSED(context))
49995009

50005010
static int
50015011
Test_property_set_impl(TestObj *self, PyObject *value)
5002-
/*[clinic end generated code: output=f3eba6487d7550e2 input=3bc3f46a23c83a88]*/
5012+
/*[clinic end generated code: output=9797cd03c5204ddb input=3bc3f46a23c83a88]*/
50035013

50045014
/*[clinic input]
50055015
output push

Lib/test/test_clinic.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,6 +2221,21 @@ class Foo "" ""
22212221
expected_error = f"{annotation} method cannot define parameters"
22222222
self.expect_failure(block, expected_error)
22232223

2224+
def test_setter_docstring(self):
2225+
block = """
2226+
module foo
2227+
class Foo "" ""
2228+
@setter
2229+
Foo.property
2230+
2231+
foo
2232+
2233+
bar
2234+
[clinic start generated code]*/
2235+
"""
2236+
expected_error = "docstrings are only supported for @getter, not @setter"
2237+
self.expect_failure(block, expected_error)
2238+
22242239
def test_duplicate_getset(self):
22252240
annotations = ["@getter", "@setter"]
22262241
for annotation in annotations:
@@ -2249,6 +2264,17 @@ class Foo "" ""
22492264
expected_error = "Cannot apply both @getter and @setter to the same function!"
22502265
self.expect_failure(block, expected_error, lineno=3)
22512266

2267+
def test_getset_no_class(self):
2268+
for annotation in "@getter", "@setter":
2269+
with self.subTest(annotation=annotation):
2270+
block = f"""
2271+
module m
2272+
{annotation}
2273+
m.func
2274+
"""
2275+
expected_error = "@getter and @setter must be methods"
2276+
self.expect_failure(block, expected_error, lineno=2)
2277+
22522278
def test_duplicate_coexist(self):
22532279
err = "Called @coexist twice"
22542280
block = """

Lib/test/test_compile.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,10 @@ def f():
444444
self.assertIn("_A__mangled_mod", A.f.__code__.co_varnames)
445445
self.assertIn("__package__", A.f.__code__.co_varnames)
446446

447+
def test_condition_expression_with_dead_blocks_compiles(self):
448+
# See gh-113054
449+
compile('if (5 if 5 else T): 0', '<eval>', 'exec')
450+
447451
def test_compile_invalid_namedexpr(self):
448452
# gh-109351
449453
m = ast.Module(

Lib/test/test_tarfile.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,23 @@ def test_list_verbose(self):
323323
# accessories if verbose flag is being used
324324
# ...
325325
# ?rw-r--r-- tarfile/tarfile 7011 2003-01-06 07:19:43 ustar/conttype
326-
# ?rw-r--r-- tarfile/tarfile 7011 2003-01-06 07:19:43 ustar/regtype
326+
# -rw-r--r-- tarfile/tarfile 7011 2003-01-06 07:19:43 ustar/regtype
327+
# drwxr-xr-x tarfile/tarfile 0 2003-01-05 15:19:43 ustar/dirtype/
327328
# ...
328-
self.assertRegex(out, (br'\?rw-r--r-- tarfile/tarfile\s+7011 '
329-
br'\d{4}-\d\d-\d\d\s+\d\d:\d\d:\d\d '
330-
br'ustar/\w+type ?\r?\n') * 2)
329+
#
330+
# Array of values to modify the regex below:
331+
# ((file_type, file_permissions, file_length), ...)
332+
type_perm_lengths = (
333+
(br'\?', b'rw-r--r--', b'7011'), (b'-', b'rw-r--r--', b'7011'),
334+
(b'd', b'rwxr-xr-x', b'0'), (b'd', b'rwxr-xr-x', b'255'),
335+
(br'\?', b'rw-r--r--', b'0'), (b'l', b'rwxrwxrwx', b'0'),
336+
(b'b', b'rw-rw----', b'3,0'), (b'c', b'rw-rw-rw-', b'1,3'),
337+
(b'p', b'rw-r--r--', b'0'))
338+
self.assertRegex(out, b''.join(
339+
[(tp + (br'%s tarfile/tarfile\s+%s ' % (perm, ln) +
340+
br'\d{4}-\d\d-\d\d\s+\d\d:\d\d:\d\d '
341+
br'ustar/\w+type[/>\sa-z-]*\n')) for tp, perm, ln
342+
in type_perm_lengths]))
331343
# Make sure it prints the source of link with verbose flag
332344
self.assertIn(b'ustar/symtype -> regtype', out)
333345
self.assertIn(b'./ustar/linktest2/symtype -> ../linktest1/regtype', out)

Mac/BuildScript/build-installer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,9 @@ def library_recipes():
359359
),
360360
),
361361
dict(
362-
name="SQLite 3.43.1",
363-
url="https://sqlite.org/2023/sqlite-autoconf-3430100.tar.gz",
364-
checksum="77e61befe9c3298da0504f87772a24b0",
362+
name="SQLite 3.44.2",
363+
url="https://sqlite.org/2023/sqlite-autoconf-3440200.tar.gz",
364+
checksum="c02f40fd4f809ced95096250adc5764a",
365365
extra_cflags=('-Os '
366366
'-DSQLITE_ENABLE_FTS5 '
367367
'-DSQLITE_ENABLE_FTS4 '

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,7 @@ Liam Routt
15731573
Todd Rovito
15741574
Craig Rowland
15751575
Clinton Roy
1576+
Ujan RoyBandyopadhyay
15761577
Paul Rubin
15771578
Sam Ruby
15781579
Demur Rumed

Misc/NEWS.d/3.9.0a1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2069,7 +2069,7 @@ Restores instantiation of Windows IOCP event loops from the non-main thread.
20692069
.. section: Library
20702070
20712071
Add default implementation of the :meth:`ast.NodeVisitor.visit_Constant`
2072-
method which emits a deprecation warning and calls corresponding methody
2072+
method which emits a deprecation warning and calls corresponding methods
20732073
``visit_Num()``, ``visit_Str()``, etc.
20742074

20752075
..
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed bug where a redundant NOP is not removed, causing an assertion to fail
2+
in the compiler in debug mode.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed tarfile list() method to show file type.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update Windows installer to use SQLite 3.44.2.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update macOS installer to use SQLite 3.44.2.

0 commit comments

Comments
 (0)