Skip to content

Commit d6b7e56

Browse files
author
Paweł Andruszkiewicz
committed
Fix compilation with Python 3.13
Change-Id: I1f0b13d9a2136e8d691639eafef3bea99772c52b
1 parent 7f19c0a commit d6b7e56

File tree

6 files changed

+74
-9
lines changed

6 files changed

+74
-9
lines changed

mysqlshdk/scripting/python_array_wrapper.cc

+31-1
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,10 @@ static PyTypeObject Array_object_type = {
293293
,
294294
0 // tp_watched
295295
#endif
296+
#if PY_VERSION_HEX >= 0x030D0000
297+
,
298+
0 // tp_versions_used
299+
#endif
296300
};
297301

298302
#if PY_VERSION_HEX >= 0x03080000 && PY_VERSION_HEX < 0x03090000
@@ -462,6 +466,10 @@ static PyTypeObject Array_object_iterator_type = {
462466
,
463467
0 // tp_watched
464468
#endif
469+
#if PY_VERSION_HEX >= 0x030D0000
470+
,
471+
0 // tp_versions_used
472+
#endif
465473
};
466474

467475
#if PY_VERSION_HEX >= 0x03080000 && PY_VERSION_HEX < 0x03090000
@@ -614,6 +622,10 @@ static PyTypeObject Array_object_reverse_iterator_type = {
614622
,
615623
0 // tp_watched
616624
#endif
625+
#if PY_VERSION_HEX >= 0x030D0000
626+
,
627+
0 // tp_versions_used
628+
#endif
617629
};
618630

619631
#if PY_VERSION_HEX >= 0x03080000 && PY_VERSION_HEX < 0x03090000
@@ -1540,7 +1552,25 @@ int ao_init(Array_object *self, PyObject *args, PyObject *kw) {
15401552
return -1;
15411553
}
15421554

1543-
if (!_PyArg_NoKeywords("List", kw)) {
1555+
static constexpr auto expect_no_keywords = [](PyObject *kwargs) {
1556+
if (!kwargs) {
1557+
return true;
1558+
}
1559+
1560+
if (!PyDict_CheckExact(kwargs)) {
1561+
PyErr_BadInternalCall();
1562+
return false;
1563+
}
1564+
1565+
if (0 == PyDict_GET_SIZE(kwargs)) {
1566+
return true;
1567+
}
1568+
1569+
PyErr_SetString(PyExc_TypeError, "List() takes no keyword arguments");
1570+
return false;
1571+
};
1572+
1573+
if (!expect_no_keywords(kw)) {
15441574
return -1;
15451575
}
15461576

mysqlshdk/scripting/python_function_wrapper.cc

+4
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ PyTypeObject PyShFuncObjectType = {
197197
,
198198
0 // tp_watched
199199
#endif
200+
#if PY_VERSION_HEX >= 0x030D0000
201+
,
202+
0 // tp_versions_used
203+
#endif
200204
};
201205

202206
#if PY_VERSION_HEX >= 0x03080000 && PY_VERSION_HEX < 0x03090000

mysqlshdk/scripting/python_map_wrapper.cc

+19-1
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ using Reverse_iterator = Iterator_base<Map_reverse_iterator>;
7272
////////////////////////////////////////////////////////////////////////////////
7373

7474
struct View {
75-
_PyDictViewObject base;
75+
// clang-format off
76+
PyObject_HEAD
7677
py::Store o;
78+
// clang-format on
7779
};
7880

7981
////////////////////////////////////////////////////////////////////////////////
@@ -380,6 +382,10 @@ PyTypeObject Type = {
380382
,
381383
0 // tp_watched
382384
#endif
385+
#if PY_VERSION_HEX >= 0x030D0000
386+
,
387+
0 // tp_versions_used
388+
#endif
383389
};
384390

385391
#if PY_VERSION_HEX >= 0x03080000 && PY_VERSION_HEX < 0x03090000
@@ -866,6 +872,10 @@ PyTypeObject Type = {
866872
,
867873
0 // tp_watched
868874
#endif
875+
#if PY_VERSION_HEX >= 0x030D0000
876+
,
877+
0 // tp_versions_used
878+
#endif
869879
};
870880

871881
#if PY_VERSION_HEX >= 0x03080000 && PY_VERSION_HEX < 0x03090000
@@ -1059,6 +1069,10 @@ PyTypeObject Type = {
10591069
,
10601070
0 // tp_watched
10611071
#endif
1072+
#if PY_VERSION_HEX >= 0x030D0000
1073+
,
1074+
0 // tp_versions_used
1075+
#endif
10621076
};
10631077

10641078
#if PY_VERSION_HEX >= 0x03080000 && PY_VERSION_HEX < 0x03090000
@@ -1255,6 +1269,10 @@ PyTypeObject Type = {
12551269
,
12561270
0 // tp_watched
12571271
#endif
1272+
#if PY_VERSION_HEX >= 0x030D0000
1273+
,
1274+
0 // tp_versions_used
1275+
#endif
12581276
};
12591277

12601278
#if PY_VERSION_HEX >= 0x03080000 && PY_VERSION_HEX < 0x03090000

mysqlshdk/scripting/python_object_wrapper.cc

+12
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@ PyTypeObject PyShMethodObjectType = {
288288
,
289289
0 // tp_watched
290290
#endif
291+
#if PY_VERSION_HEX >= 0x030D0000
292+
,
293+
0 // tp_versions_used
294+
#endif
291295
};
292296

293297
#if PY_VERSION_HEX >= 0x03080000 && PY_VERSION_HEX < 0x03090000
@@ -732,6 +736,10 @@ PyTypeObject PyShObjObjectType = {
732736
,
733737
0 // tp_watched
734738
#endif
739+
#if PY_VERSION_HEX >= 0x030D0000
740+
,
741+
0 // tp_versions_used
742+
#endif
735743
};
736744

737745
PyTypeObject PyShObjIndexedObjectType = {
@@ -831,6 +839,10 @@ PyTypeObject PyShObjIndexedObjectType = {
831839
,
832840
0 // tp_watched
833841
#endif
842+
#if PY_VERSION_HEX >= 0x030D0000
843+
,
844+
0 // tp_versions_used
845+
#endif
834846
};
835847

836848
#if PY_VERSION_HEX >= 0x03080000 && PY_VERSION_HEX < 0x03090000

unittest/scripts/auto/py_shell/scripts/dict_norecord.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ def assign_none_to_mapping():
660660

661661
#@<> __subclasshook__
662662
# __subclasshook__ comes from the object class
663-
EXPECT_EQ(NotImplemented, shdict.__subclasshook__())
663+
EXPECT_EQ(NotImplemented, shdict.__subclasshook__(None))
664664

665665
#@<> clear
666666
SETUP("clear")
@@ -1345,7 +1345,7 @@ def assign_none_to_mapping():
13451345
#@<> items - __subclasshook__
13461346
SETUP_VIEW("items", "__subclasshook__")
13471347
# __subclasshook__ comes from the object class
1348-
EXPECT_EQ(NotImplemented, actual.__class__.__subclasshook__())
1348+
EXPECT_EQ(NotImplemented, actual.__class__.__subclasshook__(None))
13491349

13501350
#@<> items - __xor__
13511351
SETUP_VIEW("items", "__xor__")
@@ -2005,7 +2005,7 @@ def assign_none_to_mapping():
20052005
#@<> keys - __subclasshook__
20062006
SETUP_VIEW("keys", "__subclasshook__")
20072007
# __subclasshook__ comes from the object class
2008-
EXPECT_EQ(NotImplemented, actual.__class__.__subclasshook__())
2008+
EXPECT_EQ(NotImplemented, actual.__class__.__subclasshook__(None))
20092009

20102010
#@<> keys - __xor__
20112011
SETUP_VIEW("keys", "__xor__")
@@ -2481,7 +2481,7 @@ def assign_none_to_mapping():
24812481
#@<> values - __subclasshook__
24822482
SETUP_VIEW("values", "__subclasshook__")
24832483
# __subclasshook__ comes from the object class
2484-
EXPECT_EQ(NotImplemented, actual.__class__.__subclasshook__())
2484+
EXPECT_EQ(NotImplemented, actual.__class__.__subclasshook__(None))
24852485

24862486
#@<> values - mapping {sys.hexversion >= 0x030A0000}
24872487
SETUP_VIEW("values", "mapping")

unittest/scripts/auto/py_shell/scripts/list_norecord.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,9 @@ def TEST_OP_LIST_ARG(*args, **kwargs):
693693
SETUP("__setitem__", range(11))
694694

695695
## exceptions
696-
# can only assign an iterable
697-
TEST(slice(2, 7), 7)
696+
# can only assign an iterable, Python 3.13+ reports must assign iterable to extended slice instead
697+
if sys.hexversion < 0x030d0000:
698+
TEST(slice(2, 7), 7)
698699
# must assign iterable to extended slice
699700
TEST(slice(2, 7, 2), 7)
700701
# attempt to assign sequence of size %zd to extended slice of size %zd
@@ -750,7 +751,7 @@ def TEST_OP_LIST_ARG(*args, **kwargs):
750751

751752
#@<> __subclasshook__
752753
# __subclasshook__ comes from the object class
753-
EXPECT_EQ(NotImplemented, shlist.__subclasshook__())
754+
EXPECT_EQ(NotImplemented, shlist.__subclasshook__(None))
754755

755756
#@<> append
756757
SETUP("append")

0 commit comments

Comments
 (0)