pub struct PythonOptions {
pub python_namespace: String,
pub python_path: Vec<String>,
pub imports: BTreeMap<String, HashSet<String>>,
pub stdpython: String,
pub with_std_python: bool,
pub allow_unsafe: bool,
pub async_runtime: AsyncRuntime,
pub lossy_warnings: bool,
pub optional_names: Rc<HashSet<String>>,
pub clone_str_attribute_returns: bool,
pub local_types: Rc<HashMap<String, String>>,
pub no_std: bool,
}Expand description
The global context for Python compilation.
Fields§
§python_namespace: StringPython imports are mapped into a given namespace that can be changed.
python_path: Vec<String>The default path we will search for Python modules.
imports: BTreeMap<String, HashSet<String>>Collects all of the things we need to compile imports[module][asnames]
stdpython: String§with_std_python: bool§allow_unsafe: bool§async_runtime: AsyncRuntimeThe async runtime to use for async Python code
lossy_warnings: boolEmit #[deprecated] notes on generated items whose conversion was lossy (dropped parameter defaults, ignored return annotations, …). On by default: silent semantic divergence from the Python source is exactly what these warnings exist to surface. Tools may disable this to suppress the warnings at the user’s explicit request.
optional_names: Rc<HashSet<String>>Names in the CURRENT scope that hold an Option (assigned None on some path, or annotated Optional): non-None stores into them wrap in Some. Set per scope by the function/module generators.
clone_str_attribute_returns: boolWhether the CURRENT function’s return annotation is str: returning
an attribute chain then clones the String field out of the shared
receiver. Python strings are immutable, so the clone reproduces
Python’s aliasing semantics exactly. Set per function.
local_types: Rc<HashMap<String, String>>Statically-known types of names in the CURRENT scope (parameter annotations and literal assignments), as canonical Python type names (“int”, “float”, “str”, “bool”). Set per function; consumed by isinstance(), which lowers to a constant.
no_std: boolTarget stdpython’s no_std (alloc) tier. Python constructs that need
the OS — print/input/open, imports of os/datetime/random/…, and
__main__ entry points — fail loudly at conversion time instead of
surfacing as resolution errors when the generated crate builds.
Implementations§
Source§impl PythonOptions
impl PythonOptions
Sourcepub fn with_tokio() -> Self
pub fn with_tokio() -> Self
Create PythonOptions with tokio runtime (default)
Sourcepub fn with_async_std() -> Self
pub fn with_async_std() -> Self
Create PythonOptions with async-std runtime
Sourcepub fn with_custom_runtime(
attribute: impl Into<String>,
import: impl Into<String>,
) -> Self
pub fn with_custom_runtime( attribute: impl Into<String>, import: impl Into<String>, ) -> Self
Create PythonOptions with a custom async runtime
Sourcepub fn set_async_runtime(&mut self, runtime: AsyncRuntime) -> &mut Self
pub fn set_async_runtime(&mut self, runtime: AsyncRuntime) -> &mut Self
Set the async runtime for these options
Trait Implementations§
Source§impl Clone for PythonOptions
impl Clone for PythonOptions
Source§fn clone(&self) -> PythonOptions
fn clone(&self) -> PythonOptions
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more