Merge branch 'main' into target-generator · python/cpython@b609279 · GitHub
Skip to content

Commit b609279

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

28 files changed

Lines changed: 399 additions & 114 deletions

Doc/library/ast.rst

Lines changed: 19 additions & 16 deletions

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

0 commit comments

Comments
 (0)