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
9 changes: 5 additions & 4 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]

steps:
- uses: actions/checkout@v3
Expand All @@ -38,6 +38,7 @@ jobs:
# if: github.event.inputs.build == 'true'
# run: python -m build --wheel --sdist --outdir dist/
env:
# Also builds the free-threaded (cp3XXt) wheels for versions that support them
CIBW_PROJECT_REQUIRES_PYTHON: ==${{ matrix.python-version }}.*
run: python -m cibuildwheel --output-dir dist/
- name: Upload Artifact
Expand All @@ -49,10 +50,10 @@ jobs:
windows:
name: Build for Windows

runs-on: windows-2019
runs-on: windows-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "3.14t"]

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -82,7 +83,7 @@ jobs:
runs-on: macos-15-intel
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "3.14t"]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.14t"]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-test-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.14t"]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "3.14t"]

steps:
- uses: actions/checkout@v3
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ Only methods marked with `@extension` will be added as extension methods.
Extending a type will extend it in all modules, not just the one that called the `extend_type_with`,
so make sure you don't override an existing function, unless, of course, it is what you want.

### Free-threaded Python
ExType supports the free-threaded build of Python (3.14t and later) and does not re-enable the GIL when imported.
Extending a type is thread-safe, but other threads that are using the type at the same time may see either
the old or the new behavior until `extend_type_with` returns. It is recommended to apply your extensions
at import time, before starting other threads.


## Features
- [x] Exteranlly extend type via another type
Expand Down
3 changes: 3 additions & 0 deletions src/extype/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ if TYPE_CHECKING:
def get_type_dict(typ: Type) -> Dict[str, Any]: ...


def set_type_attribute(typ: Type, name: str, value: Any) -> None: ...


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


Expand Down
10 changes: 4 additions & 6 deletions src/extype/extension_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import IntFlag
from typing import Generic, TypeVar
from .core import enable_magic_method, get_type_dict
from .core import enable_magic_method, set_type_attribute


_T = TypeVar("_T")
Expand All @@ -24,8 +24,6 @@ def extend_type_with(typ, cls, recurse_parents=True):
if not isinstance(typ, type):
raise TypeError(f"argument 'typ' must be a valid type, got {type(typ)}")

type_dict = get_type_dict(typ)

if recurse_parents:
for base in cls.__bases__:
extend_type_with(typ, base)
Expand All @@ -36,13 +34,15 @@ def extend_type_with(typ, cls, recurse_parents=True):
item = item.original
if callable(getattr(item, "__set_name__", None)):
item.__set_name__(typ, name)
# Set the attribute before enabling the slot, so the slot
# never runs without a method to call.
set_type_attribute(typ, name, item)
if callable(item):
if name.startswith("__") and name.endswith("__"):
try:
enable_magic_method(typ, name)
except ValueError:
...
type_dict[name] = item


class ExtensionObject(Generic[_T]):
Expand All @@ -59,8 +59,6 @@ def extension(o: _T) -> _T:
raise TypeError("Only functions and descriptors may be marked as extensions")


del _T

__all__ = [
"extension",
"extend_type_with"
Expand Down
Loading
Loading