Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ permissions:
jobs:
linux:
name: Build for Linux
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -52,12 +52,12 @@ jobs:
runs-on: windows-2019
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -82,12 +82,12 @@ jobs:
runs-on: macos-11
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
36 changes: 34 additions & 2 deletions .github/workflows/python-test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,49 @@ on:
branches: [ "main" ]

jobs:
build-legacy:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest build
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Build package
run: |
python -m build
pip install dist/*.whl
- name: Test with pytest
run: |
python -m pip install typing-extensions
pytest

build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
36 changes: 34 additions & 2 deletions .github/workflows/python-test-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,49 @@ on:
branches: [ "main" ]

jobs:
build-legacy:
runs-on: macos-15-intel
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest build
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Build package
run: |
python -m build
pip install dist/*.whl
- name: Test with pytest
run: |
python -m pip install typing-extensions
pytest

build:
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python-test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
15 changes: 10 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[build-system]
requires = [
# mesonpy, version 0.13.0 which isn't released yet
"meson-python @ git+https://github.com/mesonbuild/meson-python.git@61bb2b3315f4e312558778022ca6e87ffaed2700",
]
build-backend = 'mesonpy'
build-backend = "mesonpy"
requires = ["meson-python"]

[project]
name = "extype"
Expand All @@ -19,3 +16,11 @@ dynamic = ["version"]
[tool.cibuildwheel]
skip = "pp*"
build-frontend = "build"

[dependency-groups]
dev = [
"meson>=1.10.1",
"meson-python>=0.17.1",
"ninja>=1.11.1.4",
]
test = ["pytest>=7.4.4", "typing-extensions>=4.7.1"]
11 changes: 8 additions & 3 deletions src/extype/core.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from typing import Type, Dict, Any
from . import Protocol
from typing import Type, Dict, Any, TYPE_CHECKING

if TYPE_CHECKING:
from .extension_utils import Protocol

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


def implement_protocol_on_type(typ: Type, protocols: Protocol): ...
def implement_protocol_on_type(typ: Type, protocols: "Protocol"): ...


def enable_magic_method(typ: Type, method: str): ...


if TYPE_CHECKING:
del Protocol
21 changes: 19 additions & 2 deletions src/extype/extype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,24 @@ static PyObject *get_type_dict(PyObject *self, PyObject *args)
PyTypeObject *type;
PyArg_ParseTuple(args, "O", &type);

Py_INCREF(type->tp_dict);
return type->tp_dict;
#if PY_VERSION_HEX >= 0x030C0000

auto dict = PyType_GetDict(type);

#else

auto dict = type->tp_dict;

#endif

if (dict == NULL)
{
PyErr_SetString(PyExc_RuntimeError, "type dict was null");
return NULL;
}

Py_INCREF(dict);
return dict;
}

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

if (slot == NULL)
{
PyErr_SetString(PyExc_RuntimeError, "slot was null");
PyErr_SetString(PyExc_RuntimeError, "slot was null");
return NULL;
}
Expand Down
3 changes: 2 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from extype.core import *
from extype import extension, extend_type_with, Protocol
from extype.extension_utils import Protocol
from extype import extension, extend_type_with


def _():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_protocol_detection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from extype import *
from extype import extension, extend_type_with


def test_length_function():
Expand Down
Loading