Skip to content

Commit 2d08821

Browse files
authored
Merge branch 'main' into uuid-v7-method-1
2 parents ef85b20 + 537296c commit 2d08821

File tree

95 files changed

+1711
-1700
lines changed

Some content is hidden

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

95 files changed

+1711
-1700
lines changed

Include/internal/pycore_pystate.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,19 @@ PyAPI_FUNC(const PyConfig*) _Py_GetConfig(void);
300300
// See also PyInterpreterState_Get() and _PyInterpreterState_GET().
301301
extern PyInterpreterState* _PyGILState_GetInterpreterStateUnsafe(void);
302302

303+
#ifndef NDEBUG
304+
/* Modern equivalent of assert(PyGILState_Check()) */
305+
static inline void
306+
_Py_AssertHoldsTstateFunc(const char *func)
307+
{
308+
PyThreadState *tstate = _PyThreadState_GET();
309+
_Py_EnsureFuncTstateNotNULL(func, tstate);
310+
}
311+
#define _Py_AssertHoldsTstate() _Py_AssertHoldsTstateFunc(__func__)
312+
#else
313+
#define _Py_AssertHoldsTstate()
314+
#endif
315+
303316
#ifdef __cplusplus
304317
}
305318
#endif

Lib/test/clinic.test.c

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4758,7 +4758,7 @@ static PyObject *
47584758
Test_cls_with_param_impl(TestObj *self, PyTypeObject *cls, int a);
47594759

47604760
static PyObject *
4761-
Test_cls_with_param(TestObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4761+
Test_cls_with_param(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
47624762
{
47634763
PyObject *return_value = NULL;
47644764
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -4798,15 +4798,15 @@ Test_cls_with_param(TestObj *self, PyTypeObject *cls, PyObject *const *args, Py_
47984798
if (a == -1 && PyErr_Occurred()) {
47994799
goto exit;
48004800
}
4801-
return_value = Test_cls_with_param_impl(self, cls, a);
4801+
return_value = Test_cls_with_param_impl((TestObj *)self, cls, a);
48024802

48034803
exit:
48044804
return return_value;
48054805
}
48064806

48074807
static PyObject *
48084808
Test_cls_with_param_impl(TestObj *self, PyTypeObject *cls, int a)
4809-
/*[clinic end generated code: output=83a391eea66d08f8 input=af158077bd237ef9]*/
4809+
/*[clinic end generated code: output=7e893134a81fef92 input=af158077bd237ef9]*/
48104810

48114811

48124812
/*[clinic input]
@@ -4908,18 +4908,18 @@ static PyObject *
49084908
Test_cls_no_params_impl(TestObj *self, PyTypeObject *cls);
49094909

49104910
static PyObject *
4911-
Test_cls_no_params(TestObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4911+
Test_cls_no_params(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
49124912
{
49134913
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
49144914
PyErr_SetString(PyExc_TypeError, "cls_no_params() takes no arguments");
49154915
return NULL;
49164916
}
4917-
return Test_cls_no_params_impl(self, cls);
4917+
return Test_cls_no_params_impl((TestObj *)self, cls);
49184918
}
49194919

49204920
static PyObject *
49214921
Test_cls_no_params_impl(TestObj *self, PyTypeObject *cls)
4922-
/*[clinic end generated code: output=4d68b4652c144af3 input=e7e2e4e344e96a11]*/
4922+
/*[clinic end generated code: output=8845de054449f40a input=e7e2e4e344e96a11]*/
49234923

49244924

49254925
/*[clinic input]
@@ -4945,7 +4945,7 @@ Test_metho_not_default_return_converter(TestObj *self, PyObject *a)
49454945
PyObject *return_value = NULL;
49464946
int _return_value;
49474947

4948-
_return_value = Test_metho_not_default_return_converter_impl(self, a);
4948+
_return_value = Test_metho_not_default_return_converter_impl((TestObj *)self, a);
49494949
if ((_return_value == -1) && PyErr_Occurred()) {
49504950
goto exit;
49514951
}
@@ -4957,7 +4957,7 @@ Test_metho_not_default_return_converter(TestObj *self, PyObject *a)
49574957

49584958
static int
49594959
Test_metho_not_default_return_converter_impl(TestObj *self, PyObject *a)
4960-
/*[clinic end generated code: output=3350de11bd538007 input=428657129b521177]*/
4960+
/*[clinic end generated code: output=b2cce75a7af2e6ce input=428657129b521177]*/
49614961

49624962

49634963
/*[clinic input]
@@ -4983,7 +4983,7 @@ static PyObject *
49834983
Test_an_metho_arg_named_arg_impl(TestObj *self, int arg);
49844984

49854985
static PyObject *
4986-
Test_an_metho_arg_named_arg(TestObj *self, PyObject *arg_)
4986+
Test_an_metho_arg_named_arg(PyObject *self, PyObject *arg_)
49874987
{
49884988
PyObject *return_value = NULL;
49894989
int arg;
@@ -4992,15 +4992,15 @@ Test_an_metho_arg_named_arg(TestObj *self, PyObject *arg_)
49924992
if (arg == -1 && PyErr_Occurred()) {
49934993
goto exit;
49944994
}
4995-
return_value = Test_an_metho_arg_named_arg_impl(self, arg);
4995+
return_value = Test_an_metho_arg_named_arg_impl((TestObj *)self, arg);
49964996

49974997
exit:
49984998
return return_value;
49994999
}
50005000

50015001
static PyObject *
50025002
Test_an_metho_arg_named_arg_impl(TestObj *self, int arg)
5003-
/*[clinic end generated code: output=9f04de4a62287e28 input=2a53a57cf5624f95]*/
5003+
/*[clinic end generated code: output=38554f09950d07e7 input=2a53a57cf5624f95]*/
50045004

50055005

50065006
/*[clinic input]
@@ -5289,14 +5289,14 @@ static PyObject *
52895289
Test_meth_coexist_impl(TestObj *self);
52905290

52915291
static PyObject *
5292-
Test_meth_coexist(TestObj *self, PyObject *Py_UNUSED(ignored))
5292+
Test_meth_coexist(PyObject *self, PyObject *Py_UNUSED(ignored))
52935293
{
5294-
return Test_meth_coexist_impl(self);
5294+
return Test_meth_coexist_impl((TestObj *)self);
52955295
}
52965296

52975297
static PyObject *
52985298
Test_meth_coexist_impl(TestObj *self)
5299-
/*[clinic end generated code: output=808a293d0cd27439 input=2a1d75b5e6fec6dd]*/
5299+
/*[clinic end generated code: output=7edf4e95b29f06fa input=2a1d75b5e6fec6dd]*/
53005300

53015301
/*[clinic input]
53025302
@getter
@@ -5317,14 +5317,14 @@ static PyObject *
53175317
Test_property_get_impl(TestObj *self);
53185318

53195319
static PyObject *
5320-
Test_property_get(TestObj *self, void *Py_UNUSED(context))
5320+
Test_property_get(PyObject *self, void *Py_UNUSED(context))
53215321
{
5322-
return Test_property_get_impl(self);
5322+
return Test_property_get_impl((TestObj *)self);
53235323
}
53245324

53255325
static PyObject *
53265326
Test_property_get_impl(TestObj *self)
5327-
/*[clinic end generated code: output=7cadd0f539805266 input=2d92b3449fbc7d2b]*/
5327+
/*[clinic end generated code: output=b38d68abd3466a6e input=2d92b3449fbc7d2b]*/
53285328

53295329
/*[clinic input]
53305330
@setter
@@ -5345,18 +5345,18 @@ static int
53455345
Test_property_set_impl(TestObj *self, PyObject *value);
53465346

53475347
static int
5348-
Test_property_set(TestObj *self, PyObject *value, void *Py_UNUSED(context))
5348+
Test_property_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
53495349
{
53505350
int return_value;
53515351

5352-
return_value = Test_property_set_impl(self, value);
5352+
return_value = Test_property_set_impl((TestObj *)self, value);
53535353

53545354
return return_value;
53555355
}
53565356

53575357
static int
53585358
Test_property_set_impl(TestObj *self, PyObject *value)
5359-
/*[clinic end generated code: output=e4342fe9bb1d7817 input=3bc3f46a23c83a88]*/
5359+
/*[clinic end generated code: output=49f925ab2a33b637 input=3bc3f46a23c83a88]*/
53605360

53615361
/*[clinic input]
53625362
@setter
@@ -5377,18 +5377,18 @@ static int
53775377
Test_setter_first_with_docstr_set_impl(TestObj *self, PyObject *value);
53785378

53795379
static int
5380-
Test_setter_first_with_docstr_set(TestObj *self, PyObject *value, void *Py_UNUSED(context))
5380+
Test_setter_first_with_docstr_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
53815381
{
53825382
int return_value;
53835383

5384-
return_value = Test_setter_first_with_docstr_set_impl(self, value);
5384+
return_value = Test_setter_first_with_docstr_set_impl((TestObj *)self, value);
53855385

53865386
return return_value;
53875387
}
53885388

53895389
static int
53905390
Test_setter_first_with_docstr_set_impl(TestObj *self, PyObject *value)
5391-
/*[clinic end generated code: output=e4d76b558a4061db input=31a045ce11bbe961]*/
5391+
/*[clinic end generated code: output=5aaf44373c0af545 input=31a045ce11bbe961]*/
53925392

53935393
/*[clinic input]
53945394
@getter
@@ -5418,14 +5418,14 @@ static PyObject *
54185418
Test_setter_first_with_docstr_get_impl(TestObj *self);
54195419

54205420
static PyObject *
5421-
Test_setter_first_with_docstr_get(TestObj *self, void *Py_UNUSED(context))
5421+
Test_setter_first_with_docstr_get(PyObject *self, void *Py_UNUSED(context))
54225422
{
5423-
return Test_setter_first_with_docstr_get_impl(self);
5423+
return Test_setter_first_with_docstr_get_impl((TestObj *)self);
54245424
}
54255425

54265426
static PyObject *
54275427
Test_setter_first_with_docstr_get_impl(TestObj *self)
5428-
/*[clinic end generated code: output=749a30266f9fb443 input=10af4e43b3cb34dc]*/
5428+
/*[clinic end generated code: output=fe6e3aa844a24920 input=10af4e43b3cb34dc]*/
54295429

54305430
/*[clinic input]
54315431
output push
@@ -5708,7 +5708,7 @@ Test__pyarg_parsestackandkeywords_impl(TestObj *self, PyTypeObject *cls,
57085708
Py_ssize_t key_length);
57095709

57105710
static PyObject *
5711-
Test__pyarg_parsestackandkeywords(TestObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5711+
Test__pyarg_parsestackandkeywords(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
57125712
{
57135713
PyObject *return_value = NULL;
57145714
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -5731,7 +5731,7 @@ Test__pyarg_parsestackandkeywords(TestObj *self, PyTypeObject *cls, PyObject *co
57315731
&key, &key_length)) {
57325732
goto exit;
57335733
}
5734-
return_value = Test__pyarg_parsestackandkeywords_impl(self, cls, key, key_length);
5734+
return_value = Test__pyarg_parsestackandkeywords_impl((TestObj *)self, cls, key, key_length);
57355735

57365736
exit:
57375737
return return_value;
@@ -5741,7 +5741,7 @@ static PyObject *
57415741
Test__pyarg_parsestackandkeywords_impl(TestObj *self, PyTypeObject *cls,
57425742
const char *key,
57435743
Py_ssize_t key_length)
5744-
/*[clinic end generated code: output=4fda8a7f2547137c input=fc72ef4b4cfafabc]*/
5744+
/*[clinic end generated code: output=7060c213d7b8200e input=fc72ef4b4cfafabc]*/
57455745

57465746

57475747
/*[clinic input]

Lib/test/test_asyncio/test_base_events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,7 @@ def getaddrinfo_task(*args, **kwds):
13451345
with self.assertRaises(OSError) as cm:
13461346
self.loop.run_until_complete(coro)
13471347

1348-
self.assertTrue(str(cm.exception).startswith('Multiple exceptions: '))
1348+
self.assertStartsWith(str(cm.exception), 'Multiple exceptions: ')
13491349
self.assertTrue(m_socket.socket.return_value.close.called)
13501350

13511351
coro = self.loop.create_connection(

Lib/test/test_asyncio/test_events.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,7 +2184,7 @@ def test_subprocess_stderr(self):
21842184

21852185
transp.close()
21862186
self.assertEqual(b'OUT:test', proto.data[1])
2187-
self.assertTrue(proto.data[2].startswith(b'ERR:test'), proto.data[2])
2187+
self.assertStartsWith(proto.data[2], b'ERR:test')
21882188
self.assertEqual(0, proto.returncode)
21892189

21902190
@support.requires_subprocess()
@@ -2206,8 +2206,7 @@ def test_subprocess_stderr_redirect_to_stdout(self):
22062206

22072207
stdin.write(b'test')
22082208
self.loop.run_until_complete(proto.completed)
2209-
self.assertTrue(proto.data[1].startswith(b'OUT:testERR:test'),
2210-
proto.data[1])
2209+
self.assertStartsWith(proto.data[1], b'OUT:testERR:test')
22112210
self.assertEqual(b'', proto.data[2])
22122211

22132212
transp.close()

Lib/test/test_asyncio/test_futures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def test_uninitialized(self):
242242

243243
def test_future_cancel_message_getter(self):
244244
f = self._new_future(loop=self.loop)
245-
self.assertTrue(hasattr(f, '_cancel_message'))
245+
self.assertHasAttr(f, '_cancel_message')
246246
self.assertEqual(f._cancel_message, None)
247247

248248
f.cancel('my message')

Lib/test/test_asyncio/test_locks.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ class LockTests(unittest.IsolatedAsyncioTestCase):
2727

2828
async def test_repr(self):
2929
lock = asyncio.Lock()
30-
self.assertTrue(repr(lock).endswith('[unlocked]>'))
30+
self.assertEndsWith(repr(lock), '[unlocked]>')
3131
self.assertTrue(RGX_REPR.match(repr(lock)))
3232

3333
await lock.acquire()
34-
self.assertTrue(repr(lock).endswith('[locked]>'))
34+
self.assertEndsWith(repr(lock), '[locked]>')
3535
self.assertTrue(RGX_REPR.match(repr(lock)))
3636

3737
async def test_lock(self):
@@ -286,12 +286,12 @@ class EventTests(unittest.IsolatedAsyncioTestCase):
286286

287287
def test_repr(self):
288288
ev = asyncio.Event()
289-
self.assertTrue(repr(ev).endswith('[unset]>'))
289+
self.assertEndsWith(repr(ev), '[unset]>')
290290
match = RGX_REPR.match(repr(ev))
291291
self.assertEqual(match.group('extras'), 'unset')
292292

293293
ev.set()
294-
self.assertTrue(repr(ev).endswith('[set]>'))
294+
self.assertEndsWith(repr(ev), '[set]>')
295295
self.assertTrue(RGX_REPR.match(repr(ev)))
296296

297297
ev._waiters.append(mock.Mock())
@@ -916,11 +916,11 @@ def test_initial_value_zero(self):
916916

917917
async def test_repr(self):
918918
sem = asyncio.Semaphore()
919-
self.assertTrue(repr(sem).endswith('[unlocked, value:1]>'))
919+
self.assertEndsWith(repr(sem), '[unlocked, value:1]>')
920920
self.assertTrue(RGX_REPR.match(repr(sem)))
921921

922922
await sem.acquire()
923-
self.assertTrue(repr(sem).endswith('[locked]>'))
923+
self.assertEndsWith(repr(sem), '[locked]>')
924924
self.assertTrue('waiters' not in repr(sem))
925925
self.assertTrue(RGX_REPR.match(repr(sem)))
926926

Lib/test/test_asyncio/test_protocols.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_base_protocol(self):
1919
self.assertIsNone(p.connection_lost(f))
2020
self.assertIsNone(p.pause_writing())
2121
self.assertIsNone(p.resume_writing())
22-
self.assertFalse(hasattr(p, '__dict__'))
22+
self.assertNotHasAttr(p, '__dict__')
2323

2424
def test_protocol(self):
2525
f = mock.Mock()
@@ -30,7 +30,7 @@ def test_protocol(self):
3030
self.assertIsNone(p.eof_received())
3131
self.assertIsNone(p.pause_writing())
3232
self.assertIsNone(p.resume_writing())
33-
self.assertFalse(hasattr(p, '__dict__'))
33+
self.assertNotHasAttr(p, '__dict__')
3434

3535
def test_buffered_protocol(self):
3636
f = mock.Mock()
@@ -41,7 +41,7 @@ def test_buffered_protocol(self):
4141
self.assertIsNone(p.buffer_updated(150))
4242
self.assertIsNone(p.pause_writing())
4343
self.assertIsNone(p.resume_writing())
44-
self.assertFalse(hasattr(p, '__dict__'))
44+
self.assertNotHasAttr(p, '__dict__')
4545

4646
def test_datagram_protocol(self):
4747
f = mock.Mock()
@@ -50,7 +50,7 @@ def test_datagram_protocol(self):
5050
self.assertIsNone(dp.connection_lost(f))
5151
self.assertIsNone(dp.error_received(f))
5252
self.assertIsNone(dp.datagram_received(f, f))
53-
self.assertFalse(hasattr(dp, '__dict__'))
53+
self.assertNotHasAttr(dp, '__dict__')
5454

5555
def test_subprocess_protocol(self):
5656
f = mock.Mock()
@@ -60,7 +60,7 @@ def test_subprocess_protocol(self):
6060
self.assertIsNone(sp.pipe_data_received(1, f))
6161
self.assertIsNone(sp.pipe_connection_lost(1, f))
6262
self.assertIsNone(sp.process_exited())
63-
self.assertFalse(hasattr(sp, '__dict__'))
63+
self.assertNotHasAttr(sp, '__dict__')
6464

6565

6666
if __name__ == '__main__':

Lib/test/test_asyncio/test_queues.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async def _test_repr_or_str(self, fn, expect_id):
1818
appear in fn(Queue()).
1919
"""
2020
q = asyncio.Queue()
21-
self.assertTrue(fn(q).startswith('<Queue'), fn(q))
21+
self.assertStartsWith(fn(q), '<Queue')
2222
id_is_present = hex(id(q)) in fn(q)
2323
self.assertEqual(expect_id, id_is_present)
2424

0 commit comments

Comments
 (0)