Skip to content

Commit 1393f2d

Browse files
committed
Fix for python 3.12+
1 parent 4afe4ea commit 1393f2d

7 files changed

Lines changed: 43 additions & 16 deletions

File tree

.github/workflows/python-publish.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
runs-on: ubuntu-latest
2323
strategy:
2424
matrix:
25-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
25+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
2626

2727
steps:
2828
- uses: actions/checkout@v3
@@ -52,7 +52,7 @@ jobs:
5252
runs-on: windows-2019
5353
strategy:
5454
matrix:
55-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
55+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
5656

5757
steps:
5858
- uses: actions/checkout@v3
@@ -82,7 +82,7 @@ jobs:
8282
runs-on: macos-11
8383
strategy:
8484
matrix:
85-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
85+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
8686

8787
steps:
8888
- uses: actions/checkout@v3

.github/workflows/python-test-linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
18+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
1919

2020
steps:
2121
- uses: actions/checkout@v3

.github/workflows/python-test-macos.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
18+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
1919

2020
steps:
2121
- uses: actions/checkout@v3

.github/workflows/python-test-windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
18+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
1919

2020
steps:
2121
- uses: actions/checkout@v3

pyproject.toml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
[build-system]
2-
requires = [
3-
# mesonpy, version 0.13.0 which isn't released yet
4-
"meson-python @ git+https://github.com/mesonbuild/meson-python.git@61bb2b3315f4e312558778022ca6e87ffaed2700",
5-
]
6-
build-backend = 'mesonpy'
2+
build-backend = "mesonpy"
3+
requires = ["meson-python"]
74

85
[project]
96
name = "extype"
@@ -19,3 +16,11 @@ dynamic = ["version"]
1916
[tool.cibuildwheel]
2017
skip = "pp*"
2118
build-frontend = "build"
19+
20+
[dependency-groups]
21+
dev = [
22+
"meson>=1.10.1",
23+
"meson-python>=0.17.1",
24+
"ninja>=1.11.1.4",
25+
]
26+
test = ["pytest>=7.4.4", "typing-extensions>=4.7.1"]

src/extype/core.pyi

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
from typing import Type, Dict, Any
2-
from . import Protocol
1+
from typing import Type, Dict, Any, TYPE_CHECKING
32

3+
if TYPE_CHECKING:
4+
from .extension_utils import Protocol
45

56
def get_type_dict(typ: Type) -> Dict[str, Any]: ...
67

78

8-
def implement_protocol_on_type(typ: Type, protocols: Protocol): ...
9+
def implement_protocol_on_type(typ: Type, protocols: "Protocol"): ...
910

1011

1112
def enable_magic_method(typ: Type, method: str): ...
13+
14+
15+
if TYPE_CHECKING:
16+
del Protocol

src/extype/extype.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,24 @@ static PyObject *get_type_dict(PyObject *self, PyObject *args)
275275
PyTypeObject *type;
276276
PyArg_ParseTuple(args, "O", &type);
277277

278-
Py_INCREF(type->tp_dict);
279-
return type->tp_dict;
278+
#if PY_VERSION_HEX >= 0x030C0000
279+
280+
auto dict = PyType_GetDict(type);
281+
282+
#else
283+
284+
auto dict = type->tp_dict;
285+
286+
#endif
287+
288+
if (dict == NULL)
289+
{
290+
PyErr_SetString(PyExc_RuntimeError, "type dict was null");
291+
return NULL;
292+
}
293+
294+
Py_INCREF(dict);
295+
return dict;
280296
}
281297

282298
static MagicMethodLookupResult get_magic_method_slot(PyTypeObject *type, char const *name_str)
@@ -563,6 +579,7 @@ static PyObject *enable_magic_method(PyObject *self, PyObject *args)
563579

564580
if (slot == NULL)
565581
{
582+
PyErr_SetString(PyExc_RuntimeError, "slot was null");
566583
PyErr_SetString(PyExc_RuntimeError, "slot was null");
567584
return NULL;
568585
}

0 commit comments

Comments
 (0)