Files
RustPython/crates/wasm
Jeong, YunWon 100dac0bbe Reject payload receivers on #[pymethod] and #[pygetset] (#8898)
* Report errors from #[pyclass] trait items

The trait branch of impl_pyclass_impl built its own ImplContext, so the
errors collected while extracting trait items were never emitted: an
invalid #[pymethod] or #[pygetset] in a #[pyclass] trait was left out of
the class without a compile error. The trait branch now uses the shared
context whose errors are emitted.

Assisted-by: Claude Code:claude-opus-5-5

* Pass the object to #[pymethod] and #[pygetset] receivers outside vm

Outside crates/vm, where impl Py<T> cannot be written, #[pymethod] and
#[pygetset] receivers that took &self become zelf: &Py<Self> inside the
existing impl T blocks. Where Rust code calls one of these methods on a
payload value, the logic stays in a payload method and the Python method
forwards to it.

Assisted-by: Claude Code:claude-opus-5-5
Assisted-by: Grok:grok-4.7

* Reject payload receivers on #[pymethod] and #[pygetset]

A #[pymethod] or #[pygetset] item with a self receiver is now a compile
error when self is the payload: in an impl for T rather than Py<T> or
PyRef<T>, and in a #[pyclass] trait. The error points to taking
zelf: &Py<Self> or zelf: PyRef<Self>, or defining the item in impl Py<T>.

Assisted-by: Claude Code:claude-opus-5-5

* Pass the object to the layout test getter

The subclass layout test's extra getter is a #[pygetset] on the
payload. Take zelf: &Py<Self> so the receiver is the object.

Assisted-by: Grok:4.7
2026-09-30 22:12:16 +09:00
..
2026-07-19 14:13:47 +09:00
2026-07-19 14:13:47 +09:00

RustPython

A Python-3 (CPython >= 3.8.0) Interpreter written in Rust.

Build Status License: MIT

WARNING: this project is still in a pre-alpha state!

Using this in a production project is inadvisable. Please only do so if you understand the risks.

Usage

Check out our online demo running on WebAssembly.

Goals

  • Full Python-3 environment entirely in Rust (not CPython bindings)
  • A clean implementation without compatibility hacks

Quick Documentation

pyEval(code, options?);

code: string: The Python code to run

options:

  • vars?: { [key: string]: any }: Variables passed to the VM that can be accessed in Python with the variable js_vars. Functions do work, and receive the Python kwargs as the this argument.
  • stdout?: "console" | ((out: string) => void) | null: A function to replace the native print function, and it will be console.log when giving undefined or "console", and it will be a dumb function when giving null.
  • stderr?: "console" | ((out: string) => void) | null: A function to replace sys.stderr, and it will be console.error when giving undefined or "console".

License

This project is licensed under the MIT license.