Skip to content

PyOZ v0.7.0

Choose a tag to compare

@github-actions github-actions released this 06 Feb 10:09
· 69 commits to main since this release
f818508

What's New in v0.7.0

Added

  • Complete Python exception hierarchy - Added all missing exception types from the CPython hierarchy, covering every exception from BaseException down through all subclasses including NameError, UnboundLocalError, ReferenceError, SyntaxError, IndentationError, TabError, StopAsyncIteration, and all 11 Warning types (Warning, DeprecationWarning, UserWarning, RuntimeWarning, etc.)
  • Ergonomic raise functions returning Null - All raise* functions now return @TypeOf(null) (aliased as Null), enabling one-liner error returns: return pyoz.raiseValueError("bad input"). The null literal coerces to any optional type (?*PyObject, ?i64, ?f64, etc.)
  • 21 new raise functions - raiseAssertionError, raiseFloatingPointError, raiseLookupError, raiseNameError, raiseUnboundLocalError, raiseReferenceError, raiseStopAsyncIteration, raiseSyntaxError, raiseUnicodeError, raiseModuleNotFoundError, raiseBlockingIOError, raiseBrokenPipeError, raiseChildProcessError, raiseConnectionAbortedError, raiseConnectionRefusedError, raiseConnectionResetError, raiseFileExistsError, raiseInterruptedError, raiseIsADirectoryError, raiseNotADirectoryError, raiseProcessLookupError
  • 17 new PythonException.is* methods - isMemoryError, isOSError, isNotImplementedError, isOverflowError, isFileNotFoundError, isPermissionError, isTimeoutError, isConnectionError, isEOFError, isImportError, isNameError, isSyntaxError, isRecursionError, isArithmeticError, isBufferError, isSystemError, isUnicodeError
  • ExcBase enum expanded to 60+ variants - Users can now use any standard Python exception as a base for custom exceptions via pyoz.exception("MyError", .SyntaxError) or any other variant
  • PyExc struct covers the full hierarchy - Programmatic access to every built-in Python exception type
  • __del__ hook for custom cleanup - Structs can now define pub fn __del__(self: *Self) void which PyOZ calls during tp_dealloc before freeing the Python object. This allows releasing C memory, closing file handles, invalidating resources, etc. Works in both normal and ABI3 modes with zero runtime cost for types that don't define it.
  • Callable(ReturnType) wrapper for Python callbacks - Type-safe wrapper for accepting and invoking Python callables from Zig. Handles automatic argument marshalling (Zig→Python conversion), result conversion (Python→Zig), full refcounting, and exception propagation. Supports any number of arguments via .call(.{args}), a .callNoArgs() shortcut, and Callable(void) for callbacks with no return value. Works in ABI3 mode.
  • __class_getitem__ support (PEP 560) - Structs can declare pub const __class_getitem__ = true; to enable MyClass[int] generic type syntax. Returns types.GenericAlias on Python 3.9+, falls back gracefully on 3.8. Works in ABI3 mode.
  • allowThreads / allowThreadsTry - Ergonomic GIL release wrappers. Call any function without the GIL in one line: pyoz.allowThreads(compute, .{data}). allowThreadsTry supports error-returning functions with defer-based GIL restoration.
  • Freelist / Object Pooling - Structs can declare pub const __freelist__: usize = N; to cache up to N deallocated objects for reuse, avoiding allocator overhead for frequently created/destroyed objects. Objects are automatically re-initialized on reuse.
  • Mixed Zig/Python packages - New py-packages = ["mypackage"] option in [tool.pyoz] section of pyproject.toml. Pure Python packages are included in wheels and symlinked in develop mode, enabling hybrid Zig+Python projects.
  • Optional constructor arguments - __new__ functions can now use optional types (?f64, ?i64, etc.) for trailing parameters. Omitted arguments default to null, enabling MyClass(1.0) when y: ?f64 and z: ?f64 are optional.
  • Signal handling (checkSignals) - New pyoz.checkSignals() function for cooperative Ctrl+C / KeyboardInterrupt support in long-running Zig code. Returns error.Interrupted when a signal is pending (Python exception already set). Error wrappers now preserve already-set Python exceptions instead of overwriting them.

Changed

  • Raise functions now take comptime message - All raise functions accept comptime message: [*:0]const u8 instead of runtime strings, which enables the @TypeOf(null) return type

Installation

Download the binary for your platform and add it to your PATH:

Platform Binary
Linux x86_64 pyoz-x86_64-linux
Linux ARM64 pyoz-aarch64-linux
macOS x86_64 pyoz-x86_64-macos
macOS ARM64 (Apple Silicon) pyoz-aarch64-macos
Windows x86_64 pyoz-x86_64-windows.exe
Windows ARM64 pyoz-aarch64-windows.exe

Source

Download PyOZ-0.7.0.tar.gz for the source code.

Quick Start

pyoz init mymodule
cd mymodule
pyoz build
pip install dist/*.whl