Skip to content

Commit

Permalink
fix: uses into_bound_py_any to cover more wider range
Browse files Browse the repository at this point in the history
  • Loading branch information
konn committed Jan 17, 2025
1 parent 60f84a4 commit cdf3e9e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyo3-stub-gen-derive/src/gen_stub/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl ToTokens for ArgsWithSignature<'_> {
::pyo3::prepare_freethreaded_python();
::pyo3::Python::with_gil(|py| -> String {
let v: #ty = #value;
if let Ok(py_obj) = <#ty as ::pyo3::IntoPyObject>::into_pyobject(v, py) {
if let Ok(py_obj) = <#ty as ::pyo3::IntoPyObjectExt>::into_bound_py_any(v, py) {
::pyo3_stub_gen::util::fmt_py_obj(&py_obj)
} else {
"...".to_owned()
Expand Down
6 changes: 2 additions & 4 deletions pyo3-stub-gen/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use pyo3::{prelude::*, types::*};

pub fn all_builtin_types<T>(input: &Bound<'_, T>) -> bool {
let any = input.as_any();
pub fn all_builtin_types(any: &Bound<'_, PyAny>) -> bool {
if any.is_instance_of::<PyString>()
|| any.is_instance_of::<PyBool>()
|| any.is_instance_of::<PyInt>()
Expand Down Expand Up @@ -34,8 +33,7 @@ pub fn all_builtin_types<T>(input: &Bound<'_, T>) -> bool {
false
}

pub fn fmt_py_obj<T>(input: &Bound<'_, T>) -> String {
let any = input.as_any();
pub fn fmt_py_obj(any: &Bound<'_, PyAny>) -> String {
if all_builtin_types(any) {
if let Ok(py_str) = any.as_any().repr() {
return py_str.to_string();
Expand Down

0 comments on commit cdf3e9e

Please sign in to comment.