649 lines
127 KiB
HTML
649 lines
127 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="This trait represents the Python APIs which are usable on all Python objects."><title>PyAnyMethods in pyo3::prelude - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-46132b98.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="pyo3" data-themes="" data-resource-suffix="" data-rustdoc-version="1.85.1 (4eb161250 2025-03-15)" data-channel="1.85.1" data-search-js="search-75f5ac3e.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../pyo3/index.html">pyo3</a><span class="version">0.24.1</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">PyAny<wbr>Methods</a></h2><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.abs" title="abs">abs</a></li><li><a href="#tymethod.add" title="add">add</a></li><li><a href="#tymethod.bitand" title="bitand">bitand</a></li><li><a href="#tymethod.bitnot" title="bitnot">bitnot</a></li><li><a href="#tymethod.bitor" title="bitor">bitor</a></li><li><a href="#tymethod.bitxor" title="bitxor">bitxor</a></li><li><a href="#tymethod.call" title="call">call</a></li><li><a href="#tymethod.call0" title="call0">call0</a></li><li><a href="#tymethod.call1" title="call1">call1</a></li><li><a href="#tymethod.call_method" title="call_method">call_method</a></li><li><a href="#tymethod.call_method0" title="call_method0">call_method0</a></li><li><a href="#tymethod.call_method1" title="call_method1">call_method1</a></li><li><a href="#tymethod.compare" title="compare">compare</a></li><li><a href="#tymethod.contains" title="contains">contains</a></li><li><a href="#tymethod.del_item" title="del_item">del_item</a></li><li><a href="#tymethod.delattr" title="delattr">delattr</a></li><li><a href="#tymethod.dir" title="dir">dir</a></li><li><a href="#tymethod.div" title="div">div</a></li><li><a href="#tymethod.divmod" title="divmod">divmod</a></li><li><a href="#tymethod.downcast" title="downcast">downcast</a></li><li><a href="#tymethod.downcast_exact" title="downcast_exact">downcast_exact</a></li><li><a href="#tymethod.downcast_into" title="downcast_into">downcast_into</a></li><li><a href="#tymethod.downcast_into_exact" title="downcast_into_exact">downcast_into_exact</a></li><li><a href="#tymethod.downcast_into_unchecked" title="downcast_into_unchecked">downcast_into_unchecked</a></li><li><a href="#tymethod.downcast_unchecked" title="downcast_unchecked">downcast_unchecked</a></li><li><a href="#tymethod.eq" title="eq">eq</a></li><li><a href="#tymethod.extract" title="extract">extract</a></li><li><a href="#tymethod.floor_div" title="floor_div">floor_div</a></li><li><a href="#tymethod.ge" title="ge">ge</a></li><li><a href="#tymethod.get_item" title="get_item">get_item</a></li><li><a href="#tymethod.get_refcnt" title="get_refcnt">get_refcnt</a></li><li><a href="#tymethod.get_type" title="get_type">get_type</a></li><li><a href="#tymethod.get_type_ptr" title="get_type_ptr">get_type_ptr</a></li><li><a href="#tymethod.getattr" title="getattr">getattr</a></li><li><a href="#tymethod.getattr_opt" title="getattr_opt">getattr_opt</a></li><li><a href="#tymethod.gt" title="gt">gt</a></li><li><a href="#tymethod.hasattr" title="hasattr">hasattr</a></li><li><a href="#tymethod.hash" title="hash">hash</a></li><li><a href="#tymethod.is" title="is">is</a></li><li><a href="#tymethod.is_callable" title="is_callable">is_callable</a></li><li><a href="#tymethod.is_ellipsis" title="is_ellipsis">is_ellipsis</a></li><li><a href="#tymethod.is_empty" title="is_empty">is_empty</a></li><li><a href="#tymethod.is_exact_instance" title="is_exact_instance">is_exact_instance</a></li><li><a href="#tymethod.is_exact_instance_of" title="is_exact_instance_of">is_exact_instance_of</a></li><li><a href="#tymethod.is_instance" title="is_instance">is_instance</a></li><li><a href="#tymethod.is_instance_of" title="is_instance_of">is_instance_of</a></li><li><a href="#tymethod.is_none" title="is_none">is_none</a></li><li><a href="#tymethod.is_truthy" title="is_truthy">is_truthy</a></li><li><a href="#tymethod.iter" title="iter">iter</a></li><li><a href="#tymethod.le" title="le">le</a></li><li><a href="#tymethod.len" title="len">len</a></li><li><a href="#tymethod.lshift" title="lshift">lshift</a></li><li><a href="#tymethod.lt" title="lt">lt</a></li><li><a href="#tymethod.matmul" title="matmul">matmul</a></li><li><a href="#tymethod.mul" title="mul">mul</a></li><li><a href="#tymethod.ne" title="ne">ne</a></li><li><a href="#tymethod.neg" title="neg">neg</a></li><li><a href="#tymethod.pos" title="pos">pos</a></li><li><a href="#tymethod.pow" title="pow">pow</a></li><li><a href="#tymethod.py_super" title="py_super">py_super</a></li><li><a href="#tymethod.rem" title="rem">rem</a></li><li><a href="#tymethod.repr" title="repr">repr</a></li><li><a href="#tymethod.rich_compare" title="rich_compare">rich_compare</a></li><li><a href="#tymethod.rshift" title="rshift">rshift</a></li><li><a href="#tymethod.set_item" title="set_item">set_item</a></li><li><a href="#tymethod.setattr" title="setattr">setattr</a></li><li><a href="#tymethod.str" title="str">str</a></li><li><a href="#tymethod.sub" title="sub">sub</a></li><li><a href="#tymethod.try_iter" title="try_iter">try_iter</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In pyo3::<wbr>prelude</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">pyo3</a>::<wbr><a href="index.html">prelude</a></span><h1>Trait <span class="trait">PyAnyMethods</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/pyo3/types/any.rs.html#62-939">Source</a> </span></div><pre class="rust item-decl"><code>pub trait PyAnyMethods<'py>: Sealed {
|
||
<details class="toggle type-contents-toggle"><summary class="hideme"><span>Show 69 methods</span></summary> // Required methods
|
||
fn <a href="#tymethod.is" class="fn">is</a><T: <a class="trait" href="../conversion/trait.AsPyPointer.html" title="trait pyo3::conversion::AsPyPointer">AsPyPointer</a>>(&self, other: <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.reference.html">&T</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.hasattr" class="fn">hasattr</a><N>(&self, attr_name: N) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>>
|
||
<span class="where">where N: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py, Target = <a class="struct" href="../types/struct.PyString.html" title="struct pyo3::types::PyString">PyString</a>></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.getattr" class="fn">getattr</a><N>(&self, attr_name: N) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>
|
||
<span class="where">where N: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py, Target = <a class="struct" href="../types/struct.PyString.html" title="struct pyo3::types::PyString">PyString</a>></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.getattr_opt" class="fn">getattr_opt</a><N>(
|
||
&self,
|
||
attr_name: N,
|
||
) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="enum" href="https://doc.rust-lang.org/1.85.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>>
|
||
<span class="where">where N: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py, Target = <a class="struct" href="../types/struct.PyString.html" title="struct pyo3::types::PyString">PyString</a>></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.setattr" class="fn">setattr</a><N, V>(&self, attr_name: N, value: V) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>>
|
||
<span class="where">where N: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py, Target = <a class="struct" href="../types/struct.PyString.html" title="struct pyo3::types::PyString">PyString</a>>,
|
||
V: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.delattr" class="fn">delattr</a><N>(&self, attr_name: N) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>>
|
||
<span class="where">where N: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py, Target = <a class="struct" href="../types/struct.PyString.html" title="struct pyo3::types::PyString">PyString</a>></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.compare" class="fn">compare</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="enum" href="https://doc.rust-lang.org/1.85.1/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>>
|
||
<span class="where">where O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.rich_compare" class="fn">rich_compare</a><O>(
|
||
&self,
|
||
other: O,
|
||
compare_op: <a class="enum" href="../pyclass/enum.CompareOp.html" title="enum pyo3::pyclass::CompareOp">CompareOp</a>,
|
||
) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>
|
||
<span class="where">where O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.neg" class="fn">neg</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.pos" class="fn">pos</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.abs" class="fn">abs</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.bitnot" class="fn">bitnot</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.lt" class="fn">lt</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>>
|
||
<span class="where">where O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.le" class="fn">le</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>>
|
||
<span class="where">where O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.eq" class="fn">eq</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>>
|
||
<span class="where">where O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.ne" class="fn">ne</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>>
|
||
<span class="where">where O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.gt" class="fn">gt</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>>
|
||
<span class="where">where O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.ge" class="fn">ge</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>>
|
||
<span class="where">where O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.add" class="fn">add</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>
|
||
<span class="where">where O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.sub" class="fn">sub</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>
|
||
<span class="where">where O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.mul" class="fn">mul</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>
|
||
<span class="where">where O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.matmul" class="fn">matmul</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>
|
||
<span class="where">where O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.div" class="fn">div</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>
|
||
<span class="where">where O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.floor_div" class="fn">floor_div</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>
|
||
<span class="where">where O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.rem" class="fn">rem</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>
|
||
<span class="where">where O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.divmod" class="fn">divmod</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>
|
||
<span class="where">where O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.lshift" class="fn">lshift</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>
|
||
<span class="where">where O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.rshift" class="fn">rshift</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>
|
||
<span class="where">where O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.pow" class="fn">pow</a><O1, O2>(&self, other: O1, modulus: O2) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>
|
||
<span class="where">where O1: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,
|
||
O2: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.bitand" class="fn">bitand</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>
|
||
<span class="where">where O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.bitor" class="fn">bitor</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>
|
||
<span class="where">where O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.bitxor" class="fn">bitxor</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>
|
||
<span class="where">where O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.is_callable" class="fn">is_callable</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.call" class="fn">call</a><A>(
|
||
&self,
|
||
args: A,
|
||
kwargs: <a class="enum" href="https://doc.rust-lang.org/1.85.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyDict.html" title="struct pyo3::types::PyDict">PyDict</a>>>,
|
||
) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>
|
||
<span class="where">where A: <a class="trait" href="../call/trait.PyCallArgs.html" title="trait pyo3::call::PyCallArgs">PyCallArgs</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.call0" class="fn">call0</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.call1" class="fn">call1</a><A>(&self, args: A) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>
|
||
<span class="where">where A: <a class="trait" href="../call/trait.PyCallArgs.html" title="trait pyo3::call::PyCallArgs">PyCallArgs</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.call_method" class="fn">call_method</a><N, A>(
|
||
&self,
|
||
name: N,
|
||
args: A,
|
||
kwargs: <a class="enum" href="https://doc.rust-lang.org/1.85.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyDict.html" title="struct pyo3::types::PyDict">PyDict</a>>>,
|
||
) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>
|
||
<span class="where">where N: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py, Target = <a class="struct" href="../types/struct.PyString.html" title="struct pyo3::types::PyString">PyString</a>>,
|
||
A: <a class="trait" href="../call/trait.PyCallArgs.html" title="trait pyo3::call::PyCallArgs">PyCallArgs</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.call_method0" class="fn">call_method0</a><N>(&self, name: N) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>
|
||
<span class="where">where N: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py, Target = <a class="struct" href="../types/struct.PyString.html" title="struct pyo3::types::PyString">PyString</a>></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.call_method1" class="fn">call_method1</a><N, A>(
|
||
&self,
|
||
name: N,
|
||
args: A,
|
||
) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>
|
||
<span class="where">where N: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py, Target = <a class="struct" href="../types/struct.PyString.html" title="struct pyo3::types::PyString">PyString</a>>,
|
||
A: <a class="trait" href="../call/trait.PyCallArgs.html" title="trait pyo3::call::PyCallArgs">PyCallArgs</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.is_truthy" class="fn">is_truthy</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.is_none" class="fn">is_none</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.is_ellipsis" class="fn">is_ellipsis</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.is_empty" class="fn">is_empty</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.get_item" class="fn">get_item</a><K>(&self, key: K) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>
|
||
<span class="where">where K: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.set_item" class="fn">set_item</a><K, V>(&self, key: K, value: V) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>>
|
||
<span class="where">where K: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,
|
||
V: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.del_item" class="fn">del_item</a><K>(&self, key: K) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>>
|
||
<span class="where">where K: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.try_iter" class="fn">try_iter</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyIterator.html" title="struct pyo3::types::PyIterator">PyIterator</a>>>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.iter" class="fn">iter</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyIterator.html" title="struct pyo3::types::PyIterator">PyIterator</a>>>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.get_type" class="fn">get_type</a>(&self) -> <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyType.html" title="struct pyo3::types::PyType">PyType</a>>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.get_type_ptr" class="fn">get_type_ptr</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.pointer.html">*mut </a><a class="struct" href="../ffi/struct.PyTypeObject.html" title="struct pyo3::ffi::PyTypeObject">PyTypeObject</a>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.downcast" class="fn">downcast</a><T>(&self) -> <a class="enum" href="https://doc.rust-lang.org/1.85.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><&<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, T>, <a class="struct" href="../struct.DowncastError.html" title="struct pyo3::DowncastError">DowncastError</a><'_, 'py>>
|
||
<span class="where">where T: <a class="trait" href="../type_object/trait.PyTypeCheck.html" title="trait pyo3::type_object::PyTypeCheck">PyTypeCheck</a></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.downcast_into" class="fn">downcast_into</a><T>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.85.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, T>, <a class="struct" href="../struct.DowncastIntoError.html" title="struct pyo3::DowncastIntoError">DowncastIntoError</a><'py>>
|
||
<span class="where">where T: <a class="trait" href="../type_object/trait.PyTypeCheck.html" title="trait pyo3::type_object::PyTypeCheck">PyTypeCheck</a></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.downcast_exact" class="fn">downcast_exact</a><T>(
|
||
&self,
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.85.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><&<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, T>, <a class="struct" href="../struct.DowncastError.html" title="struct pyo3::DowncastError">DowncastError</a><'_, 'py>>
|
||
<span class="where">where T: <a class="trait" href="../type_object/trait.PyTypeInfo.html" title="trait pyo3::type_object::PyTypeInfo">PyTypeInfo</a></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.downcast_into_exact" class="fn">downcast_into_exact</a><T>(
|
||
self,
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/1.85.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, T>, <a class="struct" href="../struct.DowncastIntoError.html" title="struct pyo3::DowncastIntoError">DowncastIntoError</a><'py>>
|
||
<span class="where">where T: <a class="trait" href="../type_object/trait.PyTypeInfo.html" title="trait pyo3::type_object::PyTypeInfo">PyTypeInfo</a></span>;
|
||
<span class="item-spacer"></span> unsafe fn <a href="#tymethod.downcast_unchecked" class="fn">downcast_unchecked</a><T>(&self) -> &<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, T>;
|
||
<span class="item-spacer"></span> unsafe fn <a href="#tymethod.downcast_into_unchecked" class="fn">downcast_into_unchecked</a><T>(self) -> <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, T>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.extract" class="fn">extract</a><'a, T>(&'a self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><T>
|
||
<span class="where">where T: <a class="trait" href="../conversion/trait.FromPyObjectBound.html" title="trait pyo3::conversion::FromPyObjectBound">FromPyObjectBound</a><'a, 'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.get_refcnt" class="fn">get_refcnt</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.isize.html">isize</a>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.repr" class="fn">repr</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyString.html" title="struct pyo3::types::PyString">PyString</a>>>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.str" class="fn">str</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyString.html" title="struct pyo3::types::PyString">PyString</a>>>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.hash" class="fn">hash</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.isize.html">isize</a>>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.len" class="fn">len</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.usize.html">usize</a>>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.dir" class="fn">dir</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyList.html" title="struct pyo3::types::PyList">PyList</a>>>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.is_instance" class="fn">is_instance</a>(&self, ty: &<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.is_exact_instance" class="fn">is_exact_instance</a>(&self, ty: &<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>) -> <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.is_instance_of" class="fn">is_instance_of</a><T: <a class="trait" href="../type_object/trait.PyTypeInfo.html" title="trait pyo3::type_object::PyTypeInfo">PyTypeInfo</a>>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.is_exact_instance_of" class="fn">is_exact_instance_of</a><T: <a class="trait" href="../type_object/trait.PyTypeInfo.html" title="trait pyo3::type_object::PyTypeInfo">PyTypeInfo</a>>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.contains" class="fn">contains</a><V>(&self, value: V) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>>
|
||
<span class="where">where V: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.py_super" class="fn">py_super</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PySuper.html" title="struct pyo3::types::PySuper">PySuper</a>>>;
|
||
</details>}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>This trait represents the Python APIs which are usable on all Python objects.</p>
|
||
<p>It is recommended you import this trait via <code>use pyo3::prelude::*</code> rather than
|
||
by importing this trait directly.</p>
|
||
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.is" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#67">Source</a><h4 class="code-header">fn <a href="#tymethod.is" class="fn">is</a><T: <a class="trait" href="../conversion/trait.AsPyPointer.html" title="trait pyo3::conversion::AsPyPointer">AsPyPointer</a>>(&self, other: <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.reference.html">&T</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Returns whether <code>self</code> and <code>other</code> point to the same object. To compare
|
||
the equality of two objects (the <code>==</code> operator), use <a href="../types/trait.PyAnyMethods.html#tymethod.eq" title="method pyo3::types::PyAnyMethods::eq"><code>eq</code></a>.</p>
|
||
<p>This is equivalent to the Python expression <code>self is other</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.hasattr" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#91-93">Source</a><h4 class="code-header">fn <a href="#tymethod.hasattr" class="fn">hasattr</a><N>(&self, attr_name: N) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>><div class="where">where
|
||
N: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py, Target = <a class="struct" href="../types/struct.PyString.html" title="struct pyo3::types::PyString">PyString</a>>,</div></h4></section></summary><div class="docblock"><p>Determines whether this object has the given attribute.</p>
|
||
<p>This is equivalent to the Python expression <code>hasattr(self, attr_name)</code>.</p>
|
||
<p>To avoid repeated temporary allocations of Python strings, the <a href="../macro.intern.html" title="macro pyo3::intern"><code>intern!</code></a> macro can be used
|
||
to intern <code>attr_name</code>.</p>
|
||
<h5 id="example-interning-the-attribute-name"><a class="doc-anchor" href="#example-interning-the-attribute-name">§</a>Example: <code>intern!</code>ing the attribute name</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[pyfunction]
|
||
</span><span class="kw">fn </span>has_version(sys: <span class="kw-2">&</span>Bound<<span class="lifetime">'_</span>, PyModule>) -> PyResult<bool> {
|
||
sys.hasattr(<span class="macro">intern!</span>(sys.py(), <span class="string">"version"</span>))
|
||
}</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.getattr" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#117-119">Source</a><h4 class="code-header">fn <a href="#tymethod.getattr" class="fn">getattr</a><N>(&self, attr_name: N) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>><div class="where">where
|
||
N: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py, Target = <a class="struct" href="../types/struct.PyString.html" title="struct pyo3::types::PyString">PyString</a>>,</div></h4></section></summary><div class="docblock"><p>Retrieves an attribute value.</p>
|
||
<p>This is equivalent to the Python expression <code>self.attr_name</code>.</p>
|
||
<p>To avoid repeated temporary allocations of Python strings, the <a href="../macro.intern.html" title="macro pyo3::intern"><code>intern!</code></a> macro can be used
|
||
to intern <code>attr_name</code>.</p>
|
||
<h5 id="example-interning-the-attribute-name-1"><a class="doc-anchor" href="#example-interning-the-attribute-name-1">§</a>Example: <code>intern!</code>ing the attribute name</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[pyfunction]
|
||
</span><span class="kw">fn </span>version<<span class="lifetime">'py</span>>(sys: <span class="kw-2">&</span>Bound<<span class="lifetime">'py</span>, PyModule>) -> PyResult<Bound<<span class="lifetime">'py</span>, PyAny>> {
|
||
sys.getattr(<span class="macro">intern!</span>(sys.py(), <span class="string">"version"</span>))
|
||
}</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.getattr_opt" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#149-151">Source</a><h4 class="code-header">fn <a href="#tymethod.getattr_opt" class="fn">getattr_opt</a><N>(&self, attr_name: N) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="enum" href="https://doc.rust-lang.org/1.85.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>><div class="where">where
|
||
N: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py, Target = <a class="struct" href="../types/struct.PyString.html" title="struct pyo3::types::PyString">PyString</a>>,</div></h4></section></summary><div class="docblock"><p>Retrieves an attribute value optionally.</p>
|
||
<p>This is equivalent to the Python expression <code>getattr(self, attr_name, None)</code>, which may
|
||
be more efficient in some cases by simply returning <code>None</code> if the attribute is not found
|
||
instead of raising <code>AttributeError</code>.</p>
|
||
<p>To avoid repeated temporary allocations of Python strings, the <a href="../macro.intern.html" title="macro pyo3::intern"><code>intern!</code></a> macro can be used
|
||
to intern <code>attr_name</code>.</p>
|
||
<h5 id="errors"><a class="doc-anchor" href="#errors">§</a>Errors</h5>
|
||
<p>Returns <code>Err</code> if an exception other than <code>AttributeError</code> is raised during attribute lookup,
|
||
such as a <code>ValueError</code> from a property or descriptor.</p>
|
||
<h5 id="example-retrieving-an-optional-attribute"><a class="doc-anchor" href="#example-retrieving-an-optional-attribute">§</a>Example: Retrieving an optional attribute</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[pyfunction]
|
||
</span><span class="kw">fn </span>get_version_if_exists<<span class="lifetime">'py</span>>(sys: <span class="kw-2">&</span>Bound<<span class="lifetime">'py</span>, PyModule>) -> PyResult<<span class="prelude-ty">Option</span><Bound<<span class="lifetime">'py</span>, PyAny>>> {
|
||
sys.getattr_opt(<span class="macro">intern!</span>(sys.py(), <span class="string">"version"</span>))
|
||
}</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.setattr" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#175-178">Source</a><h4 class="code-header">fn <a href="#tymethod.setattr" class="fn">setattr</a><N, V>(&self, attr_name: N, value: V) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>><div class="where">where
|
||
N: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py, Target = <a class="struct" href="../types/struct.PyString.html" title="struct pyo3::types::PyString">PyString</a>>,
|
||
V: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Sets an attribute value.</p>
|
||
<p>This is equivalent to the Python expression <code>self.attr_name = value</code>.</p>
|
||
<p>To avoid repeated temporary allocations of Python strings, the <a href="../macro.intern.html" title="macro pyo3::intern"><code>intern!</code></a> macro can be used
|
||
to intern <code>name</code>.</p>
|
||
<h5 id="example-interning-the-attribute-name-2"><a class="doc-anchor" href="#example-interning-the-attribute-name-2">§</a>Example: <code>intern!</code>ing the attribute name</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[pyfunction]
|
||
</span><span class="kw">fn </span>set_answer(ob: <span class="kw-2">&</span>Bound<<span class="lifetime">'_</span>, PyAny>) -> PyResult<()> {
|
||
ob.setattr(<span class="macro">intern!</span>(ob.py(), <span class="string">"answer"</span>), <span class="number">42</span>)
|
||
}</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.delattr" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#186-188">Source</a><h4 class="code-header">fn <a href="#tymethod.delattr" class="fn">delattr</a><N>(&self, attr_name: N) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>><div class="where">where
|
||
N: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py, Target = <a class="struct" href="../types/struct.PyString.html" title="struct pyo3::types::PyString">PyString</a>>,</div></h4></section></summary><div class="docblock"><p>Deletes an attribute.</p>
|
||
<p>This is equivalent to the Python statement <code>del self.attr_name</code>.</p>
|
||
<p>To avoid repeated temporary allocations of Python strings, the <a href="../macro.intern.html" title="macro pyo3::intern"><code>intern!</code></a> macro can be used
|
||
to intern <code>attr_name</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.compare" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#236-238">Source</a><h4 class="code-header">fn <a href="#tymethod.compare" class="fn">compare</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="enum" href="https://doc.rust-lang.org/1.85.1/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>><div class="where">where
|
||
O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Returns an <a href="https://doc.rust-lang.org/1.85.1/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering"><code>Ordering</code></a> between <code>self</code> and <code>other</code>.</p>
|
||
<p>This is equivalent to the following Python code:</p>
|
||
<div class="example-wrap"><pre class="language-python"><code>if self == other:
|
||
return Equal
|
||
elif a < b:
|
||
return Less
|
||
elif a > b:
|
||
return Greater
|
||
else:
|
||
raise TypeError("PyAny::compare(): All comparisons returned false")</code></pre></div><h5 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>pyo3::prelude::<span class="kw-2">*</span>;
|
||
<span class="kw">use </span>pyo3::types::PyFloat;
|
||
<span class="kw">use </span>std::cmp::Ordering;
|
||
|
||
Python::with_gil(|py| -> PyResult<()> {
|
||
<span class="kw">let </span>a = PyFloat::new(py, <span class="number">0_f64</span>);
|
||
<span class="kw">let </span>b = PyFloat::new(py, <span class="number">42_f64</span>);
|
||
<span class="macro">assert_eq!</span>(a.compare(b)<span class="question-mark">?</span>, Ordering::Less);
|
||
<span class="prelude-val">Ok</span>(())
|
||
})<span class="question-mark">?</span>;</code></pre></div>
|
||
<p>It will return <code>PyErr</code> for values that cannot be compared:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>pyo3::prelude::<span class="kw-2">*</span>;
|
||
<span class="kw">use </span>pyo3::types::{PyFloat, PyString};
|
||
|
||
Python::with_gil(|py| -> PyResult<()> {
|
||
<span class="kw">let </span>a = PyFloat::new(py, <span class="number">0_f64</span>);
|
||
<span class="kw">let </span>b = PyString::new(py, <span class="string">"zero"</span>);
|
||
<span class="macro">assert!</span>(a.compare(b).is_err());
|
||
<span class="prelude-val">Ok</span>(())
|
||
})<span class="question-mark">?</span>;</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.rich_compare" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#273-275">Source</a><h4 class="code-header">fn <a href="#tymethod.rich_compare" class="fn">rich_compare</a><O>(
|
||
&self,
|
||
other: O,
|
||
compare_op: <a class="enum" href="../pyclass/enum.CompareOp.html" title="enum pyo3::pyclass::CompareOp">CompareOp</a>,
|
||
) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>><div class="where">where
|
||
O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Tests whether two Python objects obey a given <a href="../pyclass/enum.CompareOp.html" title="enum pyo3::pyclass::CompareOp"><code>CompareOp</code></a>.</p>
|
||
<p><a href="../types/trait.PyAnyMethods.html#tymethod.lt"><code>lt</code></a>, <a href="../types/trait.PyAnyMethods.html#tymethod.le"><code>le</code></a>, <a href="../types/trait.PyAnyMethods.html#tymethod.eq"><code>eq</code></a>, <a href="../types/trait.PyAnyMethods.html#tymethod.ne"><code>ne</code></a>,
|
||
<a href="../types/trait.PyAnyMethods.html#tymethod.gt"><code>gt</code></a> and <a href="../types/trait.PyAnyMethods.html#tymethod.ge"><code>ge</code></a> are the specialized versions
|
||
of this function.</p>
|
||
<p>Depending on the value of <code>compare_op</code>, this is equivalent to one of the
|
||
following Python expressions:</p>
|
||
<div><table><thead><tr><th style="text-align: center"><code>compare_op</code></th><th style="text-align: center">Python expression</th></tr></thead><tbody>
|
||
<tr><td style="text-align: center"><a href="../pyclass/enum.CompareOp.html#variant.Eq" title="variant pyo3::pyclass::CompareOp::Eq"><code>CompareOp::Eq</code></a></td><td style="text-align: center"><code>self == other</code></td></tr>
|
||
<tr><td style="text-align: center"><a href="../pyclass/enum.CompareOp.html#variant.Ne" title="variant pyo3::pyclass::CompareOp::Ne"><code>CompareOp::Ne</code></a></td><td style="text-align: center"><code>self != other</code></td></tr>
|
||
<tr><td style="text-align: center"><a href="../pyclass/enum.CompareOp.html#variant.Lt" title="variant pyo3::pyclass::CompareOp::Lt"><code>CompareOp::Lt</code></a></td><td style="text-align: center"><code>self < other</code></td></tr>
|
||
<tr><td style="text-align: center"><a href="../pyclass/enum.CompareOp.html#variant.Le" title="variant pyo3::pyclass::CompareOp::Le"><code>CompareOp::Le</code></a></td><td style="text-align: center"><code>self <= other</code></td></tr>
|
||
<tr><td style="text-align: center"><a href="../pyclass/enum.CompareOp.html#variant.Gt" title="variant pyo3::pyclass::CompareOp::Gt"><code>CompareOp::Gt</code></a></td><td style="text-align: center"><code>self > other</code></td></tr>
|
||
<tr><td style="text-align: center"><a href="../pyclass/enum.CompareOp.html#variant.Ge" title="variant pyo3::pyclass::CompareOp::Ge"><code>CompareOp::Ge</code></a></td><td style="text-align: center"><code>self >= other</code></td></tr>
|
||
</tbody></table>
|
||
</div><h5 id="examples-1"><a class="doc-anchor" href="#examples-1">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>pyo3::class::basic::CompareOp;
|
||
<span class="kw">use </span>pyo3::prelude::<span class="kw-2">*</span>;
|
||
|
||
Python::with_gil(|py| -> PyResult<()> {
|
||
<span class="kw">let </span>a = <span class="number">0_u8</span>.into_pyobject(py)<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>b = <span class="number">42_u8</span>.into_pyobject(py)<span class="question-mark">?</span>;
|
||
<span class="macro">assert!</span>(a.rich_compare(b, CompareOp::Le)<span class="question-mark">?</span>.is_truthy()<span class="question-mark">?</span>);
|
||
<span class="prelude-val">Ok</span>(())
|
||
})<span class="question-mark">?</span>;</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.neg" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#280">Source</a><h4 class="code-header">fn <a href="#tymethod.neg" class="fn">neg</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>></h4></section></summary><div class="docblock"><p>Computes the negative of self.</p>
|
||
<p>Equivalent to the Python expression <code>-self</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.pos" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#285">Source</a><h4 class="code-header">fn <a href="#tymethod.pos" class="fn">pos</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>></h4></section></summary><div class="docblock"><p>Computes the positive of self.</p>
|
||
<p>Equivalent to the Python expression <code>+self</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.abs" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#290">Source</a><h4 class="code-header">fn <a href="#tymethod.abs" class="fn">abs</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>></h4></section></summary><div class="docblock"><p>Computes the absolute of self.</p>
|
||
<p>Equivalent to the Python expression <code>abs(self)</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.bitnot" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#293">Source</a><h4 class="code-header">fn <a href="#tymethod.bitnot" class="fn">bitnot</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>></h4></section></summary><div class="docblock"><p>Computes <code>~self</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.lt" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#298-300">Source</a><h4 class="code-header">fn <a href="#tymethod.lt" class="fn">lt</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>><div class="where">where
|
||
O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Tests whether this object is less than another.</p>
|
||
<p>This is equivalent to the Python expression <code>self < other</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.le" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#305-307">Source</a><h4 class="code-header">fn <a href="#tymethod.le" class="fn">le</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>><div class="where">where
|
||
O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Tests whether this object is less than or equal to another.</p>
|
||
<p>This is equivalent to the Python expression <code>self <= other</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.eq" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#312-314">Source</a><h4 class="code-header">fn <a href="#tymethod.eq" class="fn">eq</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>><div class="where">where
|
||
O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Tests whether this object is equal to another.</p>
|
||
<p>This is equivalent to the Python expression <code>self == other</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.ne" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#319-321">Source</a><h4 class="code-header">fn <a href="#tymethod.ne" class="fn">ne</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>><div class="where">where
|
||
O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Tests whether this object is not equal to another.</p>
|
||
<p>This is equivalent to the Python expression <code>self != other</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.gt" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#326-328">Source</a><h4 class="code-header">fn <a href="#tymethod.gt" class="fn">gt</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>><div class="where">where
|
||
O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Tests whether this object is greater than another.</p>
|
||
<p>This is equivalent to the Python expression <code>self > other</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.ge" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#333-335">Source</a><h4 class="code-header">fn <a href="#tymethod.ge" class="fn">ge</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>><div class="where">where
|
||
O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Tests whether this object is greater than or equal to another.</p>
|
||
<p>This is equivalent to the Python expression <code>self >= other</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.add" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#338-340">Source</a><h4 class="code-header">fn <a href="#tymethod.add" class="fn">add</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>><div class="where">where
|
||
O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Computes <code>self + other</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.sub" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#343-345">Source</a><h4 class="code-header">fn <a href="#tymethod.sub" class="fn">sub</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>><div class="where">where
|
||
O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Computes <code>self - other</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.mul" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#348-350">Source</a><h4 class="code-header">fn <a href="#tymethod.mul" class="fn">mul</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>><div class="where">where
|
||
O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Computes <code>self * other</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.matmul" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#353-355">Source</a><h4 class="code-header">fn <a href="#tymethod.matmul" class="fn">matmul</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>><div class="where">where
|
||
O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Computes <code>self @ other</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.div" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#358-360">Source</a><h4 class="code-header">fn <a href="#tymethod.div" class="fn">div</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>><div class="where">where
|
||
O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Computes <code>self / other</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.floor_div" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#363-365">Source</a><h4 class="code-header">fn <a href="#tymethod.floor_div" class="fn">floor_div</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>><div class="where">where
|
||
O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Computes <code>self // other</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.rem" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#368-370">Source</a><h4 class="code-header">fn <a href="#tymethod.rem" class="fn">rem</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>><div class="where">where
|
||
O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Computes <code>self % other</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.divmod" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#373-375">Source</a><h4 class="code-header">fn <a href="#tymethod.divmod" class="fn">divmod</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>><div class="where">where
|
||
O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Computes <code>divmod(self, other)</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.lshift" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#378-380">Source</a><h4 class="code-header">fn <a href="#tymethod.lshift" class="fn">lshift</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>><div class="where">where
|
||
O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Computes <code>self << other</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.rshift" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#383-385">Source</a><h4 class="code-header">fn <a href="#tymethod.rshift" class="fn">rshift</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>><div class="where">where
|
||
O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Computes <code>self >> other</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.pow" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#389-392">Source</a><h4 class="code-header">fn <a href="#tymethod.pow" class="fn">pow</a><O1, O2>(&self, other: O1, modulus: O2) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>><div class="where">where
|
||
O1: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,
|
||
O2: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Computes <code>self ** other % modulus</code> (<code>pow(self, other, modulus)</code>).
|
||
<code>py.None()</code> may be passed for the <code>modulus</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.bitand" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#395-397">Source</a><h4 class="code-header">fn <a href="#tymethod.bitand" class="fn">bitand</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>><div class="where">where
|
||
O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Computes <code>self & other</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.bitor" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#400-402">Source</a><h4 class="code-header">fn <a href="#tymethod.bitor" class="fn">bitor</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>><div class="where">where
|
||
O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Computes <code>self | other</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.bitxor" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#405-407">Source</a><h4 class="code-header">fn <a href="#tymethod.bitxor" class="fn">bitxor</a><O>(&self, other: O) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>><div class="where">where
|
||
O: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Computes <code>self ^ other</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.is_callable" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#436">Source</a><h4 class="code-header">fn <a href="#tymethod.is_callable" class="fn">is_callable</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Determines whether this object appears callable.</p>
|
||
<p>This is equivalent to Python’s <a href="https://docs.python.org/3/library/functions.html#callable"><code>callable()</code></a> function.</p>
|
||
<h5 id="examples-2"><a class="doc-anchor" href="#examples-2">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>pyo3::prelude::<span class="kw-2">*</span>;
|
||
|
||
Python::with_gil(|py| -> PyResult<()> {
|
||
<span class="kw">let </span>builtins = PyModule::import(py, <span class="string">"builtins"</span>)<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>print = builtins.getattr(<span class="string">"print"</span>)<span class="question-mark">?</span>;
|
||
<span class="macro">assert!</span>(print.is_callable());
|
||
<span class="prelude-val">Ok</span>(())
|
||
})<span class="question-mark">?</span>;</code></pre></div>
|
||
<p>This is equivalent to the Python statement <code>assert callable(print)</code>.</p>
|
||
<p>Note that unless an API needs to distinguish between callable and
|
||
non-callable objects, there is no point in checking for callability.
|
||
Instead, it is better to just do the call and handle potential
|
||
exceptions.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.call" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#470-472">Source</a><h4 class="code-header">fn <a href="#tymethod.call" class="fn">call</a><A>(
|
||
&self,
|
||
args: A,
|
||
kwargs: <a class="enum" href="https://doc.rust-lang.org/1.85.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyDict.html" title="struct pyo3::types::PyDict">PyDict</a>>>,
|
||
) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>><div class="where">where
|
||
A: <a class="trait" href="../call/trait.PyCallArgs.html" title="trait pyo3::call::PyCallArgs">PyCallArgs</a><'py>,</div></h4></section></summary><div class="docblock"><p>Calls the object.</p>
|
||
<p>This is equivalent to the Python expression <code>self(*args, **kwargs)</code>.</p>
|
||
<h5 id="examples-3"><a class="doc-anchor" href="#examples-3">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>pyo3::prelude::<span class="kw-2">*</span>;
|
||
<span class="kw">use </span>pyo3::types::PyDict;
|
||
<span class="kw">use </span>pyo3_ffi::c_str;
|
||
<span class="kw">use </span>std::ffi::CStr;
|
||
|
||
<span class="kw">const </span>CODE: <span class="kw-2">&</span>CStr = <span class="macro">c_str!</span>(<span class="string">r#"
|
||
def function(*args, **kwargs):
|
||
assert args == ("hello",)
|
||
assert kwargs == {"cruel": "world"}
|
||
return "called with args and kwargs"
|
||
"#</span>);
|
||
|
||
Python::with_gil(|py| {
|
||
<span class="kw">let </span>module = PyModule::from_code(py, CODE, <span class="macro">c_str!</span>(<span class="string">""</span>), <span class="macro">c_str!</span>(<span class="string">""</span>))<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>fun = module.getattr(<span class="string">"function"</span>)<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>args = (<span class="string">"hello"</span>,);
|
||
<span class="kw">let </span>kwargs = PyDict::new(py);
|
||
kwargs.set_item(<span class="string">"cruel"</span>, <span class="string">"world"</span>)<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>result = fun.call(args, <span class="prelude-val">Some</span>(<span class="kw-2">&</span>kwargs))<span class="question-mark">?</span>;
|
||
<span class="macro">assert_eq!</span>(result.extract::<String>()<span class="question-mark">?</span>, <span class="string">"called with args and kwargs"</span>);
|
||
<span class="prelude-val">Ok</span>(())
|
||
})</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.call0" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#494">Source</a><h4 class="code-header">fn <a href="#tymethod.call0" class="fn">call0</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>></h4></section></summary><div class="docblock"><p>Calls the object without arguments.</p>
|
||
<p>This is equivalent to the Python expression <code>self()</code>.</p>
|
||
<h5 id="examples-4"><a class="doc-anchor" href="#examples-4">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>pyo3::prelude::<span class="kw-2">*</span>;
|
||
|
||
Python::with_gil(|py| -> PyResult<()> {
|
||
<span class="kw">let </span>module = PyModule::import(py, <span class="string">"builtins"</span>)<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>help = module.getattr(<span class="string">"help"</span>)<span class="question-mark">?</span>;
|
||
help.call0()<span class="question-mark">?</span>;
|
||
<span class="prelude-val">Ok</span>(())
|
||
})<span class="question-mark">?</span>;</code></pre></div>
|
||
<p>This is equivalent to the Python expression <code>help()</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.call1" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#525-527">Source</a><h4 class="code-header">fn <a href="#tymethod.call1" class="fn">call1</a><A>(&self, args: A) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>><div class="where">where
|
||
A: <a class="trait" href="../call/trait.PyCallArgs.html" title="trait pyo3::call::PyCallArgs">PyCallArgs</a><'py>,</div></h4></section></summary><div class="docblock"><p>Calls the object with only positional arguments.</p>
|
||
<p>This is equivalent to the Python expression <code>self(*args)</code>.</p>
|
||
<h5 id="examples-5"><a class="doc-anchor" href="#examples-5">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>pyo3::prelude::<span class="kw-2">*</span>;
|
||
<span class="kw">use </span>pyo3_ffi::c_str;
|
||
<span class="kw">use </span>std::ffi::CStr;
|
||
|
||
<span class="kw">const </span>CODE: <span class="kw-2">&</span>CStr = <span class="macro">c_str!</span>(<span class="string">r#"
|
||
def function(*args, **kwargs):
|
||
assert args == ("hello",)
|
||
assert kwargs == {}
|
||
return "called with args"
|
||
"#</span>);
|
||
|
||
Python::with_gil(|py| {
|
||
<span class="kw">let </span>module = PyModule::from_code(py, CODE, <span class="macro">c_str!</span>(<span class="string">""</span>), <span class="macro">c_str!</span>(<span class="string">""</span>))<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>fun = module.getattr(<span class="string">"function"</span>)<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>args = (<span class="string">"hello"</span>,);
|
||
<span class="kw">let </span>result = fun.call1(args)<span class="question-mark">?</span>;
|
||
<span class="macro">assert_eq!</span>(result.extract::<String>()<span class="question-mark">?</span>, <span class="string">"called with args"</span>);
|
||
<span class="prelude-val">Ok</span>(())
|
||
})</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.call_method" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#566-574">Source</a><h4 class="code-header">fn <a href="#tymethod.call_method" class="fn">call_method</a><N, A>(
|
||
&self,
|
||
name: N,
|
||
args: A,
|
||
kwargs: <a class="enum" href="https://doc.rust-lang.org/1.85.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyDict.html" title="struct pyo3::types::PyDict">PyDict</a>>>,
|
||
) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>><div class="where">where
|
||
N: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py, Target = <a class="struct" href="../types/struct.PyString.html" title="struct pyo3::types::PyString">PyString</a>>,
|
||
A: <a class="trait" href="../call/trait.PyCallArgs.html" title="trait pyo3::call::PyCallArgs">PyCallArgs</a><'py>,</div></h4></section></summary><div class="docblock"><p>Calls a method on the object.</p>
|
||
<p>This is equivalent to the Python expression <code>self.name(*args, **kwargs)</code>.</p>
|
||
<p>To avoid repeated temporary allocations of Python strings, the <a href="../macro.intern.html" title="macro pyo3::intern"><code>intern!</code></a> macro can be used
|
||
to intern <code>name</code>.</p>
|
||
<h5 id="examples-6"><a class="doc-anchor" href="#examples-6">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>pyo3::prelude::<span class="kw-2">*</span>;
|
||
<span class="kw">use </span>pyo3::types::PyDict;
|
||
<span class="kw">use </span>pyo3_ffi::c_str;
|
||
<span class="kw">use </span>std::ffi::CStr;
|
||
|
||
<span class="kw">const </span>CODE: <span class="kw-2">&</span>CStr = <span class="macro">c_str!</span>(<span class="string">r#"
|
||
class A:
|
||
def method(self, *args, **kwargs):
|
||
assert args == ("hello",)
|
||
assert kwargs == {"cruel": "world"}
|
||
return "called with args and kwargs"
|
||
a = A()
|
||
"#</span>);
|
||
|
||
Python::with_gil(|py| {
|
||
<span class="kw">let </span>module = PyModule::from_code(py, CODE, <span class="macro">c_str!</span>(<span class="string">""</span>), <span class="macro">c_str!</span>(<span class="string">""</span>))<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>instance = module.getattr(<span class="string">"a"</span>)<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>args = (<span class="string">"hello"</span>,);
|
||
<span class="kw">let </span>kwargs = PyDict::new(py);
|
||
kwargs.set_item(<span class="string">"cruel"</span>, <span class="string">"world"</span>)<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>result = instance.call_method(<span class="string">"method"</span>, args, <span class="prelude-val">Some</span>(<span class="kw-2">&</span>kwargs))<span class="question-mark">?</span>;
|
||
<span class="macro">assert_eq!</span>(result.extract::<String>()<span class="question-mark">?</span>, <span class="string">"called with args and kwargs"</span>);
|
||
<span class="prelude-val">Ok</span>(())
|
||
})</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.call_method0" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#609-611">Source</a><h4 class="code-header">fn <a href="#tymethod.call_method0" class="fn">call_method0</a><N>(&self, name: N) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>><div class="where">where
|
||
N: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py, Target = <a class="struct" href="../types/struct.PyString.html" title="struct pyo3::types::PyString">PyString</a>>,</div></h4></section></summary><div class="docblock"><p>Calls a method on the object without arguments.</p>
|
||
<p>This is equivalent to the Python expression <code>self.name()</code>.</p>
|
||
<p>To avoid repeated temporary allocations of Python strings, the <a href="../macro.intern.html" title="macro pyo3::intern"><code>intern!</code></a> macro can be used
|
||
to intern <code>name</code>.</p>
|
||
<h5 id="examples-7"><a class="doc-anchor" href="#examples-7">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>pyo3::prelude::<span class="kw-2">*</span>;
|
||
<span class="kw">use </span>pyo3_ffi::c_str;
|
||
<span class="kw">use </span>std::ffi::CStr;
|
||
|
||
<span class="kw">const </span>CODE: <span class="kw-2">&</span>CStr = <span class="macro">c_str!</span>(<span class="string">r#"
|
||
class A:
|
||
def method(self, *args, **kwargs):
|
||
assert args == ()
|
||
assert kwargs == {}
|
||
return "called with no arguments"
|
||
a = A()
|
||
"#</span>);
|
||
|
||
Python::with_gil(|py| {
|
||
<span class="kw">let </span>module = PyModule::from_code(py, CODE, <span class="macro">c_str!</span>(<span class="string">""</span>), <span class="macro">c_str!</span>(<span class="string">""</span>))<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>instance = module.getattr(<span class="string">"a"</span>)<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>result = instance.call_method0(<span class="string">"method"</span>)<span class="question-mark">?</span>;
|
||
<span class="macro">assert_eq!</span>(result.extract::<String>()<span class="question-mark">?</span>, <span class="string">"called with no arguments"</span>);
|
||
<span class="prelude-val">Ok</span>(())
|
||
})</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.call_method1" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#647-650">Source</a><h4 class="code-header">fn <a href="#tymethod.call_method1" class="fn">call_method1</a><N, A>(&self, name: N, args: A) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>><div class="where">where
|
||
N: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py, Target = <a class="struct" href="../types/struct.PyString.html" title="struct pyo3::types::PyString">PyString</a>>,
|
||
A: <a class="trait" href="../call/trait.PyCallArgs.html" title="trait pyo3::call::PyCallArgs">PyCallArgs</a><'py>,</div></h4></section></summary><div class="docblock"><p>Calls a method on the object with only positional arguments.</p>
|
||
<p>This is equivalent to the Python expression <code>self.name(*args)</code>.</p>
|
||
<p>To avoid repeated temporary allocations of Python strings, the <a href="../macro.intern.html" title="macro pyo3::intern"><code>intern!</code></a> macro can be used
|
||
to intern <code>name</code>.</p>
|
||
<h5 id="examples-8"><a class="doc-anchor" href="#examples-8">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>pyo3::prelude::<span class="kw-2">*</span>;
|
||
<span class="kw">use </span>pyo3_ffi::c_str;
|
||
<span class="kw">use </span>std::ffi::CStr;
|
||
|
||
<span class="kw">const </span>CODE: <span class="kw-2">&</span>CStr = <span class="macro">c_str!</span>(<span class="string">r#"
|
||
class A:
|
||
def method(self, *args, **kwargs):
|
||
assert args == ("hello",)
|
||
assert kwargs == {}
|
||
return "called with args"
|
||
a = A()
|
||
"#</span>);
|
||
|
||
Python::with_gil(|py| {
|
||
<span class="kw">let </span>module = PyModule::from_code(py, CODE, <span class="macro">c_str!</span>(<span class="string">""</span>), <span class="macro">c_str!</span>(<span class="string">""</span>))<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>instance = module.getattr(<span class="string">"a"</span>)<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>args = (<span class="string">"hello"</span>,);
|
||
<span class="kw">let </span>result = instance.call_method1(<span class="string">"method"</span>, args)<span class="question-mark">?</span>;
|
||
<span class="macro">assert_eq!</span>(result.extract::<String>()<span class="question-mark">?</span>, <span class="string">"called with args"</span>);
|
||
<span class="prelude-val">Ok</span>(())
|
||
})</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.is_truthy" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#655">Source</a><h4 class="code-header">fn <a href="#tymethod.is_truthy" class="fn">is_truthy</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>></h4></section></summary><div class="docblock"><p>Returns whether the object is considered to be true.</p>
|
||
<p>This is equivalent to the Python expression <code>bool(self)</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.is_none" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#660">Source</a><h4 class="code-header">fn <a href="#tymethod.is_none" class="fn">is_none</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Returns whether the object is considered to be None.</p>
|
||
<p>This is equivalent to the Python expression <code>self is None</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.is_ellipsis" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#666">Source</a><h4 class="code-header">fn <a href="#tymethod.is_ellipsis" class="fn">is_ellipsis</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a></h4></section><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span><span>Deprecated since 0.23.0: use <code>.is(py.Ellipsis())</code> instead</span></div></span></summary><div class="docblock"><p>Returns whether the object is Ellipsis, e.g. <code>...</code>.</p>
|
||
<p>This is equivalent to the Python expression <code>self is ...</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.is_empty" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#671">Source</a><h4 class="code-header">fn <a href="#tymethod.is_empty" class="fn">is_empty</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>></h4></section></summary><div class="docblock"><p>Returns true if the sequence or mapping has a length of 0.</p>
|
||
<p>This is equivalent to the Python expression <code>len(self) == 0</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.get_item" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#676-678">Source</a><h4 class="code-header">fn <a href="#tymethod.get_item" class="fn">get_item</a><K>(&self, key: K) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>><div class="where">where
|
||
K: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Gets an item from the collection.</p>
|
||
<p>This is equivalent to the Python expression <code>self[key]</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.set_item" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#683-686">Source</a><h4 class="code-header">fn <a href="#tymethod.set_item" class="fn">set_item</a><K, V>(&self, key: K, value: V) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>><div class="where">where
|
||
K: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,
|
||
V: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Sets a collection item value.</p>
|
||
<p>This is equivalent to the Python expression <code>self[key] = value</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.del_item" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#691-693">Source</a><h4 class="code-header">fn <a href="#tymethod.del_item" class="fn">del_item</a><K>(&self, key: K) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>><div class="where">where
|
||
K: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Deletes an item from the collection.</p>
|
||
<p>This is equivalent to the Python expression <code>del self[key]</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.try_iter" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#719">Source</a><h4 class="code-header">fn <a href="#tymethod.try_iter" class="fn">try_iter</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyIterator.html" title="struct pyo3::types::PyIterator">PyIterator</a>>></h4></section></summary><div class="docblock"><p>Takes an object and returns an iterator for it. Returns an error if the object is not
|
||
iterable.</p>
|
||
<p>This is typically a new iterator but if the argument is an iterator,
|
||
this returns itself.</p>
|
||
<h5 id="example-checking-a-python-object-for-iterability"><a class="doc-anchor" href="#example-checking-a-python-object-for-iterability">§</a>Example: Checking a Python object for iterability</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>pyo3::prelude::<span class="kw-2">*</span>;
|
||
<span class="kw">use </span>pyo3::types::{PyAny, PyNone};
|
||
|
||
<span class="kw">fn </span>is_iterable(obj: <span class="kw-2">&</span>Bound<<span class="lifetime">'_</span>, PyAny>) -> bool {
|
||
<span class="kw">match </span>obj.try_iter() {
|
||
<span class="prelude-val">Ok</span>(<span class="kw">_</span>) => <span class="bool-val">true</span>,
|
||
<span class="prelude-val">Err</span>(<span class="kw">_</span>) => <span class="bool-val">false</span>,
|
||
}
|
||
}
|
||
|
||
Python::with_gil(|py| {
|
||
<span class="macro">assert!</span>(is_iterable(<span class="kw-2">&</span><span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].into_pyobject(py).unwrap()));
|
||
<span class="macro">assert!</span>(!is_iterable(<span class="kw-2">&</span>PyNone::get(py)));
|
||
});</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.iter" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#726">Source</a><h4 class="code-header">fn <a href="#tymethod.iter" class="fn">iter</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyIterator.html" title="struct pyo3::types::PyIterator">PyIterator</a>>></h4></section><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span><span>Deprecated since 0.23.0: use <code>try_iter</code> instead</span></div></span></summary><div class="docblock"><p>Takes an object and returns an iterator for it.</p>
|
||
<p>This is typically a new iterator but if the argument is an iterator,
|
||
this returns itself.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.get_type" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#729">Source</a><h4 class="code-header">fn <a href="#tymethod.get_type" class="fn">get_type</a>(&self) -> <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyType.html" title="struct pyo3::types::PyType">PyType</a>></h4></section></summary><div class="docblock"><p>Returns the Python type object for this object’s type.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.get_type_ptr" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#732">Source</a><h4 class="code-header">fn <a href="#tymethod.get_type_ptr" class="fn">get_type_ptr</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.pointer.html">*mut </a><a class="struct" href="../ffi/struct.PyTypeObject.html" title="struct pyo3::ffi::PyTypeObject">PyTypeObject</a></h4></section></summary><div class="docblock"><p>Returns the Python type pointer for this object.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.downcast" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#786-788">Source</a><h4 class="code-header">fn <a href="#tymethod.downcast" class="fn">downcast</a><T>(&self) -> <a class="enum" href="https://doc.rust-lang.org/1.85.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><&<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, T>, <a class="struct" href="../struct.DowncastError.html" title="struct pyo3::DowncastError">DowncastError</a><'_, 'py>><div class="where">where
|
||
T: <a class="trait" href="../type_object/trait.PyTypeCheck.html" title="trait pyo3::type_object::PyTypeCheck">PyTypeCheck</a>,</div></h4></section></summary><div class="docblock"><p>Downcast this <code>PyAny</code> to a concrete Python type or pyclass.</p>
|
||
<p>Note that you can often avoid downcasting yourself by just specifying
|
||
the desired type in function or method signatures.
|
||
However, manual downcasting is sometimes necessary.</p>
|
||
<p>For extracting a Rust-only type, see <a href="struct.PyAny.html#method.extract"><code>PyAny::extract</code></a>.</p>
|
||
<h5 id="example-downcasting-to-a-specific-python-object"><a class="doc-anchor" href="#example-downcasting-to-a-specific-python-object">§</a>Example: Downcasting to a specific Python object</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>pyo3::prelude::<span class="kw-2">*</span>;
|
||
<span class="kw">use </span>pyo3::types::{PyDict, PyList};
|
||
|
||
Python::with_gil(|py| {
|
||
<span class="kw">let </span>dict = PyDict::new(py);
|
||
<span class="macro">assert!</span>(dict.is_instance_of::<PyAny>());
|
||
<span class="kw">let </span>any = dict.as_any();
|
||
|
||
<span class="macro">assert!</span>(any.downcast::<PyDict>().is_ok());
|
||
<span class="macro">assert!</span>(any.downcast::<PyList>().is_err());
|
||
});</code></pre></div>
|
||
<h5 id="example-getting-a-reference-to-a-pyclass"><a class="doc-anchor" href="#example-getting-a-reference-to-a-pyclass">§</a>Example: Getting a reference to a pyclass</h5>
|
||
<p>This is useful if you want to mutate a <code>PyObject</code> that
|
||
might actually be a pyclass.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>pyo3::prelude::<span class="kw-2">*</span>;
|
||
|
||
<span class="attr">#[pyclass]
|
||
</span><span class="kw">struct </span>Class {
|
||
i: i32,
|
||
}
|
||
|
||
Python::with_gil(|py| {
|
||
<span class="kw">let </span>class = Py::new(py, Class { i: <span class="number">0 </span>}).unwrap().into_bound(py).into_any();
|
||
|
||
<span class="kw">let </span>class_bound: <span class="kw-2">&</span>Bound<<span class="lifetime">'_</span>, Class> = class.downcast()<span class="question-mark">?</span>;
|
||
|
||
class_bound.borrow_mut().i += <span class="number">1</span>;
|
||
|
||
<span class="comment">// Alternatively you can get a `PyRefMut` directly
|
||
</span><span class="kw">let </span>class_ref: PyRefMut<<span class="lifetime">'_</span>, Class> = class.extract()<span class="question-mark">?</span>;
|
||
<span class="macro">assert_eq!</span>(class_ref.i, <span class="number">1</span>);
|
||
<span class="prelude-val">Ok</span>(())
|
||
})</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.downcast_into" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#812-814">Source</a><h4 class="code-header">fn <a href="#tymethod.downcast_into" class="fn">downcast_into</a><T>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.85.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, T>, <a class="struct" href="../struct.DowncastIntoError.html" title="struct pyo3::DowncastIntoError">DowncastIntoError</a><'py>><div class="where">where
|
||
T: <a class="trait" href="../type_object/trait.PyTypeCheck.html" title="trait pyo3::type_object::PyTypeCheck">PyTypeCheck</a>,</div></h4></section></summary><div class="docblock"><p>Like <code>downcast</code> but takes ownership of <code>self</code>.</p>
|
||
<p>In case of an error, it is possible to retrieve <code>self</code> again via <a href="../struct.DowncastIntoError.html#method.into_inner" title="method pyo3::DowncastIntoError::into_inner"><code>DowncastIntoError::into_inner</code></a>.</p>
|
||
<h5 id="example"><a class="doc-anchor" href="#example">§</a>Example</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>pyo3::prelude::<span class="kw-2">*</span>;
|
||
<span class="kw">use </span>pyo3::types::{PyDict, PyList};
|
||
|
||
Python::with_gil(|py| {
|
||
<span class="kw">let </span>obj: Bound<<span class="lifetime">'_</span>, PyAny> = PyDict::new(py).into_any();
|
||
|
||
<span class="kw">let </span>obj: Bound<<span class="lifetime">'_</span>, PyAny> = <span class="kw">match </span>obj.downcast_into::<PyList>() {
|
||
<span class="prelude-val">Ok</span>(<span class="kw">_</span>) => <span class="macro">panic!</span>(<span class="string">"obj should not be a list"</span>),
|
||
<span class="prelude-val">Err</span>(err) => err.into_inner(),
|
||
};
|
||
|
||
<span class="comment">// obj is a dictionary
|
||
</span><span class="macro">assert!</span>(obj.downcast_into::<PyDict>().is_ok());
|
||
})</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.downcast_exact" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#846-848">Source</a><h4 class="code-header">fn <a href="#tymethod.downcast_exact" class="fn">downcast_exact</a><T>(&self) -> <a class="enum" href="https://doc.rust-lang.org/1.85.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><&<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, T>, <a class="struct" href="../struct.DowncastError.html" title="struct pyo3::DowncastError">DowncastError</a><'_, 'py>><div class="where">where
|
||
T: <a class="trait" href="../type_object/trait.PyTypeInfo.html" title="trait pyo3::type_object::PyTypeInfo">PyTypeInfo</a>,</div></h4></section></summary><div class="docblock"><p>Downcast this <code>PyAny</code> to a concrete Python type or pyclass (but not a subclass of it).</p>
|
||
<p>It is almost always better to use <a href="../types/trait.PyAnyMethods.html#tymethod.downcast" title="method pyo3::types::PyAnyMethods::downcast"><code>PyAnyMethods::downcast</code></a> because it accounts for Python
|
||
subtyping. Use this method only when you do not want to allow subtypes.</p>
|
||
<p>The advantage of this method over <a href="../types/trait.PyAnyMethods.html#tymethod.downcast" title="method pyo3::types::PyAnyMethods::downcast"><code>PyAnyMethods::downcast</code></a> is that it is faster. The implementation
|
||
of <code>downcast_exact</code> uses the equivalent of the Python expression <code>type(self) is T</code>, whereas
|
||
<code>downcast</code> uses <code>isinstance(self, T)</code>.</p>
|
||
<p>For extracting a Rust-only type, see <a href="struct.PyAny.html#method.extract"><code>PyAny::extract</code></a>.</p>
|
||
<h5 id="example-downcasting-to-a-specific-python-object-but-not-a-subtype"><a class="doc-anchor" href="#example-downcasting-to-a-specific-python-object-but-not-a-subtype">§</a>Example: Downcasting to a specific Python object but not a subtype</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>pyo3::prelude::<span class="kw-2">*</span>;
|
||
<span class="kw">use </span>pyo3::types::{PyBool, PyInt};
|
||
|
||
Python::with_gil(|py| {
|
||
<span class="kw">let </span>b = PyBool::new(py, <span class="bool-val">true</span>);
|
||
<span class="macro">assert!</span>(b.is_instance_of::<PyBool>());
|
||
<span class="kw">let </span>any: <span class="kw-2">&</span>Bound<<span class="lifetime">'_</span>, PyAny> = b.as_any();
|
||
|
||
<span class="comment">// `bool` is a subtype of `int`, so `downcast` will accept a `bool` as an `int`
|
||
// but `downcast_exact` will not.
|
||
</span><span class="macro">assert!</span>(any.downcast::<PyInt>().is_ok());
|
||
<span class="macro">assert!</span>(any.downcast_exact::<PyInt>().is_err());
|
||
|
||
<span class="macro">assert!</span>(any.downcast_exact::<PyBool>().is_ok());
|
||
});</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.downcast_into_exact" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#851-853">Source</a><h4 class="code-header">fn <a href="#tymethod.downcast_into_exact" class="fn">downcast_into_exact</a><T>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.85.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, T>, <a class="struct" href="../struct.DowncastIntoError.html" title="struct pyo3::DowncastIntoError">DowncastIntoError</a><'py>><div class="where">where
|
||
T: <a class="trait" href="../type_object/trait.PyTypeInfo.html" title="trait pyo3::type_object::PyTypeInfo">PyTypeInfo</a>,</div></h4></section></summary><div class="docblock"><p>Like <code>downcast_exact</code> but takes ownership of <code>self</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.downcast_unchecked" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#860">Source</a><h4 class="code-header">unsafe fn <a href="#tymethod.downcast_unchecked" class="fn">downcast_unchecked</a><T>(&self) -> &<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, T></h4></section></summary><div class="docblock"><p>Converts this <code>PyAny</code> to a concrete Python type without checking validity.</p>
|
||
<h5 id="safety"><a class="doc-anchor" href="#safety">§</a>Safety</h5>
|
||
<p>Callers must ensure that the type is valid or risk type confusion.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.downcast_into_unchecked" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#867">Source</a><h4 class="code-header">unsafe fn <a href="#tymethod.downcast_into_unchecked" class="fn">downcast_into_unchecked</a><T>(self) -> <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, T></h4></section></summary><div class="docblock"><p>Like <code>downcast_unchecked</code> but takes ownership of <code>self</code>.</p>
|
||
<h5 id="safety-1"><a class="doc-anchor" href="#safety-1">§</a>Safety</h5>
|
||
<p>Callers must ensure that the type is valid or risk type confusion.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.extract" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#873-875">Source</a><h4 class="code-header">fn <a href="#tymethod.extract" class="fn">extract</a><'a, T>(&'a self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><T><div class="where">where
|
||
T: <a class="trait" href="../conversion/trait.FromPyObjectBound.html" title="trait pyo3::conversion::FromPyObjectBound">FromPyObjectBound</a><'a, 'py>,</div></h4></section></summary><div class="docblock"><p>Extracts some type from the Python object.</p>
|
||
<p>This is a wrapper function around
|
||
<a href="../conversion/trait.FromPyObject.html#tymethod.extract_bound" title="associated function pyo3::conversion::FromPyObject::extract_bound"><code>FromPyObject::extract_bound()</code></a>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.get_refcnt" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#878">Source</a><h4 class="code-header">fn <a href="#tymethod.get_refcnt" class="fn">get_refcnt</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.isize.html">isize</a></h4></section></summary><div class="docblock"><p>Returns the reference count for the Python object.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.repr" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#883">Source</a><h4 class="code-header">fn <a href="#tymethod.repr" class="fn">repr</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyString.html" title="struct pyo3::types::PyString">PyString</a>>></h4></section></summary><div class="docblock"><p>Computes the “repr” representation of self.</p>
|
||
<p>This is equivalent to the Python expression <code>repr(self)</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.str" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#888">Source</a><h4 class="code-header">fn <a href="#tymethod.str" class="fn">str</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyString.html" title="struct pyo3::types::PyString">PyString</a>>></h4></section></summary><div class="docblock"><p>Computes the “str” representation of self.</p>
|
||
<p>This is equivalent to the Python expression <code>str(self)</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.hash" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#893">Source</a><h4 class="code-header">fn <a href="#tymethod.hash" class="fn">hash</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.isize.html">isize</a>></h4></section></summary><div class="docblock"><p>Retrieves the hash code of self.</p>
|
||
<p>This is equivalent to the Python expression <code>hash(self)</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.len" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#898">Source</a><h4 class="code-header">fn <a href="#tymethod.len" class="fn">len</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.usize.html">usize</a>></h4></section></summary><div class="docblock"><p>Returns the length of the sequence or mapping.</p>
|
||
<p>This is equivalent to the Python expression <code>len(self)</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.dir" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#903">Source</a><h4 class="code-header">fn <a href="#tymethod.dir" class="fn">dir</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyList.html" title="struct pyo3::types::PyList">PyList</a>>></h4></section></summary><div class="docblock"><p>Returns the list of attributes of this object.</p>
|
||
<p>This is equivalent to the Python expression <code>dir(self)</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.is_instance" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#908">Source</a><h4 class="code-header">fn <a href="#tymethod.is_instance" class="fn">is_instance</a>(&self, ty: &<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>></h4></section></summary><div class="docblock"><p>Checks whether this object is an instance of type <code>ty</code>.</p>
|
||
<p>This is equivalent to the Python expression <code>isinstance(self, ty)</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.is_exact_instance" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#913">Source</a><h4 class="code-header">fn <a href="#tymethod.is_exact_instance" class="fn">is_exact_instance</a>(&self, ty: &<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>) -> <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Checks whether this object is an instance of exactly type <code>ty</code> (not a subclass).</p>
|
||
<p>This is equivalent to the Python expression <code>type(self) is ty</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.is_instance_of" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#919">Source</a><h4 class="code-header">fn <a href="#tymethod.is_instance_of" class="fn">is_instance_of</a><T: <a class="trait" href="../type_object/trait.PyTypeInfo.html" title="trait pyo3::type_object::PyTypeInfo">PyTypeInfo</a>>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Checks whether this object is an instance of type <code>T</code>.</p>
|
||
<p>This is equivalent to the Python expression <code>isinstance(self, T)</code>,
|
||
if the type <code>T</code> is known at compile time.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.is_exact_instance_of" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#925">Source</a><h4 class="code-header">fn <a href="#tymethod.is_exact_instance_of" class="fn">is_exact_instance_of</a><T: <a class="trait" href="../type_object/trait.PyTypeInfo.html" title="trait pyo3::type_object::PyTypeInfo">PyTypeInfo</a>>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Checks whether this object is an instance of exactly type <code>T</code>.</p>
|
||
<p>This is equivalent to the Python expression <code>type(self) is T</code>,
|
||
if the type <code>T</code> is known at compile time.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.contains" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#930-932">Source</a><h4 class="code-header">fn <a href="#tymethod.contains" class="fn">contains</a><V>(&self, value: V) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>><div class="where">where
|
||
V: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</div></h4></section></summary><div class="docblock"><p>Determines if self contains <code>value</code>.</p>
|
||
<p>This is equivalent to the Python expression <code>value in self</code>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.py_super" class="method"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#938">Source</a><h4 class="code-header">fn <a href="#tymethod.py_super" class="fn">py_super</a>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PySuper.html" title="struct pyo3::types::PySuper">PySuper</a>>></h4></section></summary><div class="docblock"><p>Return a proxy object that delegates method calls to a parent or sibling class of type.</p>
|
||
<p>This is equivalent to the Python expression <code>super()</code></p>
|
||
</div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/1.85.1/reference/items/traits.html#object-safety">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-PyAnyMethods%3C'py%3E-for-Bound%3C'py,+PyAny%3E" class="impl"><a class="src rightside" href="../../src/pyo3/types/any.rs.html#964-1613">Source</a><a href="#impl-PyAnyMethods%3C'py%3E-for-Bound%3C'py,+PyAny%3E" class="anchor">§</a><h3 class="code-header">impl<'py> <a class="trait" href="../types/trait.PyAnyMethods.html" title="trait pyo3::types::PyAnyMethods">PyAnyMethods</a><'py> for <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>></h3></section></div><script src="../../trait.impl/pyo3/types/any/trait.PyAnyMethods.js" async></script></section></div></main></body></html> |