index int64 0 0 | repo_id stringclasses 596 values | file_path stringlengths 31 168 | content stringlengths 1 6.2M |
|---|---|---|---|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/test_pyfunction.rs | #![cfg(feature = "macros")]
use std::collections::HashMap;
#[cfg(not(Py_LIMITED_API))]
use pyo3::buffer::PyBuffer;
use pyo3::ffi::c_str;
use pyo3::prelude::*;
#[cfg(not(Py_LIMITED_API))]
use pyo3::types::PyDateTime;
#[cfg(not(any(Py_LIMITED_API, PyPy)))]
use pyo3::types::PyFunction;
use pyo3::types::{self, PyCFunction};
#[path = "../src/tests/common.rs"]
mod common;
#[pyfunction(name = "struct")]
fn struct_function() {}
#[test]
fn test_rust_keyword_name() {
Python::with_gil(|py| {
let f = wrap_pyfunction!(struct_function)(py).unwrap();
py_assert!(py, f, "f.__name__ == 'struct'");
});
}
#[pyfunction(signature = (arg = true))]
fn optional_bool(arg: Option<bool>) -> String {
format!("{:?}", arg)
}
#[test]
fn test_optional_bool() {
// Regression test for issue #932
Python::with_gil(|py| {
let f = wrap_pyfunction!(optional_bool)(py).unwrap();
py_assert!(py, f, "f() == 'Some(true)'");
py_assert!(py, f, "f(True) == 'Some(true)'");
py_assert!(py, f, "f(False) == 'Some(false)'");
py_assert!(py, f, "f(None) == 'None'");
});
}
#[cfg(not(Py_LIMITED_API))]
#[pyfunction]
fn buffer_inplace_add(py: Python<'_>, x: PyBuffer<i32>, y: PyBuffer<i32>) {
let x = x.as_mut_slice(py).unwrap();
let y = y.as_slice(py).unwrap();
for (xi, yi) in x.iter().zip(y) {
let xi_plus_yi = xi.get() + yi.get();
xi.set(xi_plus_yi);
}
}
#[cfg(not(Py_LIMITED_API))]
#[test]
fn test_buffer_add() {
Python::with_gil(|py| {
let f = wrap_pyfunction!(buffer_inplace_add)(py).unwrap();
py_expect_exception!(
py,
f,
r#"
import array
a = array.array("i", [0, 1, 2, 3])
b = array.array("I", [0, 1, 2, 3])
f(a, b)
"#,
PyBufferError
);
pyo3::py_run!(
py,
f,
r#"
import array
a = array.array("i", [0, 1, 2, 3])
b = array.array("i", [2, 3, 4, 5])
f(a, b)
assert a, array.array("i", [2, 4, 6, 8])
"#
);
});
}
#[cfg(not(any(Py_LIMITED_API, PyPy)))]
#[pyfunction]
fn function_with_pyfunction_arg<'py>(fun: &Bound<'py, PyFunction>) -> PyResult<Bound<'py, PyAny>> {
fun.call((), None)
}
#[pyfunction]
fn function_with_pycfunction_arg<'py>(
fun: &Bound<'py, PyCFunction>,
) -> PyResult<Bound<'py, PyAny>> {
fun.call((), None)
}
#[test]
fn test_functions_with_function_args() {
Python::with_gil(|py| {
let py_cfunc_arg = wrap_pyfunction!(function_with_pycfunction_arg)(py).unwrap();
let bool_to_string = wrap_pyfunction!(optional_bool)(py).unwrap();
pyo3::py_run!(
py,
py_cfunc_arg
bool_to_string,
r#"
assert py_cfunc_arg(bool_to_string) == "Some(true)"
"#
);
#[cfg(not(any(Py_LIMITED_API, PyPy)))]
{
let py_func_arg = wrap_pyfunction!(function_with_pyfunction_arg)(py).unwrap();
pyo3::py_run!(
py,
py_func_arg,
r#"
def foo(): return "bar"
assert py_func_arg(foo) == "bar"
"#
);
}
});
}
#[cfg(not(Py_LIMITED_API))]
fn datetime_to_timestamp(dt: &Bound<'_, PyAny>) -> PyResult<i64> {
let dt = dt.downcast::<PyDateTime>()?;
let ts: f64 = dt.call_method0("timestamp")?.extract()?;
Ok(ts as i64)
}
#[cfg(not(Py_LIMITED_API))]
#[pyfunction]
fn function_with_custom_conversion(
#[pyo3(from_py_with = "datetime_to_timestamp")] timestamp: i64,
) -> i64 {
timestamp
}
#[cfg(not(Py_LIMITED_API))]
#[test]
fn test_function_with_custom_conversion() {
Python::with_gil(|py| {
let custom_conv_func = wrap_pyfunction!(function_with_custom_conversion)(py).unwrap();
pyo3::py_run!(
py,
custom_conv_func,
r#"
import datetime
dt = datetime.datetime.fromtimestamp(1612040400)
assert custom_conv_func(dt) == 1612040400
"#
)
});
}
#[cfg(not(Py_LIMITED_API))]
#[test]
fn test_function_with_custom_conversion_error() {
Python::with_gil(|py| {
let custom_conv_func = wrap_pyfunction!(function_with_custom_conversion)(py).unwrap();
py_expect_exception!(
py,
custom_conv_func,
"custom_conv_func(['a'])",
PyTypeError,
"argument 'timestamp': 'list' object cannot be converted to 'PyDateTime'"
);
});
}
#[test]
fn test_from_py_with_defaults() {
fn optional_int(x: &Bound<'_, PyAny>) -> PyResult<Option<i32>> {
if x.is_none() {
Ok(None)
} else {
Some(x.extract()).transpose()
}
}
// issue 2280 combination of from_py_with and Option<T> did not compile
#[pyfunction]
#[pyo3(signature = (int=None))]
fn from_py_with_option(#[pyo3(from_py_with = "optional_int")] int: Option<i32>) -> i32 {
int.unwrap_or(0)
}
#[pyfunction(signature = (len=0))]
fn from_py_with_default(
#[pyo3(from_py_with = "<Bound<'_, _> as PyAnyMethods>::len")] len: usize,
) -> usize {
len
}
Python::with_gil(|py| {
let f = wrap_pyfunction!(from_py_with_option)(py).unwrap();
assert_eq!(f.call0().unwrap().extract::<i32>().unwrap(), 0);
assert_eq!(f.call1((123,)).unwrap().extract::<i32>().unwrap(), 123);
assert_eq!(f.call1((999,)).unwrap().extract::<i32>().unwrap(), 999);
let f2 = wrap_pyfunction!(from_py_with_default)(py).unwrap();
assert_eq!(f2.call0().unwrap().extract::<usize>().unwrap(), 0);
assert_eq!(f2.call1(("123",)).unwrap().extract::<usize>().unwrap(), 3);
assert_eq!(f2.call1(("1234",)).unwrap().extract::<usize>().unwrap(), 4);
});
}
#[pyclass]
#[derive(Debug, FromPyObject)]
struct ValueClass {
#[pyo3(get)]
value: usize,
}
#[pyfunction]
#[pyo3(signature=(str_arg, int_arg, tuple_arg, option_arg = None, struct_arg = None))]
fn conversion_error(
str_arg: &str,
int_arg: i64,
tuple_arg: (String, f64),
option_arg: Option<i64>,
struct_arg: Option<ValueClass>,
) {
println!(
"{:?} {:?} {:?} {:?} {:?}",
str_arg, int_arg, tuple_arg, option_arg, struct_arg
);
}
#[test]
fn test_conversion_error() {
Python::with_gil(|py| {
let conversion_error = wrap_pyfunction!(conversion_error)(py).unwrap();
py_expect_exception!(
py,
conversion_error,
"conversion_error(None, None, None, None, None)",
PyTypeError,
"argument 'str_arg': 'NoneType' object cannot be converted to 'PyString'"
);
py_expect_exception!(
py,
conversion_error,
"conversion_error(100, None, None, None, None)",
PyTypeError,
"argument 'str_arg': 'int' object cannot be converted to 'PyString'"
);
py_expect_exception!(
py,
conversion_error,
"conversion_error('string1', 'string2', None, None, None)",
PyTypeError,
"argument 'int_arg': 'str' object cannot be interpreted as an integer"
);
py_expect_exception!(
py,
conversion_error,
"conversion_error('string1', -100, 'string2', None, None)",
PyTypeError,
"argument 'tuple_arg': 'str' object cannot be converted to 'PyTuple'"
);
py_expect_exception!(
py,
conversion_error,
"conversion_error('string1', -100, ('string2', 10.), 'string3', None)",
PyTypeError,
"argument 'option_arg': 'str' object cannot be interpreted as an integer"
);
let exception = py_expect_exception!(
py,
conversion_error,
"
class ValueClass:
def __init__(self, value):
self.value = value
conversion_error('string1', -100, ('string2', 10.), None, ValueClass(\"no_expected_type\"))",
PyTypeError
);
assert_eq!(
extract_traceback(py, exception),
"TypeError: argument 'struct_arg': failed to \
extract field ValueClass.value: TypeError: 'str' object cannot be interpreted as an integer"
);
let exception = py_expect_exception!(
py,
conversion_error,
"
class ValueClass:
def __init__(self, value):
self.value = value
conversion_error('string1', -100, ('string2', 10.), None, ValueClass(-5))",
PyTypeError
);
assert_eq!(
extract_traceback(py, exception),
"TypeError: argument 'struct_arg': failed to \
extract field ValueClass.value: OverflowError: can't convert negative int to unsigned"
);
});
}
/// Helper function that concatenates the error message from
/// each error in the traceback into a single string that can
/// be tested.
fn extract_traceback(py: Python<'_>, mut error: PyErr) -> String {
let mut error_msg = error.to_string();
while let Some(cause) = error.cause(py) {
error_msg.push_str(": ");
error_msg.push_str(&cause.to_string());
error = cause
}
error_msg
}
#[test]
fn test_pycfunction_new() {
use pyo3::ffi;
Python::with_gil(|py| {
unsafe extern "C" fn c_fn(
_self: *mut ffi::PyObject,
_args: *mut ffi::PyObject,
) -> *mut ffi::PyObject {
ffi::PyLong_FromLong(4200)
}
let py_fn = PyCFunction::new(
py,
c_fn,
c_str!("py_fn"),
c_str!("py_fn for test (this is the docstring)"),
None,
)
.unwrap();
py_assert!(py, py_fn, "py_fn() == 4200");
py_assert!(
py,
py_fn,
"py_fn.__doc__ == 'py_fn for test (this is the docstring)'"
);
});
}
#[test]
fn test_pycfunction_new_with_keywords() {
use pyo3::ffi;
use std::os::raw::c_long;
use std::ptr;
Python::with_gil(|py| {
unsafe extern "C" fn c_fn(
_self: *mut ffi::PyObject,
args: *mut ffi::PyObject,
kwds: *mut ffi::PyObject,
) -> *mut ffi::PyObject {
let mut foo: c_long = 0;
let mut bar: c_long = 0;
#[cfg(not(Py_3_13))]
let foo_name = std::ffi::CString::new("foo").unwrap();
#[cfg(not(Py_3_13))]
let kw_bar_name = std::ffi::CString::new("kw_bar").unwrap();
#[cfg(not(Py_3_13))]
let mut args_names = [foo_name.into_raw(), kw_bar_name.into_raw(), ptr::null_mut()];
#[cfg(Py_3_13)]
let args_names = [
c_str!("foo").as_ptr(),
c_str!("kw_bar").as_ptr(),
ptr::null_mut(),
];
ffi::PyArg_ParseTupleAndKeywords(
args,
kwds,
c_str!("l|l").as_ptr(),
#[cfg(Py_3_13)]
args_names.as_ptr(),
#[cfg(not(Py_3_13))]
args_names.as_mut_ptr(),
&mut foo,
&mut bar,
);
#[cfg(not(Py_3_13))]
drop(std::ffi::CString::from_raw(args_names[0]));
#[cfg(not(Py_3_13))]
drop(std::ffi::CString::from_raw(args_names[1]));
ffi::PyLong_FromLong(foo * bar)
}
let py_fn = PyCFunction::new_with_keywords(
py,
c_fn,
c_str!("py_fn"),
c_str!("py_fn for test (this is the docstring)"),
None,
)
.unwrap();
py_assert!(py, py_fn, "py_fn(42, kw_bar=100) == 4200");
py_assert!(py, py_fn, "py_fn(foo=42, kw_bar=100) == 4200");
py_assert!(
py,
py_fn,
"py_fn.__doc__ == 'py_fn for test (this is the docstring)'"
);
});
}
#[test]
fn test_closure() {
Python::with_gil(|py| {
let f = |args: &Bound<'_, types::PyTuple>,
_kwargs: Option<&Bound<'_, types::PyDict>>|
-> PyResult<_> {
Python::with_gil(|py| {
let res: PyResult<Vec<_>> = args
.iter()
.map(|elem| {
if let Ok(i) = elem.extract::<i64>() {
Ok((i + 1).into_pyobject(py)?.into_any().unbind())
} else if let Ok(f) = elem.extract::<f64>() {
Ok((2. * f).into_pyobject(py)?.into_any().unbind())
} else if let Ok(mut s) = elem.extract::<String>() {
s.push_str("-py");
Ok(s.into_pyobject(py)?.into_any().unbind())
} else {
panic!("unexpected argument type for {:?}", elem)
}
})
.collect();
res
})
};
let closure_py =
PyCFunction::new_closure(py, Some(c_str!("test_fn")), Some(c_str!("test_fn doc")), f)
.unwrap();
py_assert!(py, closure_py, "closure_py(42) == [43]");
py_assert!(py, closure_py, "closure_py.__name__ == 'test_fn'");
py_assert!(py, closure_py, "closure_py.__doc__ == 'test_fn doc'");
py_assert!(
py,
closure_py,
"closure_py(42, 3.14, 'foo') == [43, 6.28, 'foo-py']"
);
});
}
#[test]
fn test_closure_counter() {
Python::with_gil(|py| {
let counter = std::cell::RefCell::new(0);
let counter_fn = move |_args: &Bound<'_, types::PyTuple>,
_kwargs: Option<&Bound<'_, types::PyDict>>|
-> PyResult<i32> {
let mut counter = counter.borrow_mut();
*counter += 1;
Ok(*counter)
};
let counter_py = PyCFunction::new_closure(py, None, None, counter_fn).unwrap();
py_assert!(py, counter_py, "counter_py() == 1");
py_assert!(py, counter_py, "counter_py() == 2");
py_assert!(py, counter_py, "counter_py() == 3");
});
}
#[test]
fn use_pyfunction() {
mod function_in_module {
use pyo3::prelude::*;
#[pyfunction]
pub fn foo(x: i32) -> i32 {
x
}
}
Python::with_gil(|py| {
use function_in_module::foo;
// check imported name can be wrapped
let f = wrap_pyfunction!(foo, py).unwrap();
assert_eq!(f.call1((5,)).unwrap().extract::<i32>().unwrap(), 5);
assert_eq!(f.call1((42,)).unwrap().extract::<i32>().unwrap(), 42);
// check path import can be wrapped
let f2 = wrap_pyfunction!(function_in_module::foo, py).unwrap();
assert_eq!(f2.call1((5,)).unwrap().extract::<i32>().unwrap(), 5);
assert_eq!(f2.call1((42,)).unwrap().extract::<i32>().unwrap(), 42);
})
}
#[pyclass]
struct Key(String);
#[pyclass]
struct Value(i32);
#[pyfunction]
fn return_value_borrows_from_arguments<'py>(
py: Python<'py>,
key: &'py Key,
value: &'py Value,
) -> HashMap<&'py str, i32> {
py.allow_threads(move || {
let mut map = HashMap::new();
map.insert(key.0.as_str(), value.0);
map
})
}
#[test]
fn test_return_value_borrows_from_arguments() {
Python::with_gil(|py| {
let function = wrap_pyfunction!(return_value_borrows_from_arguments, py).unwrap();
let key = Py::new(py, Key("key".to_owned())).unwrap();
let value = Py::new(py, Value(42)).unwrap();
py_assert!(py, function key value, "function(key, value) == { \"key\": 42 }");
});
}
#[test]
fn test_some_wrap_arguments() {
// https://github.com/PyO3/pyo3/issues/3460
const NONE: Option<u8> = None;
#[pyfunction(signature = (a = 1, b = Some(2), c = None, d = NONE))]
fn some_wrap_arguments(
a: Option<u8>,
b: Option<u8>,
c: Option<u8>,
d: Option<u8>,
) -> [Option<u8>; 4] {
[a, b, c, d]
}
Python::with_gil(|py| {
let function = wrap_pyfunction!(some_wrap_arguments, py).unwrap();
py_assert!(py, function, "function() == [1, 2, None, None]");
})
}
#[test]
fn test_reference_to_bound_arguments() {
#[pyfunction]
#[pyo3(signature = (x, y = None))]
fn reference_args<'py>(
x: &Bound<'py, PyAny>,
y: Option<&Bound<'py, PyAny>>,
) -> PyResult<Bound<'py, PyAny>> {
y.map_or_else(|| Ok(x.clone()), |y| y.add(x))
}
Python::with_gil(|py| {
let function = wrap_pyfunction!(reference_args, py).unwrap();
py_assert!(py, function, "function(1) == 1");
py_assert!(py, function, "function(1, 2) == 3");
})
}
#[test]
fn test_pyfunction_raw_ident() {
#[pyfunction]
fn r#struct() -> bool {
true
}
#[pyfunction]
#[pyo3(name = "r#enum")]
fn raw_ident() -> bool {
true
}
#[pymodule]
fn m(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(r#struct, m)?)?;
m.add_function(wrap_pyfunction!(raw_ident, m)?)?;
Ok(())
}
Python::with_gil(|py| {
let m = pyo3::wrap_pymodule!(m)(py);
py_assert!(py, m, "m.struct()");
py_assert!(py, m, "m.enum()");
})
}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/test_string.rs | #![cfg(feature = "macros")]
use pyo3::prelude::*;
#[path = "../src/tests/common.rs"]
mod common;
#[pyfunction]
fn take_str(_s: &str) {}
#[test]
fn test_unicode_encode_error() {
Python::with_gil(|py| {
let take_str = wrap_pyfunction!(take_str)(py).unwrap();
py_expect_exception!(
py,
take_str,
"take_str('\\ud800')",
PyUnicodeEncodeError,
"'utf-8' codec can't encode character '\\ud800' in position 0: surrogates not allowed"
);
});
}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/test_inheritance.rs | #![cfg(feature = "macros")]
use pyo3::prelude::*;
use pyo3::py_run;
use pyo3::ffi;
use pyo3::types::IntoPyDict;
#[path = "../src/tests/common.rs"]
mod common;
#[pyclass(subclass)]
struct BaseClass {
#[pyo3(get)]
val1: usize,
}
#[pyclass(subclass)]
struct SubclassAble {}
#[test]
fn subclass() {
Python::with_gil(|py| {
let d = [("SubclassAble", py.get_type::<SubclassAble>())]
.into_py_dict(py)
.unwrap();
py.run(
ffi::c_str!("class A(SubclassAble): pass\nassert issubclass(A, SubclassAble)"),
None,
Some(&d),
)
.map_err(|e| e.display(py))
.unwrap();
});
}
#[pymethods]
impl BaseClass {
#[new]
fn new() -> Self {
BaseClass { val1: 10 }
}
fn base_method(&self, x: usize) -> usize {
x * self.val1
}
fn base_set(&mut self, fn_: &Bound<'_, PyAny>) -> PyResult<()> {
let value: usize = fn_.call0()?.extract()?;
self.val1 = value;
Ok(())
}
}
#[pyclass(extends=BaseClass)]
struct SubClass {
#[pyo3(get)]
val2: usize,
}
#[pymethods]
impl SubClass {
#[new]
fn new() -> (Self, BaseClass) {
(SubClass { val2: 5 }, BaseClass { val1: 10 })
}
fn sub_method(&self, x: usize) -> usize {
x * self.val2
}
fn sub_set_and_ret(&mut self, x: usize) -> usize {
self.val2 = x;
x
}
}
#[test]
fn inheritance_with_new_methods() {
Python::with_gil(|py| {
let typeobj = py.get_type::<SubClass>();
let inst = typeobj.call((), None).unwrap();
py_run!(py, inst, "assert inst.val1 == 10; assert inst.val2 == 5");
});
}
#[test]
fn call_base_and_sub_methods() {
Python::with_gil(|py| {
let obj = Py::new(py, SubClass::new()).unwrap();
py_run!(
py,
obj,
r#"
assert obj.base_method(10) == 100
assert obj.sub_method(10) == 50
"#
);
});
}
#[test]
fn mutation_fails() {
Python::with_gil(|py| {
let obj = Py::new(py, SubClass::new()).unwrap();
let global = [("obj", obj)].into_py_dict(py).unwrap();
let e = py
.run(
ffi::c_str!("obj.base_set(lambda: obj.sub_set_and_ret(1))"),
Some(&global),
None,
)
.unwrap_err();
assert_eq!(&e.to_string(), "RuntimeError: Already borrowed");
});
}
#[test]
fn is_subclass_and_is_instance() {
Python::with_gil(|py| {
let sub_ty = py.get_type::<SubClass>();
let base_ty = py.get_type::<BaseClass>();
assert!(sub_ty.is_subclass_of::<BaseClass>().unwrap());
assert!(sub_ty.is_subclass(&base_ty).unwrap());
let obj = Bound::new(py, SubClass::new()).unwrap().into_any();
assert!(obj.is_instance_of::<SubClass>());
assert!(obj.is_instance_of::<BaseClass>());
assert!(obj.is_instance(&sub_ty).unwrap());
assert!(obj.is_instance(&base_ty).unwrap());
});
}
#[pyclass(subclass)]
struct BaseClassWithResult {
_val: usize,
}
#[pymethods]
impl BaseClassWithResult {
#[new]
fn new(value: isize) -> PyResult<Self> {
Ok(Self {
_val: std::convert::TryFrom::try_from(value)?,
})
}
}
#[pyclass(extends=BaseClassWithResult)]
struct SubClass2 {}
#[pymethods]
impl SubClass2 {
#[new]
fn new(value: isize) -> PyResult<(Self, BaseClassWithResult)> {
let base = BaseClassWithResult::new(value)?;
Ok((Self {}, base))
}
}
#[test]
fn handle_result_in_new() {
Python::with_gil(|py| {
let subclass = py.get_type::<SubClass2>();
py_run!(
py,
subclass,
r#"
try:
subclass(-10)
assert Fals
except ValueError as e:
pass
except Exception as e:
raise e
"#
);
});
}
// Subclassing builtin types is not allowed in the LIMITED API.
#[cfg(not(Py_LIMITED_API))]
mod inheriting_native_type {
use super::*;
use pyo3::exceptions::PyException;
use pyo3::types::PyDict;
#[cfg(not(PyPy))]
#[test]
fn inherit_set() {
use pyo3::types::PySet;
#[cfg(not(PyPy))]
#[pyclass(extends=PySet)]
#[derive(Debug)]
struct SetWithName {
#[pyo3(get, name = "name")]
_name: &'static str,
}
#[cfg(not(PyPy))]
#[pymethods]
impl SetWithName {
#[new]
fn new() -> Self {
SetWithName { _name: "Hello :)" }
}
}
Python::with_gil(|py| {
let set_sub = pyo3::Py::new(py, SetWithName::new()).unwrap();
py_run!(
py,
set_sub,
r#"set_sub.add(10); assert list(set_sub) == [10]; assert set_sub.name == "Hello :)""#
);
});
}
#[pyclass(extends=PyDict)]
#[derive(Debug)]
struct DictWithName {
#[pyo3(get, name = "name")]
_name: &'static str,
}
#[pymethods]
impl DictWithName {
#[new]
fn new() -> Self {
DictWithName { _name: "Hello :)" }
}
}
#[test]
fn inherit_dict() {
Python::with_gil(|py| {
let dict_sub = pyo3::Py::new(py, DictWithName::new()).unwrap();
py_run!(
py,
dict_sub,
r#"dict_sub[0] = 1; assert dict_sub[0] == 1; assert dict_sub.name == "Hello :)""#
);
});
}
#[test]
fn inherit_dict_drop() {
Python::with_gil(|py| {
let dict_sub = pyo3::Py::new(py, DictWithName::new()).unwrap();
assert_eq!(dict_sub.get_refcnt(py), 1);
let item = &py.eval(ffi::c_str!("object()"), None, None).unwrap();
assert_eq!(item.get_refcnt(), 1);
dict_sub.bind(py).set_item("foo", item).unwrap();
assert_eq!(item.get_refcnt(), 2);
drop(dict_sub);
assert_eq!(item.get_refcnt(), 1);
})
}
#[pyclass(extends=PyException)]
struct CustomException {
#[pyo3(get)]
context: &'static str,
}
#[pymethods]
impl CustomException {
#[new]
fn new(_exc_arg: &Bound<'_, PyAny>) -> Self {
CustomException {
context: "Hello :)",
}
}
}
#[test]
fn custom_exception() {
Python::with_gil(|py| {
let cls = py.get_type::<CustomException>();
let dict = [("cls", &cls)].into_py_dict(py).unwrap();
let res = py.run(
ffi::c_str!("e = cls('hello'); assert str(e) == 'hello'; assert e.context == 'Hello :)'; raise e"),
None,
Some(&dict)
);
let err = res.unwrap_err();
assert!(err.matches(py, &cls).unwrap(), "{}", err);
// catching the exception in Python also works:
py_run!(
py,
cls,
r#"
try:
raise cls("foo")
except cls:
pass
"#
)
})
}
}
#[pyclass(subclass)]
struct SimpleClass {}
#[pymethods]
impl SimpleClass {
#[new]
fn new() -> Self {
Self {}
}
}
#[test]
fn test_subclass_ref_counts() {
// regression test for issue #1363
Python::with_gil(|py| {
#[allow(non_snake_case)]
let SimpleClass = py.get_type::<SimpleClass>();
py_run!(
py,
SimpleClass,
r#"
import gc
import sys
class SubClass(SimpleClass):
pass
gc.collect()
count = sys.getrefcount(SubClass)
for i in range(1000):
c = SubClass()
del c
gc.collect()
after = sys.getrefcount(SubClass)
# depending on Python's GC the count may be either identical or exactly 1000 higher,
# both are expected values that are not representative of the issue.
#
# (With issue #1363 the count will be decreased.)
assert after == count or (after == count + 1000), f"{after} vs {count}"
"#
);
})
}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/test_datetime.rs | #![cfg(not(Py_LIMITED_API))]
use pyo3::types::{timezone_utc, IntoPyDict, PyDate, PyDateTime, PyTime};
use pyo3::{ffi, prelude::*};
use pyo3_ffi::PyDateTime_IMPORT;
use std::ffi::CString;
fn _get_subclasses<'py>(
py: Python<'py>,
py_type: &str,
args: &str,
) -> PyResult<(Bound<'py, PyAny>, Bound<'py, PyAny>, Bound<'py, PyAny>)> {
// Import the class from Python and create some subclasses
let datetime = py.import("datetime")?;
let locals = [(py_type, datetime.getattr(py_type)?)]
.into_py_dict(py)
.unwrap();
let make_subclass_py = CString::new(format!("class Subklass({}):\n pass", py_type))?;
let make_sub_subclass_py = ffi::c_str!("class SubSubklass(Subklass):\n pass");
py.run(&make_subclass_py, None, Some(&locals))?;
py.run(make_sub_subclass_py, None, Some(&locals))?;
// Construct an instance of the base class
let obj = py.eval(
&CString::new(format!("{}({})", py_type, args))?,
None,
Some(&locals),
)?;
// Construct an instance of the subclass
let sub_obj = py.eval(
&CString::new(format!("Subklass({})", args))?,
None,
Some(&locals),
)?;
// Construct an instance of the sub-subclass
let sub_sub_obj = py.eval(
&CString::new(format!("SubSubklass({})", args))?,
None,
Some(&locals),
)?;
Ok((obj, sub_obj, sub_sub_obj))
}
macro_rules! assert_check_exact {
($check_func:ident, $check_func_exact:ident, $obj: expr) => {
unsafe {
use pyo3::ffi::*;
assert!($check_func(($obj).as_ptr()) != 0);
assert!($check_func_exact(($obj).as_ptr()) != 0);
}
};
}
macro_rules! assert_check_only {
($check_func:ident, $check_func_exact:ident, $obj: expr) => {
unsafe {
use pyo3::ffi::*;
assert!($check_func(($obj).as_ptr()) != 0);
assert!($check_func_exact(($obj).as_ptr()) == 0);
}
};
}
#[test]
fn test_date_check() {
Python::with_gil(|py| {
let (obj, sub_obj, sub_sub_obj) = _get_subclasses(py, "date", "2018, 1, 1").unwrap();
unsafe { PyDateTime_IMPORT() }
assert_check_exact!(PyDate_Check, PyDate_CheckExact, obj);
assert_check_only!(PyDate_Check, PyDate_CheckExact, sub_obj);
assert_check_only!(PyDate_Check, PyDate_CheckExact, sub_sub_obj);
assert!(obj.is_instance_of::<PyDate>());
assert!(!obj.is_instance_of::<PyTime>());
assert!(!obj.is_instance_of::<PyDateTime>());
});
}
#[test]
fn test_time_check() {
Python::with_gil(|py| {
let (obj, sub_obj, sub_sub_obj) = _get_subclasses(py, "time", "12, 30, 15").unwrap();
unsafe { PyDateTime_IMPORT() }
assert_check_exact!(PyTime_Check, PyTime_CheckExact, obj);
assert_check_only!(PyTime_Check, PyTime_CheckExact, sub_obj);
assert_check_only!(PyTime_Check, PyTime_CheckExact, sub_sub_obj);
assert!(!obj.is_instance_of::<PyDate>());
assert!(obj.is_instance_of::<PyTime>());
assert!(!obj.is_instance_of::<PyDateTime>());
});
}
#[test]
fn test_datetime_check() {
Python::with_gil(|py| {
let (obj, sub_obj, sub_sub_obj) = _get_subclasses(py, "datetime", "2018, 1, 1, 13, 30, 15")
.map_err(|e| e.display(py))
.unwrap();
unsafe { PyDateTime_IMPORT() }
assert_check_only!(PyDate_Check, PyDate_CheckExact, obj);
assert_check_exact!(PyDateTime_Check, PyDateTime_CheckExact, obj);
assert_check_only!(PyDateTime_Check, PyDateTime_CheckExact, sub_obj);
assert_check_only!(PyDateTime_Check, PyDateTime_CheckExact, sub_sub_obj);
assert!(obj.is_instance_of::<PyDate>());
assert!(!obj.is_instance_of::<PyTime>());
assert!(obj.is_instance_of::<PyDateTime>());
});
}
#[test]
fn test_delta_check() {
Python::with_gil(|py| {
let (obj, sub_obj, sub_sub_obj) = _get_subclasses(py, "timedelta", "1, -3").unwrap();
unsafe { PyDateTime_IMPORT() }
assert_check_exact!(PyDelta_Check, PyDelta_CheckExact, obj);
assert_check_only!(PyDelta_Check, PyDelta_CheckExact, sub_obj);
assert_check_only!(PyDelta_Check, PyDelta_CheckExact, sub_sub_obj);
});
}
#[test]
fn test_datetime_utc() {
use assert_approx_eq::assert_approx_eq;
use pyo3::types::PyDateTime;
Python::with_gil(|py| {
let utc = timezone_utc(py);
let dt = PyDateTime::new(py, 2018, 1, 1, 0, 0, 0, 0, Some(&utc)).unwrap();
let locals = [("dt", dt)].into_py_dict(py).unwrap();
let offset: f32 = py
.eval(
ffi::c_str!("dt.utcoffset().total_seconds()"),
None,
Some(&locals),
)
.unwrap()
.extract()
.unwrap();
assert_approx_eq!(offset, 0f32);
});
}
static INVALID_DATES: &[(i32, u8, u8)] = &[
(-1, 1, 1),
(0, 1, 1),
(10000, 1, 1),
(2 << 30, 1, 1),
(2018, 0, 1),
(2018, 13, 1),
(2018, 1, 0),
(2017, 2, 29),
(2018, 1, 32),
];
static INVALID_TIMES: &[(u8, u8, u8, u32)] =
&[(25, 0, 0, 0), (255, 0, 0, 0), (0, 60, 0, 0), (0, 0, 61, 0)];
#[test]
fn test_pydate_out_of_bounds() {
use pyo3::types::PyDate;
Python::with_gil(|py| {
for val in INVALID_DATES {
let (year, month, day) = val;
let dt = PyDate::new(py, *year, *month, *day);
dt.unwrap_err();
}
});
}
#[test]
fn test_pytime_out_of_bounds() {
use pyo3::types::PyTime;
Python::with_gil(|py| {
for val in INVALID_TIMES {
let (hour, minute, second, microsecond) = val;
let dt = PyTime::new(py, *hour, *minute, *second, *microsecond, None);
dt.unwrap_err();
}
});
}
#[test]
fn test_pydatetime_out_of_bounds() {
use pyo3::types::PyDateTime;
use std::iter;
Python::with_gil(|py| {
let valid_time = (0, 0, 0, 0);
let valid_date = (2018, 1, 1);
let invalid_dates = INVALID_DATES.iter().zip(iter::repeat(&valid_time));
let invalid_times = iter::repeat(&valid_date).zip(INVALID_TIMES.iter());
let vals = invalid_dates.chain(invalid_times);
for val in vals {
let (date, time) = val;
let (year, month, day) = date;
let (hour, minute, second, microsecond) = time;
let dt = PyDateTime::new(
py,
*year,
*month,
*day,
*hour,
*minute,
*second,
*microsecond,
None,
);
dt.unwrap_err();
}
});
}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/test_append_to_inittab.rs | #![cfg(all(feature = "macros", not(PyPy)))]
use pyo3::prelude::*;
#[pyfunction]
fn foo() -> usize {
123
}
#[pymodule]
fn module_fn_with_functions(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(foo, m)?)?;
Ok(())
}
#[pymodule]
mod module_mod_with_functions {
#[pymodule_export]
use super::foo;
}
#[cfg(not(PyPy))]
#[test]
fn test_module_append_to_inittab() {
use pyo3::{append_to_inittab, ffi};
append_to_inittab!(module_fn_with_functions);
append_to_inittab!(module_mod_with_functions);
Python::with_gil(|py| {
py.run(
ffi::c_str!(
r#"
import module_fn_with_functions
assert module_fn_with_functions.foo() == 123
"#
),
None,
None,
)
.map_err(|e| e.display(py))
.unwrap();
});
Python::with_gil(|py| {
py.run(
ffi::c_str!(
r#"
import module_mod_with_functions
assert module_mod_with_functions.foo() == 123
"#
),
None,
None,
)
.map_err(|e| e.display(py))
.unwrap();
});
}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/test_field_cfg.rs | #![cfg(feature = "macros")]
use pyo3::prelude::*;
#[pyclass]
struct CfgClass {
#[pyo3(get, set)]
#[cfg(any())]
pub a: u32,
#[pyo3(get, set)]
// This is always true
#[cfg(any(
target_family = "unix",
target_family = "windows",
target_family = "wasm"
))]
pub b: u32,
}
#[pyclass(eq, eq_int)]
#[derive(PartialEq)]
enum CfgSimpleEnum {
#[cfg(any())]
DisabledVariant,
#[cfg(not(any()))]
EnabledVariant,
}
#[test]
fn test_cfg() {
Python::with_gil(|py| {
let cfg = CfgClass { b: 3 };
let py_cfg = Py::new(py, cfg).unwrap();
assert!(py_cfg.bind(py).getattr("a").is_err());
let b: u32 = py_cfg.bind(py).getattr("b").unwrap().extract().unwrap();
assert_eq!(b, 3);
});
}
#[test]
fn test_cfg_simple_enum() {
Python::with_gil(|py| {
let simple = py.get_type::<CfgSimpleEnum>();
pyo3::py_run!(
py,
simple,
r#"
assert hasattr(simple, "EnabledVariant")
assert not hasattr(simple, "DisabledVariant")
"#
);
})
}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/test_bytes.rs | #![cfg(feature = "macros")]
use pyo3::prelude::*;
use pyo3::types::PyBytes;
#[path = "../src/tests/common.rs"]
mod common;
#[pyfunction]
fn bytes_pybytes_conversion(bytes: &[u8]) -> &[u8] {
bytes
}
#[test]
fn test_pybytes_bytes_conversion() {
Python::with_gil(|py| {
let f = wrap_pyfunction!(bytes_pybytes_conversion)(py).unwrap();
py_assert!(py, f, "f(b'Hello World') == b'Hello World'");
});
}
#[pyfunction]
fn bytes_vec_conversion(py: Python<'_>, bytes: Vec<u8>) -> Bound<'_, PyBytes> {
PyBytes::new(py, bytes.as_slice())
}
#[test]
fn test_pybytes_vec_conversion() {
Python::with_gil(|py| {
let f = wrap_pyfunction!(bytes_vec_conversion)(py).unwrap();
py_assert!(py, f, "f(b'Hello World') == b'Hello World'");
});
}
#[test]
fn test_bytearray_vec_conversion() {
Python::with_gil(|py| {
let f = wrap_pyfunction!(bytes_vec_conversion)(py).unwrap();
py_assert!(py, f, "f(bytearray(b'Hello World')) == b'Hello World'");
});
}
#[test]
fn test_py_as_bytes() {
let pyobj: pyo3::Py<pyo3::types::PyBytes> =
Python::with_gil(|py| pyo3::types::PyBytes::new(py, b"abc").unbind());
let data = Python::with_gil(|py| pyobj.as_bytes(py));
assert_eq!(data, b"abc");
Python::with_gil(move |_py| drop(pyobj));
}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/test_datetime_import.rs | #![cfg(not(Py_LIMITED_API))]
use pyo3::{prelude::*, types::PyDate};
use tempfile::Builder;
#[test]
#[should_panic(expected = "module 'datetime' has no attribute 'datetime_CAPI'")]
fn test_bad_datetime_module_panic() {
// Create an empty temporary directory
// with an empty "datetime" module which we'll put on the sys.path
let tmpdir = Builder::new()
.prefix("pyo3_test_data_check")
.tempdir()
.unwrap();
std::fs::File::create(tmpdir.path().join("datetime.py")).unwrap();
Python::with_gil(|py: Python<'_>| {
let sys = py.import("sys").unwrap();
sys.getattr("path")
.unwrap()
.call_method1("insert", (0, tmpdir.path()))
.unwrap();
// This should panic because the "datetime" module is empty
PyDate::new(py, 2018, 1, 1).unwrap();
});
tmpdir.close().unwrap();
}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/test_class_comparisons.rs | #![cfg(feature = "macros")]
use pyo3::prelude::*;
#[path = "../src/tests/common.rs"]
mod common;
#[pyclass(eq)]
#[derive(Debug, Clone, PartialEq)]
pub enum MyEnum {
Variant,
OtherVariant,
}
#[pyclass(eq, ord)]
#[derive(Debug, PartialEq, Eq, Clone, PartialOrd)]
pub enum MyEnumOrd {
Variant,
OtherVariant,
}
#[test]
fn test_enum_eq_enum() {
Python::with_gil(|py| {
let var1 = Py::new(py, MyEnum::Variant).unwrap();
let var2 = Py::new(py, MyEnum::Variant).unwrap();
let other_var = Py::new(py, MyEnum::OtherVariant).unwrap();
py_assert!(py, var1 var2, "var1 == var2");
py_assert!(py, var1 other_var, "var1 != other_var");
py_assert!(py, var1 var2, "(var1 != var2) == False");
})
}
#[test]
fn test_enum_eq_incomparable() {
Python::with_gil(|py| {
let var1 = Py::new(py, MyEnum::Variant).unwrap();
py_assert!(py, var1, "(var1 == 'foo') == False");
py_assert!(py, var1, "(var1 != 'foo') == True");
})
}
#[test]
fn test_enum_ord_comparable_opt_in_only() {
Python::with_gil(|py| {
let var1 = Py::new(py, MyEnum::Variant).unwrap();
let var2 = Py::new(py, MyEnum::OtherVariant).unwrap();
// ordering on simple enums if opt in only, thus raising an error below
py_expect_exception!(py, var1 var2, "(var1 > var2) == False", PyTypeError);
})
}
#[test]
fn test_simple_enum_ord_comparable() {
Python::with_gil(|py| {
let var1 = Py::new(py, MyEnumOrd::Variant).unwrap();
let var2 = Py::new(py, MyEnumOrd::OtherVariant).unwrap();
let var3 = Py::new(py, MyEnumOrd::OtherVariant).unwrap();
py_assert!(py, var1 var2, "(var1 > var2) == False");
py_assert!(py, var1 var2, "(var1 < var2) == True");
py_assert!(py, var1 var2, "(var1 >= var2) == False");
py_assert!(py, var2 var3, "(var3 >= var2) == True");
py_assert!(py, var1 var2, "(var1 <= var2) == True");
})
}
#[pyclass(eq, ord)]
#[derive(Debug, PartialEq, Eq, Clone, PartialOrd)]
pub enum MyComplexEnumOrd {
Variant(i32),
OtherVariant(String),
}
#[pyclass(eq, ord)]
#[derive(Debug, PartialEq, Eq, Clone, PartialOrd)]
pub enum MyComplexEnumOrd2 {
Variant { msg: String, idx: u32 },
OtherVariant { name: String, idx: u32 },
}
#[test]
fn test_complex_enum_ord_comparable() {
Python::with_gil(|py| {
let var1 = Py::new(py, MyComplexEnumOrd::Variant(-2)).unwrap();
let var2 = Py::new(py, MyComplexEnumOrd::Variant(5)).unwrap();
let var3 = Py::new(py, MyComplexEnumOrd::OtherVariant("a".to_string())).unwrap();
let var4 = Py::new(py, MyComplexEnumOrd::OtherVariant("b".to_string())).unwrap();
py_assert!(py, var1 var2, "(var1 > var2) == False");
py_assert!(py, var1 var2, "(var1 < var2) == True");
py_assert!(py, var1 var2, "(var1 >= var2) == False");
py_assert!(py, var1 var2, "(var1 <= var2) == True");
py_assert!(py, var1 var3, "(var1 >= var3) == False");
py_assert!(py, var1 var3, "(var1 <= var3) == True");
py_assert!(py, var3 var4, "(var3 >= var4) == False");
py_assert!(py, var3 var4, "(var3 <= var4) == True");
let var5 = Py::new(
py,
MyComplexEnumOrd2::Variant {
msg: "hello".to_string(),
idx: 1,
},
)
.unwrap();
let var6 = Py::new(
py,
MyComplexEnumOrd2::Variant {
msg: "hello".to_string(),
idx: 1,
},
)
.unwrap();
let var7 = Py::new(
py,
MyComplexEnumOrd2::Variant {
msg: "goodbye".to_string(),
idx: 7,
},
)
.unwrap();
let var8 = Py::new(
py,
MyComplexEnumOrd2::Variant {
msg: "about".to_string(),
idx: 0,
},
)
.unwrap();
let var9 = Py::new(
py,
MyComplexEnumOrd2::OtherVariant {
name: "albert".to_string(),
idx: 1,
},
)
.unwrap();
py_assert!(py, var5 var6, "(var5 == var6) == True");
py_assert!(py, var5 var6, "(var5 <= var6) == True");
py_assert!(py, var6 var7, "(var6 <= var7) == False");
py_assert!(py, var6 var7, "(var6 >= var7) == True");
py_assert!(py, var5 var8, "(var5 > var8) == True");
py_assert!(py, var8 var9, "(var9 > var8) == True");
})
}
#[pyclass(eq, ord)]
#[derive(Debug, PartialEq, Eq, Clone, PartialOrd)]
pub struct Point {
x: i32,
y: i32,
z: i32,
}
#[test]
fn test_struct_numeric_ord_comparable() {
Python::with_gil(|py| {
let var1 = Py::new(py, Point { x: 10, y: 2, z: 3 }).unwrap();
let var2 = Py::new(py, Point { x: 2, y: 2, z: 3 }).unwrap();
let var3 = Py::new(py, Point { x: 1, y: 22, z: 4 }).unwrap();
let var4 = Py::new(py, Point { x: 1, y: 3, z: 4 }).unwrap();
let var5 = Py::new(py, Point { x: 1, y: 3, z: 4 }).unwrap();
py_assert!(py, var1 var2, "(var1 > var2) == True");
py_assert!(py, var1 var2, "(var1 <= var2) == False");
py_assert!(py, var2 var3, "(var3 < var2) == True");
py_assert!(py, var3 var4, "(var3 > var4) == True");
py_assert!(py, var4 var5, "(var4 == var5) == True");
py_assert!(py, var3 var5, "(var3 != var5) == True");
})
}
#[pyclass(eq, ord)]
#[derive(Debug, PartialEq, Eq, Clone, PartialOrd)]
pub struct Person {
surname: String,
given_name: String,
}
#[test]
fn test_struct_string_ord_comparable() {
Python::with_gil(|py| {
let var1 = Py::new(
py,
Person {
surname: "zzz".to_string(),
given_name: "bob".to_string(),
},
)
.unwrap();
let var2 = Py::new(
py,
Person {
surname: "aaa".to_string(),
given_name: "sally".to_string(),
},
)
.unwrap();
let var3 = Py::new(
py,
Person {
surname: "eee".to_string(),
given_name: "qqq".to_string(),
},
)
.unwrap();
let var4 = Py::new(
py,
Person {
surname: "ddd".to_string(),
given_name: "aaa".to_string(),
},
)
.unwrap();
py_assert!(py, var1 var2, "(var1 > var2) == True");
py_assert!(py, var1 var2, "(var1 <= var2) == False");
py_assert!(py, var1 var3, "(var1 >= var3) == True");
py_assert!(py, var2 var3, "(var2 >= var3) == False");
py_assert!(py, var3 var4, "(var3 >= var4) == True");
py_assert!(py, var3 var4, "(var3 != var4) == True");
})
}
#[pyclass(eq, ord)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Record {
name: String,
title: String,
idx: u32,
}
impl PartialOrd for Record {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.idx.partial_cmp(&other.idx).unwrap())
}
}
#[test]
fn test_struct_custom_ord_comparable() {
Python::with_gil(|py| {
let var1 = Py::new(
py,
Record {
name: "zzz".to_string(),
title: "bbb".to_string(),
idx: 9,
},
)
.unwrap();
let var2 = Py::new(
py,
Record {
name: "ddd".to_string(),
title: "aaa".to_string(),
idx: 1,
},
)
.unwrap();
let var3 = Py::new(
py,
Record {
name: "vvv".to_string(),
title: "ggg".to_string(),
idx: 19,
},
)
.unwrap();
let var4 = Py::new(
py,
Record {
name: "vvv".to_string(),
title: "ggg".to_string(),
idx: 19,
},
)
.unwrap();
py_assert!(py, var1 var2, "(var1 > var2) == True");
py_assert!(py, var1 var2, "(var1 <= var2) == False");
py_assert!(py, var1 var3, "(var1 >= var3) == False");
py_assert!(py, var2 var3, "(var2 >= var3) == False");
py_assert!(py, var3 var4, "(var3 == var4) == True");
py_assert!(py, var2 var4, "(var2 != var4) == True");
})
}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/test_intopyobject.rs | #![cfg(feature = "macros")]
use pyo3::types::{PyDict, PyString};
use pyo3::{prelude::*, IntoPyObject};
use std::collections::HashMap;
use std::hash::Hash;
#[macro_use]
#[path = "../src/tests/common.rs"]
mod common;
#[derive(Debug, IntoPyObject)]
pub struct A<'py> {
s: String,
t: Bound<'py, PyString>,
p: Bound<'py, PyAny>,
}
#[test]
fn test_named_fields_struct() {
Python::with_gil(|py| {
let a = A {
s: "Hello".into(),
t: PyString::new(py, "World"),
p: 42i32.into_pyobject(py).unwrap().into_any(),
};
let pya = a.into_pyobject(py).unwrap();
assert_eq!(
pya.get_item("s")
.unwrap()
.unwrap()
.downcast::<PyString>()
.unwrap(),
"Hello"
);
assert_eq!(
pya.get_item("t")
.unwrap()
.unwrap()
.downcast::<PyString>()
.unwrap(),
"World"
);
assert_eq!(
pya.get_item("p")
.unwrap()
.unwrap()
.extract::<i32>()
.unwrap(),
42
);
});
}
#[derive(Debug, IntoPyObject)]
#[pyo3(transparent)]
pub struct B<'a> {
test: &'a str,
}
#[test]
fn test_transparent_named_field_struct() {
Python::with_gil(|py| {
let pyb = B { test: "test" }.into_pyobject(py).unwrap();
let b = pyb.extract::<String>().unwrap();
assert_eq!(b, "test");
});
}
#[derive(Debug, IntoPyObject)]
#[pyo3(transparent)]
pub struct D<T> {
test: T,
}
#[test]
fn test_generic_transparent_named_field_struct() {
Python::with_gil(|py| {
let pyd = D {
test: String::from("test"),
}
.into_pyobject(py)
.unwrap();
let d = pyd.extract::<String>().unwrap();
assert_eq!(d, "test");
let pyd = D { test: 1usize }.into_pyobject(py).unwrap();
let d = pyd.extract::<usize>().unwrap();
assert_eq!(d, 1);
});
}
#[derive(Debug, IntoPyObject)]
pub struct GenericWithBound<K: Hash + Eq, V>(HashMap<K, V>);
#[test]
fn test_generic_with_bound() {
Python::with_gil(|py| {
let mut hash_map = HashMap::<String, i32>::new();
hash_map.insert("1".into(), 1);
hash_map.insert("2".into(), 2);
let map = GenericWithBound(hash_map).into_pyobject(py).unwrap();
assert_eq!(map.len(), 2);
assert_eq!(
map.get_item("1")
.unwrap()
.unwrap()
.extract::<i32>()
.unwrap(),
1
);
assert_eq!(
map.get_item("2")
.unwrap()
.unwrap()
.extract::<i32>()
.unwrap(),
2
);
assert!(map.get_item("3").unwrap().is_none());
});
}
#[derive(Debug, IntoPyObject)]
pub struct Tuple(String, usize);
#[test]
fn test_tuple_struct() {
Python::with_gil(|py| {
let tup = Tuple(String::from("test"), 1).into_pyobject(py).unwrap();
assert!(tup.extract::<(usize, String)>().is_err());
let tup = tup.extract::<(String, usize)>().unwrap();
assert_eq!(tup.0, "test");
assert_eq!(tup.1, 1);
});
}
#[derive(Debug, IntoPyObject)]
pub struct TransparentTuple(String);
#[test]
fn test_transparent_tuple_struct() {
Python::with_gil(|py| {
let tup = TransparentTuple(String::from("test"))
.into_pyobject(py)
.unwrap();
assert!(tup.extract::<(String,)>().is_err());
let tup = tup.extract::<String>().unwrap();
assert_eq!(tup, "test");
});
}
#[derive(Debug, IntoPyObject)]
pub enum Foo<'py> {
TupleVar(usize, String),
StructVar {
test: Bound<'py, PyString>,
},
#[pyo3(transparent)]
TransparentTuple(usize),
#[pyo3(transparent)]
TransparentStructVar {
a: Option<String>,
},
}
#[test]
fn test_enum() {
Python::with_gil(|py| {
let foo = Foo::TupleVar(1, "test".into()).into_pyobject(py).unwrap();
assert_eq!(
foo.extract::<(usize, String)>().unwrap(),
(1, String::from("test"))
);
let foo = Foo::StructVar {
test: PyString::new(py, "test"),
}
.into_pyobject(py)
.unwrap()
.downcast_into::<PyDict>()
.unwrap();
assert_eq!(
foo.get_item("test")
.unwrap()
.unwrap()
.downcast_into::<PyString>()
.unwrap(),
"test"
);
let foo = Foo::TransparentTuple(1).into_pyobject(py).unwrap();
assert_eq!(foo.extract::<usize>().unwrap(), 1);
let foo = Foo::TransparentStructVar { a: None }
.into_pyobject(py)
.unwrap();
assert!(foo.is_none());
});
}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/test_getter_setter.rs | #![cfg(feature = "macros")]
use std::cell::Cell;
use pyo3::prelude::*;
use pyo3::py_run;
use pyo3::types::PyString;
use pyo3::types::{IntoPyDict, PyList};
#[path = "../src/tests/common.rs"]
mod common;
#[pyclass]
struct ClassWithProperties {
num: i32,
}
#[pymethods]
impl ClassWithProperties {
fn get_num(&self) -> i32 {
self.num
}
#[getter(DATA)]
/// a getter for data
fn get_data(&self) -> i32 {
self.num
}
#[setter(DATA)]
fn set_data(&mut self, value: i32) {
self.num = value;
}
#[getter]
/// a getter with a type un-wrapped by PyResult
fn get_unwrapped(&self) -> i32 {
self.num
}
#[setter]
fn set_unwrapped(&mut self, value: i32) {
self.num = value;
}
#[setter]
fn set_from_len(&mut self, #[pyo3(from_py_with = "extract_len")] value: i32) {
self.num = value;
}
#[setter]
fn set_from_any(&mut self, value: &Bound<'_, PyAny>) -> PyResult<()> {
self.num = value.extract()?;
Ok(())
}
#[getter]
fn get_data_list<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyList>> {
PyList::new(py, [self.num])
}
}
fn extract_len(any: &Bound<'_, PyAny>) -> PyResult<i32> {
any.len().map(|len| len as i32)
}
#[test]
fn class_with_properties() {
Python::with_gil(|py| {
let inst = Py::new(py, ClassWithProperties { num: 10 }).unwrap();
py_run!(py, inst, "assert inst.get_num() == 10");
py_run!(py, inst, "assert inst.get_num() == inst.DATA");
py_run!(py, inst, "inst.DATA = 20");
py_run!(py, inst, "assert inst.get_num() == 20 == inst.DATA");
py_expect_exception!(py, inst, "del inst.DATA", PyAttributeError);
py_run!(py, inst, "assert inst.get_num() == inst.unwrapped == 20");
py_run!(py, inst, "inst.unwrapped = 42");
py_run!(py, inst, "assert inst.get_num() == inst.unwrapped == 42");
py_run!(py, inst, "assert inst.data_list == [42]");
py_run!(py, inst, "inst.from_len = [0, 0, 0]");
py_run!(py, inst, "assert inst.get_num() == 3");
py_run!(py, inst, "inst.from_any = 15");
py_run!(py, inst, "assert inst.get_num() == 15");
let d = [("C", py.get_type::<ClassWithProperties>())]
.into_py_dict(py)
.unwrap();
py_assert!(py, *d, "C.DATA.__doc__ == 'a getter for data'");
});
}
#[pyclass]
struct GetterSetter {
#[pyo3(get, set)]
num: i32,
#[pyo3(get, set)]
text: String,
}
#[pymethods]
impl GetterSetter {
fn get_num2(&self) -> i32 {
self.num
}
}
#[test]
fn getter_setter_autogen() {
Python::with_gil(|py| {
let inst = Py::new(
py,
GetterSetter {
num: 10,
text: "Hello".to_string(),
},
)
.unwrap();
py_run!(py, inst, "assert inst.num == 10");
py_run!(py, inst, "inst.num = 20; assert inst.num == 20");
py_run!(
py,
inst,
"assert inst.text == 'Hello'; inst.text = 'There'; assert inst.text == 'There'"
);
});
}
#[pyclass]
struct RefGetterSetter {
num: i32,
}
#[pymethods]
impl RefGetterSetter {
#[getter]
fn get_num(slf: PyRef<'_, Self>) -> i32 {
slf.num
}
#[setter]
fn set_num(mut slf: PyRefMut<'_, Self>, value: i32) {
slf.num = value;
}
}
#[test]
fn ref_getter_setter() {
// Regression test for #837
Python::with_gil(|py| {
let inst = Py::new(py, RefGetterSetter { num: 10 }).unwrap();
py_run!(py, inst, "assert inst.num == 10");
py_run!(py, inst, "inst.num = 20; assert inst.num == 20");
});
}
#[pyclass]
struct TupleClassGetterSetter(i32);
#[pymethods]
impl TupleClassGetterSetter {
#[getter(num)]
fn get_num(&self) -> i32 {
self.0
}
#[setter(num)]
fn set_num(&mut self, value: i32) {
self.0 = value;
}
}
#[test]
fn tuple_struct_getter_setter() {
Python::with_gil(|py| {
let inst = Py::new(py, TupleClassGetterSetter(10)).unwrap();
py_assert!(py, inst, "inst.num == 10");
py_run!(py, inst, "inst.num = 20");
py_assert!(py, inst, "inst.num == 20");
});
}
#[pyclass(get_all, set_all)]
struct All {
num: i32,
}
#[test]
fn get_set_all() {
Python::with_gil(|py| {
let inst = Py::new(py, All { num: 10 }).unwrap();
py_run!(py, inst, "assert inst.num == 10");
py_run!(py, inst, "inst.num = 20; assert inst.num == 20");
});
}
#[pyclass(get_all)]
struct All2 {
#[pyo3(set)]
num: i32,
}
#[test]
fn get_all_and_set() {
Python::with_gil(|py| {
let inst = Py::new(py, All2 { num: 10 }).unwrap();
py_run!(py, inst, "assert inst.num == 10");
py_run!(py, inst, "inst.num = 20; assert inst.num == 20");
});
}
#[pyclass(unsendable)]
struct CellGetterSetter {
#[pyo3(get, set)]
cell_inner: Cell<i32>,
}
#[test]
fn cell_getter_setter() {
let c = CellGetterSetter {
cell_inner: Cell::new(10),
};
Python::with_gil(|py| {
let inst = Py::new(py, c).unwrap();
let cell = Cell::new(20i32).into_pyobject(py).unwrap();
py_run!(py, cell, "assert cell == 20");
py_run!(py, inst, "assert inst.cell_inner == 10");
py_run!(
py,
inst,
"inst.cell_inner = 20; assert inst.cell_inner == 20"
);
});
}
#[test]
fn borrowed_value_with_lifetime_of_self() {
#[pyclass]
struct BorrowedValue {}
#[pymethods]
impl BorrowedValue {
#[getter]
fn value(&self) -> &str {
"value"
}
}
Python::with_gil(|py| {
let inst = Py::new(py, BorrowedValue {}).unwrap();
py_run!(py, inst, "assert inst.value == 'value'");
});
}
#[test]
fn frozen_py_field_get() {
#[pyclass(frozen)]
struct FrozenPyField {
#[pyo3(get)]
value: Py<PyString>,
}
Python::with_gil(|py| {
let inst = Py::new(
py,
FrozenPyField {
value: "value".into_pyobject(py).unwrap().unbind(),
},
)
.unwrap();
py_run!(py, inst, "assert inst.value == 'value'");
});
}
#[test]
fn test_optional_setter() {
#[pyclass]
struct SimpleClass {
field: Option<u32>,
}
#[pymethods]
impl SimpleClass {
#[getter]
fn get_field(&self) -> Option<u32> {
self.field
}
#[setter]
fn set_field(&mut self, field: Option<u32>) {
self.field = field;
}
}
Python::with_gil(|py| {
let instance = Py::new(py, SimpleClass { field: None }).unwrap();
py_run!(py, instance, "assert instance.field is None");
py_run!(
py,
instance,
"instance.field = 42; assert instance.field == 42"
);
py_run!(
py,
instance,
"instance.field = None; assert instance.field is None"
);
})
}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/test_super.rs | #![cfg(all(feature = "macros", not(PyPy)))]
use pyo3::{prelude::*, types::PySuper};
#[pyclass(subclass)]
struct BaseClass {
val1: usize,
}
#[pymethods]
impl BaseClass {
#[new]
fn new() -> Self {
BaseClass { val1: 10 }
}
pub fn method(&self) -> usize {
self.val1
}
}
#[pyclass(extends=BaseClass)]
struct SubClass {}
#[pymethods]
impl SubClass {
#[new]
fn new() -> (Self, BaseClass) {
(SubClass {}, BaseClass::new())
}
fn method<'py>(self_: &Bound<'py, Self>) -> PyResult<Bound<'py, PyAny>> {
let super_ = self_.py_super()?;
super_.call_method("method", (), None)
}
fn method_super_new<'py>(self_: &Bound<'py, Self>) -> PyResult<Bound<'py, PyAny>> {
let super_ = PySuper::new(&self_.get_type(), self_)?;
super_.call_method("method", (), None)
}
}
#[test]
fn test_call_super_method() {
Python::with_gil(|py| {
let cls = py.get_type::<SubClass>();
pyo3::py_run!(
py,
cls,
r#"
obj = cls()
assert obj.method() == 10
assert obj.method_super_new() == 10
"#
)
});
}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/test_anyhow.rs | #![cfg(feature = "anyhow")]
use pyo3::{ffi, wrap_pyfunction};
#[test]
fn test_anyhow_py_function_ok_result() {
use pyo3::{py_run, pyfunction, Python};
#[pyfunction]
#[allow(clippy::unnecessary_wraps)]
fn produce_ok_result() -> anyhow::Result<String> {
Ok(String::from("OK buddy"))
}
Python::with_gil(|py| {
let func = wrap_pyfunction!(produce_ok_result)(py).unwrap();
py_run!(
py,
func,
r#"
func()
"#
);
});
}
#[test]
fn test_anyhow_py_function_err_result() {
use pyo3::prelude::PyDictMethods;
use pyo3::{pyfunction, types::PyDict, Python};
#[pyfunction]
fn produce_err_result() -> anyhow::Result<String> {
anyhow::bail!("error time")
}
Python::with_gil(|py| {
let func = wrap_pyfunction!(produce_err_result)(py).unwrap();
let locals = PyDict::new(py);
locals.set_item("func", func).unwrap();
py.run(
ffi::c_str!(
r#"
func()
"#
),
None,
Some(&locals),
)
.unwrap_err();
});
}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/test_class_basics.rs | #![cfg(feature = "macros")]
use pyo3::prelude::*;
use pyo3::types::PyType;
use pyo3::{py_run, PyClass};
#[path = "../src/tests/common.rs"]
mod common;
#[pyclass]
struct EmptyClass {}
#[test]
fn empty_class() {
Python::with_gil(|py| {
let typeobj = py.get_type::<EmptyClass>();
// By default, don't allow creating instances from python.
assert!(typeobj.call((), None).is_err());
py_assert!(py, typeobj, "typeobj.__name__ == 'EmptyClass'");
});
}
#[pyclass]
struct UnitClass;
#[test]
fn unit_class() {
Python::with_gil(|py| {
let typeobj = py.get_type::<UnitClass>();
// By default, don't allow creating instances from python.
assert!(typeobj.call((), None).is_err());
py_assert!(py, typeobj, "typeobj.__name__ == 'UnitClass'");
});
}
/// Line1
///Line2
/// Line3
// this is not doc string
#[pyclass]
struct ClassWithDocs {
/// Property field
#[pyo3(get, set)]
value: i32,
/// Read-only property field
#[pyo3(get)]
readonly: i32,
/// Write-only property field
#[pyo3(set)]
#[allow(dead_code)] // Rust detects field is never read
writeonly: i32,
}
#[test]
fn class_with_docstr() {
Python::with_gil(|py| {
let typeobj = py.get_type::<ClassWithDocs>();
py_run!(
py,
typeobj,
"assert typeobj.__doc__ == 'Line1\\nLine2\\n Line3'"
);
py_run!(
py,
typeobj,
"assert typeobj.value.__doc__ == 'Property field'"
);
py_run!(
py,
typeobj,
"assert typeobj.readonly.__doc__ == 'Read-only property field'"
);
py_run!(
py,
typeobj,
"assert typeobj.writeonly.__doc__ == 'Write-only property field'"
);
});
}
#[pyclass(name = "CustomName")]
struct EmptyClass2 {}
#[pymethods]
impl EmptyClass2 {
#[pyo3(name = "custom_fn")]
fn bar(&self) {}
#[staticmethod]
#[pyo3(name = "custom_static")]
fn bar_static() {}
#[getter]
#[pyo3(name = "custom_getter")]
fn foo(&self) -> i32 {
5
}
}
#[test]
fn custom_names() {
Python::with_gil(|py| {
let typeobj = py.get_type::<EmptyClass2>();
py_assert!(py, typeobj, "typeobj.__name__ == 'CustomName'");
py_assert!(py, typeobj, "typeobj.custom_fn.__name__ == 'custom_fn'");
py_assert!(
py,
typeobj,
"typeobj.custom_static.__name__ == 'custom_static'"
);
py_assert!(
py,
typeobj,
"typeobj.custom_getter.__name__ == 'custom_getter'"
);
py_assert!(py, typeobj, "not hasattr(typeobj, 'bar')");
py_assert!(py, typeobj, "not hasattr(typeobj, 'bar_static')");
py_assert!(py, typeobj, "not hasattr(typeobj, 'foo')");
});
}
#[pyclass(name = "loop")]
struct ClassRustKeywords {
#[pyo3(name = "unsafe", get, set)]
unsafe_variable: usize,
}
#[pymethods]
impl ClassRustKeywords {
#[pyo3(name = "struct")]
fn struct_method(&self) {}
#[staticmethod]
#[pyo3(name = "type")]
fn type_method() {}
}
#[test]
fn keyword_names() {
Python::with_gil(|py| {
let typeobj = py.get_type::<ClassRustKeywords>();
py_assert!(py, typeobj, "typeobj.__name__ == 'loop'");
py_assert!(py, typeobj, "typeobj.struct.__name__ == 'struct'");
py_assert!(py, typeobj, "typeobj.type.__name__ == 'type'");
py_assert!(py, typeobj, "typeobj.unsafe.__name__ == 'unsafe'");
py_assert!(py, typeobj, "not hasattr(typeobj, 'unsafe_variable')");
py_assert!(py, typeobj, "not hasattr(typeobj, 'struct_method')");
py_assert!(py, typeobj, "not hasattr(typeobj, 'type_method')");
});
}
#[pyclass]
struct RawIdents {
#[pyo3(get, set)]
r#type: i64,
}
#[pymethods]
impl RawIdents {
fn r#fn(&self) {}
}
#[test]
fn test_raw_idents() {
Python::with_gil(|py| {
let typeobj = py.get_type::<RawIdents>();
py_assert!(py, typeobj, "not hasattr(typeobj, 'r#fn')");
py_assert!(py, typeobj, "hasattr(typeobj, 'fn')");
py_assert!(py, typeobj, "hasattr(typeobj, 'type')");
});
}
#[pyclass]
struct EmptyClassInModule {}
// Ignored because heap types do not show up as being in builtins, instead they
// raise AttributeError:
// https://github.com/python/cpython/blob/v3.11.1/Objects/typeobject.c#L541-L570
#[test]
#[ignore]
fn empty_class_in_module() {
Python::with_gil(|py| {
let module = PyModule::new(py, "test_module.nested").unwrap();
module.add_class::<EmptyClassInModule>().unwrap();
let ty = module.getattr("EmptyClassInModule").unwrap();
assert_eq!(
ty.getattr("__name__").unwrap().extract::<String>().unwrap(),
"EmptyClassInModule"
);
let module: String = ty.getattr("__module__").unwrap().extract().unwrap();
// Rationale: The class can be added to many modules, but will only be initialized once.
// We currently have no way of determining a canonical module, so builtins is better
// than using whatever calls init first.
assert_eq!(module, "builtins");
});
}
#[pyclass]
struct ClassWithObjectField {
// It used to be that PyObject was not supported with (get, set)
// - this test is just ensuring it compiles.
#[pyo3(get, set)]
value: PyObject,
}
#[pymethods]
impl ClassWithObjectField {
#[new]
fn new(value: PyObject) -> ClassWithObjectField {
Self { value }
}
}
#[test]
fn class_with_object_field() {
Python::with_gil(|py| {
let ty = py.get_type::<ClassWithObjectField>();
py_assert!(py, ty, "ty(5).value == 5");
py_assert!(py, ty, "ty(None).value == None");
});
}
#[pyclass(frozen, eq, hash)]
#[derive(PartialEq, Hash)]
struct ClassWithHash {
value: usize,
}
#[test]
fn class_with_hash() {
Python::with_gil(|py| {
use pyo3::types::IntoPyDict;
let class = ClassWithHash { value: 42 };
let hash = {
use std::hash::{Hash, Hasher};
let mut hasher = std::collections::hash_map::DefaultHasher::new();
class.hash(&mut hasher);
hasher.finish() as isize
};
let env = [
("obj", Py::new(py, class).unwrap().into_any()),
("hsh", hash.into_pyobject(py).unwrap().into_any().unbind()),
]
.into_py_dict(py)
.unwrap();
py_assert!(py, *env, "hash(obj) == hsh");
});
}
#[pyclass(unsendable, subclass)]
struct UnsendableBase {
value: std::rc::Rc<usize>,
}
#[pymethods]
impl UnsendableBase {
#[new]
fn new(value: usize) -> UnsendableBase {
Self {
value: std::rc::Rc::new(value),
}
}
#[getter]
fn value(&self) -> usize {
*self.value
}
}
#[pyclass(extends=UnsendableBase)]
struct UnsendableChild {}
#[pymethods]
impl UnsendableChild {
#[new]
fn new(value: usize) -> (UnsendableChild, UnsendableBase) {
(UnsendableChild {}, UnsendableBase::new(value))
}
}
fn test_unsendable<T: PyClass + 'static>() -> PyResult<()> {
let (keep_obj_here, obj) = Python::with_gil(|py| -> PyResult<_> {
let obj: Py<T> = PyType::new::<T>(py).call1((5,))?.extract()?;
// Accessing the value inside this thread should not panic
let caught_panic =
std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| -> PyResult<_> {
assert_eq!(obj.getattr(py, "value")?.extract::<usize>(py)?, 5);
Ok(())
}))
.is_err();
assert!(!caught_panic);
Ok((obj.clone_ref(py), obj))
})?;
let caught_panic = std::thread::spawn(move || {
// This access must panic
Python::with_gil(move |py| {
obj.borrow(py);
});
})
.join();
Python::with_gil(|_py| drop(keep_obj_here));
if let Err(err) = caught_panic {
if let Some(msg) = err.downcast_ref::<String>() {
panic!("{}", msg);
}
}
Ok(())
}
/// If a class is marked as `unsendable`, it panics when accessed by another thread.
#[test]
#[cfg_attr(target_arch = "wasm32", ignore)]
#[should_panic(
expected = "test_class_basics::UnsendableBase is unsendable, but sent to another thread"
)]
fn panic_unsendable_base() {
test_unsendable::<UnsendableBase>().unwrap();
}
#[test]
#[cfg_attr(target_arch = "wasm32", ignore)]
#[should_panic(
expected = "test_class_basics::UnsendableBase is unsendable, but sent to another thread"
)]
fn panic_unsendable_child() {
test_unsendable::<UnsendableChild>().unwrap();
}
fn get_length(obj: &Bound<'_, PyAny>) -> PyResult<usize> {
let length = obj.len()?;
Ok(length)
}
fn is_even(obj: &Bound<'_, PyAny>) -> PyResult<bool> {
obj.extract::<i32>().map(|i| i % 2 == 0)
}
#[pyclass]
struct ClassWithFromPyWithMethods {}
#[pymethods]
impl ClassWithFromPyWithMethods {
fn instance_method(&self, #[pyo3(from_py_with = "get_length")] argument: usize) -> usize {
argument
}
#[classmethod]
fn classmethod(
_cls: &Bound<'_, PyType>,
#[pyo3(from_py_with = "Bound::<'_, PyAny>::len")] argument: usize,
) -> usize {
argument
}
#[staticmethod]
fn staticmethod(#[pyo3(from_py_with = "get_length")] argument: usize) -> usize {
argument
}
fn __contains__(&self, #[pyo3(from_py_with = "is_even")] obj: bool) -> bool {
obj
}
}
#[test]
fn test_pymethods_from_py_with() {
Python::with_gil(|py| {
let instance = Py::new(py, ClassWithFromPyWithMethods {}).unwrap();
py_run!(
py,
instance,
r#"
arg = {1: 1, 2: 3}
assert instance.instance_method(arg) == 2
assert instance.classmethod(arg) == 2
assert instance.staticmethod(arg) == 2
assert 42 in instance
assert 73 not in instance
"#
);
})
}
#[pyclass]
struct TupleClass(#[pyo3(get, set, name = "value")] i32);
#[test]
fn test_tuple_struct_class() {
Python::with_gil(|py| {
let typeobj = py.get_type::<TupleClass>();
assert!(typeobj.call((), None).is_err());
py_assert!(py, typeobj, "typeobj.__name__ == 'TupleClass'");
let instance = Py::new(py, TupleClass(5)).unwrap();
py_run!(
py,
instance,
r#"
assert instance.value == 5;
instance.value = 1234;
assert instance.value == 1234;
"#
);
assert_eq!(instance.borrow(py).0, 1234);
});
}
#[cfg(any(Py_3_9, not(Py_LIMITED_API)))]
#[pyclass(dict, subclass)]
struct DunderDictSupport {
// Make sure that dict_offset runs with non-zero sized Self
_pad: [u8; 32],
}
#[test]
#[cfg(any(Py_3_9, not(Py_LIMITED_API)))]
fn dunder_dict_support() {
Python::with_gil(|py| {
let inst = Py::new(
py,
DunderDictSupport {
_pad: *b"DEADBEEFDEADBEEFDEADBEEFDEADBEEF",
},
)
.unwrap();
py_run!(
py,
inst,
r#"
inst.a = 1
assert inst.a == 1
"#
);
});
}
#[test]
#[cfg(any(Py_3_9, not(Py_LIMITED_API)))]
fn access_dunder_dict() {
Python::with_gil(|py| {
let inst = Py::new(
py,
DunderDictSupport {
_pad: *b"DEADBEEFDEADBEEFDEADBEEFDEADBEEF",
},
)
.unwrap();
py_run!(
py,
inst,
r#"
inst.a = 1
assert inst.__dict__ == {'a': 1}
"#
);
});
}
// If the base class has dict support, child class also has dict
#[cfg(any(Py_3_9, not(Py_LIMITED_API)))]
#[pyclass(extends=DunderDictSupport)]
struct InheritDict {
_value: usize,
}
#[test]
#[cfg(any(Py_3_9, not(Py_LIMITED_API)))]
fn inherited_dict() {
Python::with_gil(|py| {
let inst = Py::new(
py,
(
InheritDict { _value: 0 },
DunderDictSupport {
_pad: *b"DEADBEEFDEADBEEFDEADBEEFDEADBEEF",
},
),
)
.unwrap();
py_run!(
py,
inst,
r#"
inst.a = 1
assert inst.a == 1
"#
);
});
}
#[cfg(any(Py_3_9, not(Py_LIMITED_API)))]
#[pyclass(weakref, dict)]
struct WeakRefDunderDictSupport {
// Make sure that weaklist_offset runs with non-zero sized Self
_pad: [u8; 32],
}
#[test]
#[cfg(any(Py_3_9, not(Py_LIMITED_API)))]
fn weakref_dunder_dict_support() {
Python::with_gil(|py| {
let inst = Py::new(
py,
WeakRefDunderDictSupport {
_pad: *b"DEADBEEFDEADBEEFDEADBEEFDEADBEEF",
},
)
.unwrap();
py_run!(
py,
inst,
"import weakref; assert weakref.ref(inst)() is inst; inst.a = 1; assert inst.a == 1"
);
});
}
#[cfg(any(Py_3_9, not(Py_LIMITED_API)))]
#[pyclass(weakref, subclass)]
struct WeakRefSupport {
_pad: [u8; 32],
}
#[test]
#[cfg(any(Py_3_9, not(Py_LIMITED_API)))]
fn weakref_support() {
Python::with_gil(|py| {
let inst = Py::new(
py,
WeakRefSupport {
_pad: *b"DEADBEEFDEADBEEFDEADBEEFDEADBEEF",
},
)
.unwrap();
py_run!(
py,
inst,
"import weakref; assert weakref.ref(inst)() is inst"
);
});
}
// If the base class has weakref support, child class also has weakref.
#[cfg(any(Py_3_9, not(Py_LIMITED_API)))]
#[pyclass(extends=WeakRefSupport)]
struct InheritWeakRef {
_value: usize,
}
#[test]
#[cfg(any(Py_3_9, not(Py_LIMITED_API)))]
fn inherited_weakref() {
Python::with_gil(|py| {
let inst = Py::new(
py,
(
InheritWeakRef { _value: 0 },
WeakRefSupport {
_pad: *b"DEADBEEFDEADBEEFDEADBEEFDEADBEEF",
},
),
)
.unwrap();
py_run!(
py,
inst,
"import weakref; assert weakref.ref(inst)() is inst"
);
});
}
#[test]
fn access_frozen_class_without_gil() {
use std::sync::atomic::{AtomicUsize, Ordering};
#[pyclass(frozen)]
struct FrozenCounter {
value: AtomicUsize,
}
let py_counter: Py<FrozenCounter> = Python::with_gil(|py| {
let counter = FrozenCounter {
value: AtomicUsize::new(0),
};
let cell = Bound::new(py, counter).unwrap();
cell.get().value.fetch_add(1, Ordering::Relaxed);
cell.into()
});
assert_eq!(py_counter.get().value.load(Ordering::Relaxed), 1);
Python::with_gil(move |_py| drop(py_counter));
}
#[test]
#[cfg(all(Py_3_8, not(Py_GIL_DISABLED)))] // sys.unraisablehook not available until Python 3.8
#[cfg_attr(target_arch = "wasm32", ignore)]
fn drop_unsendable_elsewhere() {
use common::UnraisableCapture;
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
};
use std::thread::spawn;
#[pyclass(unsendable)]
struct Unsendable {
dropped: Arc<AtomicBool>,
}
impl Drop for Unsendable {
fn drop(&mut self) {
self.dropped.store(true, Ordering::SeqCst);
}
}
Python::with_gil(|py| {
let capture = UnraisableCapture::install(py);
let dropped = Arc::new(AtomicBool::new(false));
let unsendable = Py::new(
py,
Unsendable {
dropped: dropped.clone(),
},
)
.unwrap();
py.allow_threads(|| {
spawn(move || {
Python::with_gil(move |_py| {
drop(unsendable);
});
})
.join()
.unwrap();
});
assert!(!dropped.load(Ordering::SeqCst));
let (err, object) = capture.borrow_mut(py).capture.take().unwrap();
assert_eq!(err.to_string(), "RuntimeError: test_class_basics::drop_unsendable_elsewhere::Unsendable is unsendable, but is being dropped on another thread");
assert!(object.is_none(py));
capture.borrow_mut(py).uninstall(py);
});
}
#[test]
#[cfg(any(Py_3_9, not(Py_LIMITED_API)))]
fn test_unsendable_dict() {
#[pyclass(dict, unsendable)]
struct UnsendableDictClass {}
#[pymethods]
impl UnsendableDictClass {
#[new]
fn new() -> Self {
UnsendableDictClass {}
}
}
Python::with_gil(|py| {
let inst = Py::new(py, UnsendableDictClass {}).unwrap();
py_run!(py, inst, "assert inst.__dict__ == {}");
});
}
#[test]
#[cfg(any(Py_3_9, not(Py_LIMITED_API)))]
fn test_unsendable_dict_with_weakref() {
#[pyclass(dict, unsendable, weakref)]
struct UnsendableDictClassWithWeakRef {}
#[pymethods]
impl UnsendableDictClassWithWeakRef {
#[new]
fn new() -> Self {
Self {}
}
}
Python::with_gil(|py| {
let inst = Py::new(py, UnsendableDictClassWithWeakRef {}).unwrap();
py_run!(py, inst, "assert inst.__dict__ == {}");
py_run!(
py,
inst,
"import weakref; assert weakref.ref(inst)() is inst; inst.a = 1; assert inst.a == 1"
);
});
}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/test_exceptions.rs | #![cfg(feature = "macros")]
use pyo3::prelude::*;
use pyo3::{exceptions, py_run};
use std::error::Error;
use std::fmt;
#[cfg(not(target_os = "windows"))]
use std::fs::File;
#[path = "../src/tests/common.rs"]
mod common;
#[pyfunction]
#[cfg(not(target_os = "windows"))]
fn fail_to_open_file() -> PyResult<()> {
File::open("not_there.txt")?;
Ok(())
}
#[test]
#[cfg_attr(target_arch = "wasm32", ignore)] // Not sure why this fails.
#[cfg(not(target_os = "windows"))]
fn test_filenotfounderror() {
Python::with_gil(|py| {
let fail_to_open_file = wrap_pyfunction!(fail_to_open_file)(py).unwrap();
py_run!(
py,
fail_to_open_file,
r#"
try:
fail_to_open_file()
except FileNotFoundError as e:
assert str(e) == "No such file or directory (os error 2)"
"#
);
});
}
#[derive(Debug)]
struct CustomError;
impl Error for CustomError {}
impl fmt::Display for CustomError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Oh no!")
}
}
impl std::convert::From<CustomError> for PyErr {
fn from(err: CustomError) -> PyErr {
exceptions::PyOSError::new_err(err.to_string())
}
}
fn fail_with_custom_error() -> Result<(), CustomError> {
Err(CustomError)
}
#[pyfunction]
fn call_fail_with_custom_error() -> PyResult<()> {
fail_with_custom_error()?;
Ok(())
}
#[test]
fn test_custom_error() {
Python::with_gil(|py| {
let call_fail_with_custom_error =
wrap_pyfunction!(call_fail_with_custom_error)(py).unwrap();
py_run!(
py,
call_fail_with_custom_error,
r#"
try:
call_fail_with_custom_error()
except OSError as e:
assert str(e) == "Oh no!"
"#
);
});
}
#[test]
fn test_exception_nosegfault() {
use std::net::TcpListener;
fn io_err() -> PyResult<()> {
TcpListener::bind("no:address")?;
Ok(())
}
fn parse_int() -> PyResult<()> {
"@_@".parse::<i64>()?;
Ok(())
}
assert!(io_err().is_err());
assert!(parse_int().is_err());
}
#[test]
#[cfg(all(Py_3_8, not(Py_GIL_DISABLED)))]
fn test_write_unraisable() {
use common::UnraisableCapture;
use pyo3::{exceptions::PyRuntimeError, ffi, types::PyNotImplemented};
Python::with_gil(|py| {
let capture = UnraisableCapture::install(py);
assert!(capture.borrow(py).capture.is_none());
let err = PyRuntimeError::new_err("foo");
err.write_unraisable(py, None);
let (err, object) = capture.borrow_mut(py).capture.take().unwrap();
assert_eq!(err.to_string(), "RuntimeError: foo");
assert!(object.is_none(py));
let err = PyRuntimeError::new_err("bar");
err.write_unraisable(py, Some(&PyNotImplemented::get(py)));
let (err, object) = capture.borrow_mut(py).capture.take().unwrap();
assert_eq!(err.to_string(), "RuntimeError: bar");
assert!(object.as_ptr() == unsafe { ffi::Py_NotImplemented() });
capture.borrow_mut(py).uninstall(py);
});
}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/test_macros.rs | #![cfg(feature = "macros")]
//! Ensure that pyo3 macros can be used inside macro_rules!
use pyo3::prelude::*;
#[macro_use]
#[path = "../src/tests/common.rs"]
mod common;
macro_rules! make_struct_using_macro {
// Ensure that one doesn't need to fall back on the escape type: tt
// in order to macro create pyclass.
($class_name:ident, $py_name:literal) => {
#[pyclass(name=$py_name, subclass)]
struct $class_name {}
};
}
make_struct_using_macro!(MyBaseClass, "MyClass");
macro_rules! set_extends_via_macro {
($class_name:ident, $base_class:path) => {
// Try and pass a variable into the extends parameter
#[allow(dead_code)]
#[pyclass(extends=$base_class)]
struct $class_name {}
};
}
set_extends_via_macro!(MyClass2, MyBaseClass);
//
// Check that pyfunctiona nd text_signature can be called with macro arguments.
//
macro_rules! fn_macro {
($sig:literal, $a_exp:expr, $b_exp:expr, $c_exp: expr) => {
// Try and pass a variable into the signature parameter
#[pyfunction(signature = ($a_exp, $b_exp, *, $c_exp))]
#[pyo3(text_signature = $sig)]
fn my_function_in_macro(a: i32, b: Option<i32>, c: i32) {
let _ = (a, b, c);
}
};
}
fn_macro!("(a, b=None, *, c=42)", a, b = None, c = 42);
macro_rules! property_rename_via_macro {
($prop_name:ident) => {
#[pyclass]
struct ClassWithProperty {
member: u64,
}
#[pymethods]
impl ClassWithProperty {
#[getter($prop_name)]
fn get_member(&self) -> u64 {
self.member
}
#[setter($prop_name)]
fn set_member(&mut self, member: u64) {
self.member = member;
}
}
};
}
property_rename_via_macro!(my_new_property_name);
#[test]
fn test_macro_rules_interactions() {
Python::with_gil(|py| {
let my_base = py.get_type::<MyBaseClass>();
py_assert!(py, my_base, "my_base.__name__ == 'MyClass'");
let my_func = wrap_pyfunction!(my_function_in_macro, py).unwrap();
py_assert!(
py,
my_func,
"my_func.__text_signature__ == '(a, b=None, *, c=42)'"
);
let renamed_prop = py.get_type::<ClassWithProperty>();
py_assert!(
py,
renamed_prop,
"hasattr(renamed_prop, 'my_new_property_name')"
);
});
}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pymethod_receiver.stderr | error[E0277]: the trait bound `i32: TryFrom<BoundRef<'_, '_, MyClass>>` is not satisfied
--> tests/ui/invalid_pymethod_receiver.rs:8:44
|
8 | fn method_with_invalid_self_type(_slf: i32, _py: Python<'_>, _index: u32) {}
| ^^^ the trait `From<BoundRef<'_, '_, MyClass>>` is not implemented for `i32`, which is required by `i32: TryFrom<BoundRef<'_, '_, MyClass>>`
|
= help: the following other types implement trait `From<T>`:
`i32` implements `From<bool>`
`i32` implements `From<i16>`
`i32` implements `From<i8>`
`i32` implements `From<u16>`
`i32` implements `From<u8>`
= note: required for `BoundRef<'_, '_, MyClass>` to implement `Into<i32>`
= note: required for `i32` to implement `TryFrom<BoundRef<'_, '_, MyClass>>`
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/static_ref.stderr | error: lifetime may not live long enough
--> tests/ui/static_ref.rs:4:1
|
4 | #[pyfunction]
| ^^^^^^^^^^^^^
| |
| lifetime `'py` defined here
| cast requires that `'py` must outlive `'static`
|
= note: this error originates in the attribute macro `pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0597]: `output[_]` does not live long enough
--> tests/ui/static_ref.rs:4:1
|
4 | #[pyfunction]
| ^^^^^^^^^^^^-
| | |
| | `output[_]` dropped here while still borrowed
| borrowed value does not live long enough
| argument requires that `output[_]` is borrowed for `'static`
|
= note: this error originates in the attribute macro `pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0597]: `holder_0` does not live long enough
--> tests/ui/static_ref.rs:5:15
|
4 | #[pyfunction]
| -------------
| | |
| | `holder_0` dropped here while still borrowed
| binding `holder_0` declared here
5 | fn static_ref(list: &'static Bound<'_, PyList>) -> usize {
| ^^^^^^-
| | |
| | argument requires that `holder_0` is borrowed for `'static`
| borrowed value does not live long enough
error: lifetime may not live long enough
--> tests/ui/static_ref.rs:9:1
|
9 | #[pyfunction]
| ^^^^^^^^^^^^^
| |
| lifetime `'py` defined here
| cast requires that `'py` must outlive `'static`
|
= note: this error originates in the attribute macro `pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info)
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pymethod_enum.rs | use pyo3::prelude::*;
#[pyclass]
enum ComplexEnum {
Int { int: i32 },
Str { string: String },
}
#[pymethods]
impl ComplexEnum {
fn mutate_in_place(&mut self) {
*self = match self {
ComplexEnum::Int { int } => ComplexEnum::Str { string: int.to_string() },
ComplexEnum::Str { string } => ComplexEnum::Int { int: string.len() as i32 },
}
}
}
#[pyclass]
enum TupleEnum {
Int(i32),
Str(String),
}
#[pymethods]
impl TupleEnum {
fn mutate_in_place(&mut self) {
*self = match self {
TupleEnum::Int(int) => TupleEnum::Str(int.to_string()),
TupleEnum::Str(string) => TupleEnum::Int(string.len() as i32),
}
}
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/deprecations.rs | #![deny(deprecated)]
#![allow(dead_code)]
use pyo3::prelude::*;
fn extract_options(obj: &Bound<'_, PyAny>) -> PyResult<Option<i32>> {
obj.extract()
}
#[pyfunction]
#[pyo3(signature = (_i, _any=None))]
fn pyfunction_option_1(_i: u32, _any: Option<i32>) {}
#[pyfunction]
fn pyfunction_option_2(_i: u32, _any: Option<i32>) {}
#[pyfunction]
fn pyfunction_option_3(_i: u32, _any: Option<i32>, _foo: Option<String>) {}
#[pyfunction]
fn pyfunction_option_4(
_i: u32,
#[pyo3(from_py_with = "extract_options")] _any: Option<i32>,
_foo: Option<String>,
) {
}
#[pyclass]
pub enum SimpleEnumWithoutEq {
VariamtA,
VariantB,
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_frompy_derive.rs | use pyo3::FromPyObject;
#[derive(FromPyObject)]
struct Foo();
#[derive(FromPyObject)]
struct Foo2 {}
#[derive(FromPyObject)]
enum EmptyEnum {}
#[derive(FromPyObject)]
enum EnumWithEmptyTupleVar {
EmptyTuple(),
Valid(String),
}
#[derive(FromPyObject)]
enum EnumWithEmptyStructVar {
EmptyStruct {},
Valid(String),
}
#[derive(FromPyObject)]
#[pyo3(transparent)]
struct EmptyTransparentTup();
#[derive(FromPyObject)]
#[pyo3(transparent)]
struct EmptyTransparentStruct {}
#[derive(FromPyObject)]
enum EnumWithTransparentEmptyTupleVar {
#[pyo3(transparent)]
EmptyTuple(),
Valid(String),
}
#[derive(FromPyObject)]
enum EnumWithTransparentEmptyStructVar {
#[pyo3(transparent)]
EmptyStruct {},
Valid(String),
}
#[derive(FromPyObject)]
#[pyo3(transparent)]
struct TransparentTupTooManyFields(String, String);
#[derive(FromPyObject)]
#[pyo3(transparent)]
struct TransparentStructTooManyFields {
foo: String,
bar: String,
}
#[derive(FromPyObject)]
enum EnumWithTransparentTupleTooMany {
#[pyo3(transparent)]
EmptyTuple(String, String),
Valid(String),
}
#[derive(FromPyObject)]
enum EnumWithTransparentStructTooMany {
#[pyo3(transparent)]
EmptyStruct {
foo: String,
bar: String,
},
Valid(String),
}
#[derive(FromPyObject)]
struct UnknownAttribute {
#[pyo3(attr)]
a: String,
}
#[derive(FromPyObject)]
struct InvalidAttributeArg {
#[pyo3(attribute(1))]
a: String,
}
#[derive(FromPyObject)]
struct TooManyAttributeArgs {
#[pyo3(attribute("a", "b"))]
a: String,
}
#[derive(FromPyObject)]
struct EmptyAttributeArg {
#[pyo3(attribute(""))]
a: String,
}
#[derive(FromPyObject)]
struct NoAttributeArg {
#[pyo3(attribute())]
a: String,
}
#[derive(FromPyObject)]
struct TooManyitemArgs {
#[pyo3(item("a", "b"))]
a: String,
}
#[derive(FromPyObject)]
struct NoItemArg {
#[pyo3(item())]
a: String,
}
#[derive(FromPyObject)]
struct ItemAndAttribute {
#[pyo3(item, attribute)]
a: String,
}
#[derive(FromPyObject)]
#[pyo3(unknown = "should not work")]
struct UnknownContainerAttr {
a: String,
}
#[derive(FromPyObject)]
#[pyo3(annotation = "should not work")]
struct AnnotationOnStruct {
a: String,
}
#[derive(FromPyObject)]
enum InvalidAnnotatedEnum {
#[pyo3(annotation = 1)]
Foo(String),
}
#[derive(FromPyObject)]
enum TooManyLifetimes<'a, 'b> {
Foo(&'a str),
Bar(&'b str),
}
#[derive(FromPyObject)]
union Union {
a: usize,
}
#[derive(FromPyObject)]
enum UnitEnum {
Unit,
}
#[derive(FromPyObject)]
struct InvalidFromPyWith {
#[pyo3(from_py_with)]
field: String,
}
#[derive(FromPyObject)]
struct InvalidFromPyWithLiteral {
#[pyo3(from_py_with = func)]
field: String,
}
#[derive(FromPyObject)]
struct InvalidTupleGetter(#[pyo3(item("foo"))] String);
#[derive(FromPyObject)]
#[pyo3(transparent)]
struct InvalidTransparentWithGetter {
#[pyo3(item("foo"))]
field: String,
}
#[derive(FromPyObject)]
#[pyo3(from_item_all)]
struct FromItemAllOnTuple(String);
#[derive(FromPyObject)]
#[pyo3(from_item_all)]
#[pyo3(transparent)]
struct FromItemAllWithTransparent {
field: String,
}
#[derive(FromPyObject)]
#[pyo3(from_item_all, from_item_all)]
struct MultipleFromItemAll {
field: String,
}
#[derive(FromPyObject)]
#[pyo3(from_item_all)]
struct UselessItemAttr {
#[pyo3(item)]
field: String,
}
#[derive(FromPyObject)]
#[pyo3(from_item_all)]
struct FromItemAllConflictAttr {
#[pyo3(attribute)]
field: String,
}
#[derive(FromPyObject)]
#[pyo3(from_item_all)]
struct FromItemAllConflictAttrWithArgs {
#[pyo3(attribute("f"))]
field: String,
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_result_conversion.rs | //! Testing https://github.com/PyO3/pyo3/issues/1106. A result type that
//! *doesn't* implement `From<MyError> for PyErr` won't be automatically
//! converted when using `#[pyfunction]`.
use pyo3::prelude::*;
use std::fmt;
/// A basic error type for the tests. It's missing `From<MyError> for PyErr`,
/// though, so it shouldn't work.
#[derive(Debug)]
struct MyError {
pub descr: &'static str,
}
impl fmt::Display for MyError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "My error message: {}", self.descr)
}
}
#[pyfunction]
fn should_not_work() -> Result<(), MyError> {
Err(MyError {
descr: "something went wrong",
})
}
fn main() {
Python::with_gil(|py| {
wrap_pyfunction!(should_not_work)(py);
});
}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_intern_arg.stderr | error[E0435]: attempt to use a non-constant value in a constant
--> tests/ui/invalid_intern_arg.rs:5:55
|
5 | Python::with_gil(|py| py.import(pyo3::intern!(py, _foo)).unwrap());
| ^^^^ non-constant value
|
help: consider using `let` instead of `static`
--> src/sync.rs
|
| let INTERNED: $crate::sync::Interned = $crate::sync::Interned::new($text);
| ~~~
error: lifetime may not live long enough
--> tests/ui/invalid_intern_arg.rs:5:27
|
5 | Python::with_gil(|py| py.import(pyo3::intern!(py, _foo)).unwrap());
| --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'2`
| | |
| | return type of closure is pyo3::Bound<'2, PyModule>
| has type `Python<'1>`
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_frozen_pyclass_borrow.stderr | error: cannot use `#[pyo3(set)]` on a `frozen` class
--> tests/ui/invalid_frozen_pyclass_borrow.rs:38:12
|
38 | #[pyo3(set)]
| ^^^
error[E0271]: type mismatch resolving `<Foo as PyClass>::Frozen == False`
--> tests/ui/invalid_frozen_pyclass_borrow.rs:11:19
|
11 | fn mut_method(&mut self) {}
| ^ expected `False`, found `True`
|
note: required by a bound in `extract_pyclass_ref_mut`
--> src/impl_/extract_argument.rs
|
| pub fn extract_pyclass_ref_mut<'a, 'py: 'a, T: PyClass<Frozen = False>>(
| ^^^^^^^^^^^^^^ required by this bound in `extract_pyclass_ref_mut`
error[E0271]: type mismatch resolving `<Foo as PyClass>::Frozen == False`
--> tests/ui/invalid_frozen_pyclass_borrow.rs:9:1
|
9 | #[pymethods]
| ^^^^^^^^^^^^ expected `False`, found `True`
|
note: required by a bound in `PyRefMut`
--> src/pycell.rs
|
| pub struct PyRefMut<'p, T: PyClass<Frozen = False>> {
| ^^^^^^^^^^^^^^ required by this bound in `PyRefMut`
= note: this error originates in the attribute macro `pymethods` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0271]: type mismatch resolving `<Foo as PyClass>::Frozen == False`
--> tests/ui/invalid_frozen_pyclass_borrow.rs:15:31
|
15 | let borrow = foo.bind(py).borrow_mut();
| ^^^^^^^^^^ expected `False`, found `True`
|
note: required by a bound in `pyo3::Bound::<'py, T>::borrow_mut`
--> src/instance.rs
|
| pub fn borrow_mut(&self) -> PyRefMut<'py, T>
| ---------- required by a bound in this associated function
| where
| T: PyClass<Frozen = False>,
| ^^^^^^^^^^^^^^ required by this bound in `Bound::<'py, T>::borrow_mut`
error[E0271]: type mismatch resolving `<ImmutableChild as PyClass>::Frozen == False`
--> tests/ui/invalid_frozen_pyclass_borrow.rs:25:33
|
25 | let borrow = child.bind(py).borrow_mut();
| ^^^^^^^^^^ expected `False`, found `True`
|
note: required by a bound in `pyo3::Bound::<'py, T>::borrow_mut`
--> src/instance.rs
|
| pub fn borrow_mut(&self) -> PyRefMut<'py, T>
| ---------- required by a bound in this associated function
| where
| T: PyClass<Frozen = False>,
| ^^^^^^^^^^^^^^ required by this bound in `Bound::<'py, T>::borrow_mut`
error[E0271]: type mismatch resolving `<MutableBase as PyClass>::Frozen == True`
--> tests/ui/invalid_frozen_pyclass_borrow.rs:29:11
|
29 | class.get();
| ^^^ expected `True`, found `False`
|
note: required by a bound in `pyo3::Py::<T>::get`
--> src/instance.rs
|
| pub fn get(&self) -> &T
| --- required by a bound in this associated function
| where
| T: PyClass<Frozen = True> + Sync,
| ^^^^^^^^^^^^^ required by this bound in `Py::<T>::get`
error[E0271]: type mismatch resolving `<MutableBase as PyClass>::Frozen == True`
--> tests/ui/invalid_frozen_pyclass_borrow.rs:33:11
|
33 | class.get();
| ^^^ expected `True`, found `False`
|
note: required by a bound in `pyo3::Bound::<'py, T>::get`
--> src/instance.rs
|
| pub fn get(&self) -> &T
| --- required by a bound in this associated function
| where
| T: PyClass<Frozen = True> + Sync,
| ^^^^^^^^^^^^^ required by this bound in `Bound::<'py, T>::get`
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pyclass_enum.stderr | error: enums can't be inherited by other classes
--> tests/ui/invalid_pyclass_enum.rs:3:11
|
3 | #[pyclass(subclass)]
| ^^^^^^^^
error: enums can't extend from other classes
--> tests/ui/invalid_pyclass_enum.rs:9:11
|
9 | #[pyclass(extends = PyList)]
| ^^^^^^^
error: #[pyclass] can't be used on enums without any variants
--> tests/ui/invalid_pyclass_enum.rs:16:18
|
16 | enum NoEmptyEnum {}
| ^^
error: Unit variant `UnitVariant` is not yet supported in a complex enum
= help: change to an empty tuple variant instead: `UnitVariant()`
= note: the enum is complex because of non-unit variant `StructVariant`
--> tests/ui/invalid_pyclass_enum.rs:21:5
|
21 | UnitVariant,
| ^^^^^^^^^^^
error: `constructor` can't be used on a simple enum variant
--> tests/ui/invalid_pyclass_enum.rs:26:12
|
26 | #[pyo3(constructor = (a, b))]
| ^^^^^^^^^^^
error: The `eq_int` option requires the `eq` option.
--> tests/ui/invalid_pyclass_enum.rs:43:11
|
43 | #[pyclass(eq_int)]
| ^^^^^^
error: `eq_int` can only be used on simple enums.
--> tests/ui/invalid_pyclass_enum.rs:49:11
|
49 | #[pyclass(eq_int)]
| ^^^^^^
error: The `hash` option requires the `frozen` option.
--> tests/ui/invalid_pyclass_enum.rs:69:11
|
69 | #[pyclass(hash)]
| ^^^^
error: The `hash` option requires the `eq` option.
--> tests/ui/invalid_pyclass_enum.rs:69:11
|
69 | #[pyclass(hash)]
| ^^^^
error: The `hash` option requires the `eq` option.
--> tests/ui/invalid_pyclass_enum.rs:76:11
|
76 | #[pyclass(hash)]
| ^^^^
error: The `ord` option requires the `eq` option.
--> tests/ui/invalid_pyclass_enum.rs:83:11
|
83 | #[pyclass(ord)]
| ^^^
error: #[pyclass] can't be used on enums without any variants - all variants of enum `AllEnumVariantsDisabled` have been configured out by cfg attributes
--> tests/ui/invalid_pyclass_enum.rs:98:6
|
98 | enum AllEnumVariantsDisabled {
| ^^^^^^^^^^^^^^^^^^^^^^^
error[E0369]: binary operation `==` cannot be applied to type `&SimpleEqOptRequiresPartialEq`
--> tests/ui/invalid_pyclass_enum.rs:31:11
|
31 | #[pyclass(eq, eq_int)]
| ^^
|
note: an implementation of `PartialEq` might be missing for `SimpleEqOptRequiresPartialEq`
--> tests/ui/invalid_pyclass_enum.rs:32:1
|
32 | enum SimpleEqOptRequiresPartialEq {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ must implement `PartialEq`
help: consider annotating `SimpleEqOptRequiresPartialEq` with `#[derive(PartialEq)]`
|
32 + #[derive(PartialEq)]
33 | enum SimpleEqOptRequiresPartialEq {
|
error[E0369]: binary operation `!=` cannot be applied to type `&SimpleEqOptRequiresPartialEq`
--> tests/ui/invalid_pyclass_enum.rs:31:11
|
31 | #[pyclass(eq, eq_int)]
| ^^
|
note: an implementation of `PartialEq` might be missing for `SimpleEqOptRequiresPartialEq`
--> tests/ui/invalid_pyclass_enum.rs:32:1
|
32 | enum SimpleEqOptRequiresPartialEq {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ must implement `PartialEq`
help: consider annotating `SimpleEqOptRequiresPartialEq` with `#[derive(PartialEq)]`
|
32 + #[derive(PartialEq)]
33 | enum SimpleEqOptRequiresPartialEq {
|
error[E0369]: binary operation `==` cannot be applied to type `&ComplexEqOptRequiresPartialEq`
--> tests/ui/invalid_pyclass_enum.rs:37:11
|
37 | #[pyclass(eq)]
| ^^
|
note: an implementation of `PartialEq` might be missing for `ComplexEqOptRequiresPartialEq`
--> tests/ui/invalid_pyclass_enum.rs:38:1
|
38 | enum ComplexEqOptRequiresPartialEq {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ must implement `PartialEq`
help: consider annotating `ComplexEqOptRequiresPartialEq` with `#[derive(PartialEq)]`
|
38 + #[derive(PartialEq)]
39 | enum ComplexEqOptRequiresPartialEq {
|
error[E0369]: binary operation `!=` cannot be applied to type `&ComplexEqOptRequiresPartialEq`
--> tests/ui/invalid_pyclass_enum.rs:37:11
|
37 | #[pyclass(eq)]
| ^^
|
note: an implementation of `PartialEq` might be missing for `ComplexEqOptRequiresPartialEq`
--> tests/ui/invalid_pyclass_enum.rs:38:1
|
38 | enum ComplexEqOptRequiresPartialEq {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ must implement `PartialEq`
help: consider annotating `ComplexEqOptRequiresPartialEq` with `#[derive(PartialEq)]`
|
38 + #[derive(PartialEq)]
39 | enum ComplexEqOptRequiresPartialEq {
|
error[E0277]: the trait bound `SimpleHashOptRequiresHash: Hash` is not satisfied
--> tests/ui/invalid_pyclass_enum.rs:55:31
|
55 | #[pyclass(frozen, eq, eq_int, hash)]
| ^^^^ the trait `Hash` is not implemented for `SimpleHashOptRequiresHash`
|
help: consider annotating `SimpleHashOptRequiresHash` with `#[derive(Hash)]`
|
57 + #[derive(Hash)]
58 | enum SimpleHashOptRequiresHash {
|
error[E0277]: the trait bound `ComplexHashOptRequiresHash: Hash` is not satisfied
--> tests/ui/invalid_pyclass_enum.rs:62:23
|
62 | #[pyclass(frozen, eq, hash)]
| ^^^^ the trait `Hash` is not implemented for `ComplexHashOptRequiresHash`
|
help: consider annotating `ComplexHashOptRequiresHash` with `#[derive(Hash)]`
|
64 + #[derive(Hash)]
65 | enum ComplexHashOptRequiresHash {
|
error[E0369]: binary operation `>` cannot be applied to type `&InvalidOrderedComplexEnum2`
--> tests/ui/invalid_pyclass_enum.rs:89:14
|
89 | #[pyclass(eq,ord)]
| ^^^
|
note: an implementation of `PartialOrd` might be missing for `InvalidOrderedComplexEnum2`
--> tests/ui/invalid_pyclass_enum.rs:91:1
|
91 | enum InvalidOrderedComplexEnum2 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ must implement `PartialOrd`
help: consider annotating `InvalidOrderedComplexEnum2` with `#[derive(PartialEq, PartialOrd)]`
|
91 + #[derive(PartialEq, PartialOrd)]
92 | enum InvalidOrderedComplexEnum2 {
|
error[E0369]: binary operation `<` cannot be applied to type `&InvalidOrderedComplexEnum2`
--> tests/ui/invalid_pyclass_enum.rs:89:14
|
89 | #[pyclass(eq,ord)]
| ^^^
|
note: an implementation of `PartialOrd` might be missing for `InvalidOrderedComplexEnum2`
--> tests/ui/invalid_pyclass_enum.rs:91:1
|
91 | enum InvalidOrderedComplexEnum2 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ must implement `PartialOrd`
help: consider annotating `InvalidOrderedComplexEnum2` with `#[derive(PartialEq, PartialOrd)]`
|
91 + #[derive(PartialEq, PartialOrd)]
92 | enum InvalidOrderedComplexEnum2 {
|
error[E0369]: binary operation `<=` cannot be applied to type `&InvalidOrderedComplexEnum2`
--> tests/ui/invalid_pyclass_enum.rs:89:14
|
89 | #[pyclass(eq,ord)]
| ^^^
|
note: an implementation of `PartialOrd` might be missing for `InvalidOrderedComplexEnum2`
--> tests/ui/invalid_pyclass_enum.rs:91:1
|
91 | enum InvalidOrderedComplexEnum2 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ must implement `PartialOrd`
help: consider annotating `InvalidOrderedComplexEnum2` with `#[derive(PartialEq, PartialOrd)]`
|
91 + #[derive(PartialEq, PartialOrd)]
92 | enum InvalidOrderedComplexEnum2 {
|
error[E0369]: binary operation `>=` cannot be applied to type `&InvalidOrderedComplexEnum2`
--> tests/ui/invalid_pyclass_enum.rs:89:14
|
89 | #[pyclass(eq,ord)]
| ^^^
|
note: an implementation of `PartialOrd` might be missing for `InvalidOrderedComplexEnum2`
--> tests/ui/invalid_pyclass_enum.rs:91:1
|
91 | enum InvalidOrderedComplexEnum2 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ must implement `PartialOrd`
help: consider annotating `InvalidOrderedComplexEnum2` with `#[derive(PartialEq, PartialOrd)]`
|
91 + #[derive(PartialEq, PartialOrd)]
92 | enum InvalidOrderedComplexEnum2 {
|
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pymethods.stderr | error: #[classattr] can only have one argument (of type pyo3::Python)
--> tests/ui/invalid_pymethods.rs:9:35
|
9 | fn class_attr_with_args(_foo: i32) {}
| ^^^
error: `#[classattr]` does not take any arguments
--> tests/ui/invalid_pymethods.rs:14:5
|
14 | #[classattr(foobar)]
| ^
error: static method needs #[staticmethod] attribute
--> tests/ui/invalid_pymethods.rs:20:5
|
20 | fn staticmethod_without_attribute() {}
| ^^
error: unexpected receiver
--> tests/ui/invalid_pymethods.rs:26:35
|
26 | fn staticmethod_with_receiver(&self) {}
| ^
error: Expected `&Bound<PyType>` or `Py<PyType>` as the first argument to `#[classmethod]`
--> tests/ui/invalid_pymethods.rs:32:33
|
32 | fn classmethod_with_receiver(&self) {}
| ^^^^^^^
error: Expected `&Bound<PyType>` or `Py<PyType>` as the first argument to `#[classmethod]`
--> tests/ui/invalid_pymethods.rs:38:36
|
38 | fn classmethod_missing_argument() -> Self {
| ^^
error: expected receiver for `#[getter]`
--> tests/ui/invalid_pymethods.rs:54:5
|
54 | fn getter_without_receiver() {}
| ^^
error: expected receiver for `#[setter]`
--> tests/ui/invalid_pymethods.rs:60:5
|
60 | fn setter_without_receiver() {}
| ^^
error: static method needs #[staticmethod] attribute
--> tests/ui/invalid_pymethods.rs:66:5
|
66 | fn text_signature_on_call() {}
| ^^
error: `text_signature` not allowed with `getter`
--> tests/ui/invalid_pymethods.rs:72:12
|
72 | #[pyo3(text_signature = "()")]
| ^^^^^^^^^^^^^^
error: `text_signature` not allowed with `setter`
--> tests/ui/invalid_pymethods.rs:79:12
|
79 | #[pyo3(text_signature = "()")]
| ^^^^^^^^^^^^^^
error: `text_signature` not allowed with `classattr`
--> tests/ui/invalid_pymethods.rs:86:12
|
86 | #[pyo3(text_signature = "()")]
| ^^^^^^^^^^^^^^
error: expected a string literal or `None`
--> tests/ui/invalid_pymethods.rs:92:30
|
92 | #[pyo3(text_signature = 1)]
| ^
error: `text_signature` may only be specified once
--> tests/ui/invalid_pymethods.rs:99:12
|
99 | #[pyo3(text_signature = None)]
| ^^^^^^^^^^^^^^
error: `signature` not allowed with `getter`
--> tests/ui/invalid_pymethods.rs:106:12
|
106 | #[pyo3(signature = ())]
| ^^^^^^^^^
error: `signature` not allowed with `setter`
--> tests/ui/invalid_pymethods.rs:113:12
|
113 | #[pyo3(signature = ())]
| ^^^^^^^^^
error: `signature` not allowed with `classattr`
--> tests/ui/invalid_pymethods.rs:120:12
|
120 | #[pyo3(signature = ())]
| ^^^^^^^^^
error: `#[new]` may not be combined with `#[classmethod]` `#[staticmethod]`, `#[classattr]`, `#[getter]`, and `#[setter]`
--> tests/ui/invalid_pymethods.rs:126:7
|
126 | #[new]
| ^^^
error: `#[new]` does not take any arguments
= help: did you mean `#[new] #[pyo3(signature = ())]`?
--> tests/ui/invalid_pymethods.rs:137:7
|
137 | #[new(signature = ())]
| ^^^
error: `#[new]` does not take any arguments
= note: this was previously accepted and ignored
--> tests/ui/invalid_pymethods.rs:143:11
|
143 | #[new = ()] // in this form there's no suggestion to move arguments to `#[pyo3()]` attribute
| ^
error: `#[classmethod]` does not take any arguments
= help: did you mean `#[classmethod] #[pyo3(signature = ())]`?
--> tests/ui/invalid_pymethods.rs:149:7
|
149 | #[classmethod(signature = ())]
| ^^^^^^^^^^^
error: `#[staticmethod]` does not take any arguments
= help: did you mean `#[staticmethod] #[pyo3(signature = ())]`?
--> tests/ui/invalid_pymethods.rs:155:7
|
155 | #[staticmethod(signature = ())]
| ^^^^^^^^^^^^
error: `#[classattr]` does not take any arguments
= help: did you mean `#[classattr] #[pyo3(signature = ())]`?
--> tests/ui/invalid_pymethods.rs:161:7
|
161 | #[classattr(signature = ())]
| ^^^^^^^^^
error: Python functions cannot have generic type parameters
--> tests/ui/invalid_pymethods.rs:167:23
|
167 | fn generic_method<T>(_value: T) {}
| ^
error: Python functions cannot have `impl Trait` arguments
--> tests/ui/invalid_pymethods.rs:172:49
|
172 | fn impl_trait_method_first_arg(_impl_trait: impl AsRef<PyAny>) {}
| ^^^^
error: Python functions cannot have `impl Trait` arguments
--> tests/ui/invalid_pymethods.rs:177:57
|
177 | fn impl_trait_method_second_arg(&self, _impl_trait: impl AsRef<PyAny>) {}
| ^^^^
error: `pass_module` cannot be used on Python methods
--> tests/ui/invalid_pymethods.rs:182:12
|
182 | #[pyo3(pass_module)]
| ^^^^^^^^^^^
error: Python objects are shared, so 'self' cannot be moved out of the Python interpreter.
Try `&self`, `&mut self, `slf: PyRef<'_, Self>` or `slf: PyRefMut<'_, Self>`.
--> tests/ui/invalid_pymethods.rs:188:29
|
188 | fn method_self_by_value(self) {}
| ^^^^
error: macros cannot be used as items in `#[pymethods]` impl blocks
= note: this was previously accepted and ignored
--> tests/ui/invalid_pymethods.rs:197:5
|
197 | macro_invocation!();
| ^^^^^^^^^^^^^^^^
error[E0277]: the trait bound `i32: From<BoundRef<'_, '_, PyType>>` is not satisfied
--> tests/ui/invalid_pymethods.rs:46:45
|
46 | fn classmethod_wrong_first_argument(_x: i32) -> Self {
| ^^^ the trait `From<BoundRef<'_, '_, PyType>>` is not implemented for `i32`, which is required by `BoundRef<'_, '_, PyType>: Into<_>`
|
= help: the following other types implement trait `From<T>`:
`i32` implements `From<bool>`
`i32` implements `From<i16>`
`i32` implements `From<i8>`
`i32` implements `From<u16>`
`i32` implements `From<u8>`
= note: required for `BoundRef<'_, '_, PyType>` to implement `Into<i32>`
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pymodule_two_pymodule_init.stderr | error: only one `#[pymodule_init]` may be specified
--> tests/ui/invalid_pymodule_two_pymodule_init.rs:13:5
|
13 | fn init2(_m: &Bound<'_, PyModule>) -> PyResult<()> {
| ^^
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pyclass_args.stderr | error: expected one of: `crate`, `dict`, `eq`, `eq_int`, `extends`, `freelist`, `frozen`, `get_all`, `hash`, `mapping`, `module`, `name`, `ord`, `rename_all`, `sequence`, `set_all`, `str`, `subclass`, `unsendable`, `weakref`
--> tests/ui/invalid_pyclass_args.rs:4:11
|
4 | #[pyclass(extend=pyo3::types::PyDict)]
| ^^^^^^
error: expected identifier
--> tests/ui/invalid_pyclass_args.rs:7:21
|
7 | #[pyclass(extends = "PyDict")]
| ^^^^^^^^
error: expected string literal
--> tests/ui/invalid_pyclass_args.rs:10:18
|
10 | #[pyclass(name = m::MyClass)]
| ^
error: expected a single identifier in double quotes
--> tests/ui/invalid_pyclass_args.rs:13:18
|
13 | #[pyclass(name = "Custom Name")]
| ^^^^^^^^^^^^^
error: expected string literal
--> tests/ui/invalid_pyclass_args.rs:16:18
|
16 | #[pyclass(name = CustomName)]
| ^^^^^^^^^^
error: expected string literal
--> tests/ui/invalid_pyclass_args.rs:19:24
|
19 | #[pyclass(rename_all = camelCase)]
| ^^^^^^^^^
error: expected a valid renaming rule, possible values are: "camelCase", "kebab-case", "lowercase", "PascalCase", "SCREAMING-KEBAB-CASE", "SCREAMING_SNAKE_CASE", "snake_case", "UPPERCASE"
--> tests/ui/invalid_pyclass_args.rs:22:24
|
22 | #[pyclass(rename_all = "Camel-Case")]
| ^^^^^^^^^^^^
error: expected string literal
--> tests/ui/invalid_pyclass_args.rs:25:20
|
25 | #[pyclass(module = my_module)]
| ^^^^^^^^^
error: expected one of: `crate`, `dict`, `eq`, `eq_int`, `extends`, `freelist`, `frozen`, `get_all`, `hash`, `mapping`, `module`, `name`, `ord`, `rename_all`, `sequence`, `set_all`, `str`, `subclass`, `unsendable`, `weakref`
--> tests/ui/invalid_pyclass_args.rs:28:11
|
28 | #[pyclass(weakrev)]
| ^^^^^^^
error: a `#[pyclass]` cannot be both a `mapping` and a `sequence`
--> tests/ui/invalid_pyclass_args.rs:32:8
|
32 | struct CannotBeMappingAndSequence {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: `eq_int` can only be used on simple enums.
--> tests/ui/invalid_pyclass_args.rs:53:11
|
53 | #[pyclass(eq_int)]
| ^^^^^^
error: The `hash` option requires the `frozen` option.
--> tests/ui/invalid_pyclass_args.rs:60:11
|
60 | #[pyclass(hash)]
| ^^^^
error: The `hash` option requires the `eq` option.
--> tests/ui/invalid_pyclass_args.rs:60:11
|
60 | #[pyclass(hash)]
| ^^^^
error: The `ord` option requires the `eq` option.
--> tests/ui/invalid_pyclass_args.rs:75:11
|
75 | #[pyclass(ord)]
| ^^^
error: expected one of: `get`, `set`, `name`
--> tests/ui/invalid_pyclass_args.rs:82:12
|
82 | #[pyo3(foo)]
| ^^^
error: expected one of: `get`, `set`, `name`
--> tests/ui/invalid_pyclass_args.rs:83:12
|
83 | #[pyo3(blah)]
| ^^^^
error: expected one of: `get`, `set`, `name`
--> tests/ui/invalid_pyclass_args.rs:85:12
|
85 | #[pyo3(pop)]
| ^^^
error: invalid format string: expected `'}'` but string was terminated
--> tests/ui/invalid_pyclass_args.rs:105:19
|
105 | #[pyclass(str = "{")]
| -^ expected `'}'` in format string
| |
| because of this opening brace
|
= note: if you intended to print `{`, you can escape it using `{{`
error: invalid format string: expected `'}'`, found `'$'`
--> tests/ui/invalid_pyclass_args.rs:109:19
|
109 | #[pyclass(str = "{$}")]
| -^ expected `'}'` in format string
| |
| because of this opening brace
|
= note: if you intended to print `{`, you can escape it using `{{`
error: The format string syntax is incompatible with any renaming via `name` or `rename_all`
--> tests/ui/invalid_pyclass_args.rs:133:31
|
133 | #[pyclass(name = "aaa", str = "unsafe: {unsafe_variable}")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: The format string syntax is incompatible with any renaming via `name` or `rename_all`
--> tests/ui/invalid_pyclass_args.rs:139:31
|
139 | #[pyclass(name = "aaa", str = "unsafe: {unsafe_variable}")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: The format string syntax is incompatible with any renaming via `name` or `rename_all`
--> tests/ui/invalid_pyclass_args.rs:144:17
|
144 | #[pyclass(str = "unsafe: {unsafe_variable}")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: The format string syntax is incompatible with any renaming via `name` or `rename_all`
--> tests/ui/invalid_pyclass_args.rs:150:54
|
150 | #[pyclass(rename_all = "SCREAMING_SNAKE_CASE", str = "{a_a}, {b_b}, {c_d_e}")]
| ^^^^^^^^^^^^^^^^^^^^^^^
error: No member found, you must provide a named or positionally specified member.
--> tests/ui/invalid_pyclass_args.rs:157:17
|
157 | #[pyclass(str = "{:?}")]
| ^^^^^^
error: No member found, you must provide a named or positionally specified member.
--> tests/ui/invalid_pyclass_args.rs:164:17
|
164 | #[pyclass(str = "{}")]
| ^^^^
error: The format string syntax cannot be used with enums
--> tests/ui/invalid_pyclass_args.rs:171:21
|
171 | #[pyclass(eq, str = "Stuff...")]
| ^^^^^^^^^^
error[E0119]: conflicting implementations of trait `HasCustomRichCmp` for type `EqOptAndManualRichCmp`
--> tests/ui/invalid_pyclass_args.rs:41:1
|
37 | #[pyclass(eq)]
| -------------- first implementation here
...
41 | #[pymethods]
| ^^^^^^^^^^^^ conflicting implementation for `EqOptAndManualRichCmp`
|
= note: this error originates in the attribute macro `pymethods` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0592]: duplicate definitions with name `__pymethod___richcmp____`
--> tests/ui/invalid_pyclass_args.rs:37:1
|
37 | #[pyclass(eq)]
| ^^^^^^^^^^^^^^ duplicate definitions for `__pymethod___richcmp____`
...
41 | #[pymethods]
| ------------ other definition for `__pymethod___richcmp____`
|
= note: this error originates in the attribute macro `pyclass` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0592]: duplicate definitions with name `__pymethod___hash____`
--> tests/ui/invalid_pyclass_args.rs:64:1
|
64 | #[pyclass(frozen, eq, hash)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definitions for `__pymethod___hash____`
...
68 | #[pymethods]
| ------------ other definition for `__pymethod___hash____`
|
= note: this error originates in the attribute macro `pyclass` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0592]: duplicate definitions with name `__pymethod___str____`
--> tests/ui/invalid_pyclass_args.rs:89:1
|
89 | #[pyclass(str)]
| ^^^^^^^^^^^^^^^ duplicate definitions for `__pymethod___str____`
...
98 | #[pymethods]
| ------------ other definition for `__pymethod___str____`
|
= note: this error originates in the attribute macro `pyclass` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0369]: binary operation `==` cannot be applied to type `&EqOptRequiresEq`
--> tests/ui/invalid_pyclass_args.rs:34:11
|
34 | #[pyclass(eq)]
| ^^
|
note: an implementation of `PartialEq` might be missing for `EqOptRequiresEq`
--> tests/ui/invalid_pyclass_args.rs:35:1
|
35 | struct EqOptRequiresEq {}
| ^^^^^^^^^^^^^^^^^^^^^^ must implement `PartialEq`
help: consider annotating `EqOptRequiresEq` with `#[derive(PartialEq)]`
|
35 + #[derive(PartialEq)]
36 | struct EqOptRequiresEq {}
|
error[E0369]: binary operation `!=` cannot be applied to type `&EqOptRequiresEq`
--> tests/ui/invalid_pyclass_args.rs:34:11
|
34 | #[pyclass(eq)]
| ^^
|
note: an implementation of `PartialEq` might be missing for `EqOptRequiresEq`
--> tests/ui/invalid_pyclass_args.rs:35:1
|
35 | struct EqOptRequiresEq {}
| ^^^^^^^^^^^^^^^^^^^^^^ must implement `PartialEq`
help: consider annotating `EqOptRequiresEq` with `#[derive(PartialEq)]`
|
35 + #[derive(PartialEq)]
36 | struct EqOptRequiresEq {}
|
error[E0034]: multiple applicable items in scope
--> tests/ui/invalid_pyclass_args.rs:37:1
|
37 | #[pyclass(eq)]
| ^^^^^^^^^^^^^^ multiple `__pymethod___richcmp____` found
|
note: candidate #1 is defined in an impl for the type `EqOptAndManualRichCmp`
--> tests/ui/invalid_pyclass_args.rs:37:1
|
37 | #[pyclass(eq)]
| ^^^^^^^^^^^^^^
note: candidate #2 is defined in an impl for the type `EqOptAndManualRichCmp`
--> tests/ui/invalid_pyclass_args.rs:41:1
|
41 | #[pymethods]
| ^^^^^^^^^^^^
= note: this error originates in the attribute macro `pyclass` which comes from the expansion of the attribute macro `pymethods` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0034]: multiple applicable items in scope
--> tests/ui/invalid_pyclass_args.rs:41:1
|
41 | #[pymethods]
| ^^^^^^^^^^^^ multiple `__pymethod___richcmp____` found
|
note: candidate #1 is defined in an impl for the type `EqOptAndManualRichCmp`
--> tests/ui/invalid_pyclass_args.rs:37:1
|
37 | #[pyclass(eq)]
| ^^^^^^^^^^^^^^
note: candidate #2 is defined in an impl for the type `EqOptAndManualRichCmp`
--> tests/ui/invalid_pyclass_args.rs:41:1
|
41 | #[pymethods]
| ^^^^^^^^^^^^
= note: this error originates in the attribute macro `pymethods` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `HashOptRequiresHash: Hash` is not satisfied
--> tests/ui/invalid_pyclass_args.rs:56:23
|
56 | #[pyclass(frozen, eq, hash)]
| ^^^^ the trait `Hash` is not implemented for `HashOptRequiresHash`
|
help: consider annotating `HashOptRequiresHash` with `#[derive(Hash)]`
|
58 + #[derive(Hash)]
59 | struct HashOptRequiresHash;
|
error[E0034]: multiple applicable items in scope
--> tests/ui/invalid_pyclass_args.rs:64:1
|
64 | #[pyclass(frozen, eq, hash)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ multiple `__pymethod___hash____` found
|
note: candidate #1 is defined in an impl for the type `HashOptAndManualHash`
--> tests/ui/invalid_pyclass_args.rs:64:1
|
64 | #[pyclass(frozen, eq, hash)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: candidate #2 is defined in an impl for the type `HashOptAndManualHash`
--> tests/ui/invalid_pyclass_args.rs:68:1
|
68 | #[pymethods]
| ^^^^^^^^^^^^
= note: this error originates in the attribute macro `pyclass` which comes from the expansion of the attribute macro `pymethods` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0034]: multiple applicable items in scope
--> tests/ui/invalid_pyclass_args.rs:68:1
|
68 | #[pymethods]
| ^^^^^^^^^^^^ multiple `__pymethod___hash____` found
|
note: candidate #1 is defined in an impl for the type `HashOptAndManualHash`
--> tests/ui/invalid_pyclass_args.rs:64:1
|
64 | #[pyclass(frozen, eq, hash)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: candidate #2 is defined in an impl for the type `HashOptAndManualHash`
--> tests/ui/invalid_pyclass_args.rs:68:1
|
68 | #[pymethods]
| ^^^^^^^^^^^^
= note: this error originates in the attribute macro `pymethods` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0034]: multiple applicable items in scope
--> tests/ui/invalid_pyclass_args.rs:89:1
|
89 | #[pyclass(str)]
| ^^^^^^^^^^^^^^^ multiple `__pymethod___str____` found
|
note: candidate #1 is defined in an impl for the type `StrOptAndManualStr`
--> tests/ui/invalid_pyclass_args.rs:89:1
|
89 | #[pyclass(str)]
| ^^^^^^^^^^^^^^^
note: candidate #2 is defined in an impl for the type `StrOptAndManualStr`
--> tests/ui/invalid_pyclass_args.rs:98:1
|
98 | #[pymethods]
| ^^^^^^^^^^^^
= note: this error originates in the attribute macro `pyclass` which comes from the expansion of the attribute macro `pymethods` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0034]: multiple applicable items in scope
--> tests/ui/invalid_pyclass_args.rs:98:1
|
98 | #[pymethods]
| ^^^^^^^^^^^^ multiple `__pymethod___str____` found
|
note: candidate #1 is defined in an impl for the type `StrOptAndManualStr`
--> tests/ui/invalid_pyclass_args.rs:89:1
|
89 | #[pyclass(str)]
| ^^^^^^^^^^^^^^^
note: candidate #2 is defined in an impl for the type `StrOptAndManualStr`
--> tests/ui/invalid_pyclass_args.rs:98:1
|
98 | #[pymethods]
| ^^^^^^^^^^^^
= note: this error originates in the attribute macro `pymethods` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0609]: no field `aaaa` on type `&Point`
--> tests/ui/invalid_pyclass_args.rs:113:17
|
113 | #[pyclass(str = "X: {aaaa}, Y: {y}, Z: {z}")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ unknown field
|
= note: available fields are: `x`, `y`, `z`
error[E0609]: no field `zzz` on type `&Point2`
--> tests/ui/invalid_pyclass_args.rs:121:17
|
121 | #[pyclass(str = "X: {x}, Y: {y}}}, Z: {zzz}")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unknown field
|
= note: available fields are: `x`, `y`, `z`
error[E0609]: no field `162543` on type `&Coord3`
--> tests/ui/invalid_pyclass_args.rs:129:17
|
129 | #[pyclass(str = "{0}, {162543}, {2}")]
| ^^^^^^^^^^^^^^^^^^^^ unknown field
|
= note: available fields are: `0`, `1`, `2`
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pymethods.rs | use pyo3::prelude::*;
#[pyclass]
struct MyClass {}
#[pymethods]
impl MyClass {
#[classattr]
fn class_attr_with_args(_foo: i32) {}
}
#[pymethods]
impl MyClass {
#[classattr(foobar)]
const CLASS_ATTR_WITH_ATTRIBUTE_ARG: i32 = 3;
}
#[pymethods]
impl MyClass {
fn staticmethod_without_attribute() {}
}
#[pymethods]
impl MyClass {
#[staticmethod]
fn staticmethod_with_receiver(&self) {}
}
#[pymethods]
impl MyClass {
#[classmethod]
fn classmethod_with_receiver(&self) {}
}
#[pymethods]
impl MyClass {
#[classmethod]
fn classmethod_missing_argument() -> Self {
Self {}
}
}
#[pymethods]
impl MyClass {
#[classmethod]
fn classmethod_wrong_first_argument(_x: i32) -> Self {
Self {}
}
}
#[pymethods]
impl MyClass {
#[getter(x)]
fn getter_without_receiver() {}
}
#[pymethods]
impl MyClass {
#[setter(x)]
fn setter_without_receiver() {}
}
#[pymethods]
impl MyClass {
#[pyo3(name = "__call__", text_signature = "()")]
fn text_signature_on_call() {}
}
#[pymethods]
impl MyClass {
#[getter(x)]
#[pyo3(text_signature = "()")]
fn text_signature_on_getter(&self) {}
}
#[pymethods]
impl MyClass {
#[setter(x)]
#[pyo3(text_signature = "()")]
fn text_signature_on_setter(&self) {}
}
#[pymethods]
impl MyClass {
#[classattr]
#[pyo3(text_signature = "()")]
fn text_signature_on_classattr() {}
}
#[pymethods]
impl MyClass {
#[pyo3(text_signature = 1)]
fn invalid_text_signature() {}
}
#[pymethods]
impl MyClass {
#[pyo3(text_signature = "()")]
#[pyo3(text_signature = None)]
fn duplicate_text_signature() {}
}
#[pymethods]
impl MyClass {
#[getter(x)]
#[pyo3(signature = ())]
fn signature_on_getter(&self) {}
}
#[pymethods]
impl MyClass {
#[setter(x)]
#[pyo3(signature = ())]
fn signature_on_setter(&self) {}
}
#[pymethods]
impl MyClass {
#[classattr]
#[pyo3(signature = ())]
fn signature_on_classattr() {}
}
#[pymethods]
impl MyClass {
#[new]
#[classmethod]
#[staticmethod]
#[classattr]
#[getter(x)]
#[setter(x)]
fn multiple_method_types() {}
}
#[pymethods]
impl MyClass {
#[new(signature = ())]
fn new_takes_no_arguments(&self) {}
}
#[pymethods]
impl MyClass {
#[new = ()] // in this form there's no suggestion to move arguments to `#[pyo3()]` attribute
fn new_takes_no_arguments_nv(&self) {}
}
#[pymethods]
impl MyClass {
#[classmethod(signature = ())]
fn classmethod_takes_no_arguments(&self) {}
}
#[pymethods]
impl MyClass {
#[staticmethod(signature = ())]
fn staticmethod_takes_no_arguments(&self) {}
}
#[pymethods]
impl MyClass {
#[classattr(signature = ())]
fn classattr_takes_no_arguments(&self) {}
}
#[pymethods]
impl MyClass {
fn generic_method<T>(_value: T) {}
}
#[pymethods]
impl MyClass {
fn impl_trait_method_first_arg(_impl_trait: impl AsRef<PyAny>) {}
}
#[pymethods]
impl MyClass {
fn impl_trait_method_second_arg(&self, _impl_trait: impl AsRef<PyAny>) {}
}
#[pymethods]
impl MyClass {
#[pyo3(pass_module)]
fn method_cannot_pass_module(&self, _m: &PyModule) {}
}
#[pymethods]
impl MyClass {
fn method_self_by_value(self) {}
}
macro_rules! macro_invocation {
() => {};
}
#[pymethods]
impl MyClass {
macro_invocation!();
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_base_class.rs | use pyo3::prelude::*;
use pyo3::types::PyBool;
#[pyclass(extends=PyBool)]
struct ExtendsBool;
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pymodule_glob.rs | #![allow(unused_imports)]
use pyo3::prelude::*;
#[pyfunction]
fn foo() -> usize {
0
}
#[pymodule]
mod module {
#[pymodule_export]
use super::*;
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_intopy_derive.stderr | error: cannot derive `IntoPyObject` for empty structs
--> tests/ui/invalid_intopy_derive.rs:4:11
|
4 | struct Foo();
| ^^
error: cannot derive `IntoPyObject` for empty structs
--> tests/ui/invalid_intopy_derive.rs:7:13
|
7 | struct Foo2 {}
| ^^
error: cannot derive `IntoPyObject` for empty enum
--> tests/ui/invalid_intopy_derive.rs:10:6
|
10 | enum EmptyEnum {}
| ^^^^^^^^^
error: cannot derive `IntoPyObject` for empty variants
--> tests/ui/invalid_intopy_derive.rs:14:5
|
14 | EmptyTuple(),
| ^^^^^^^^^^
error: cannot derive `IntoPyObject` for empty variants
--> tests/ui/invalid_intopy_derive.rs:20:5
|
20 | EmptyStruct {},
| ^^^^^^^^^^^
error: cannot derive `IntoPyObject` for empty structs
--> tests/ui/invalid_intopy_derive.rs:26:27
|
26 | struct EmptyTransparentTup();
| ^^
error: cannot derive `IntoPyObject` for empty structs
--> tests/ui/invalid_intopy_derive.rs:30:31
|
30 | struct EmptyTransparentStruct {}
| ^^
error: cannot derive `IntoPyObject` for empty variants
--> tests/ui/invalid_intopy_derive.rs:35:5
|
35 | EmptyTuple(),
| ^^^^^^^^^^
error: cannot derive `IntoPyObject` for empty variants
--> tests/ui/invalid_intopy_derive.rs:42:5
|
42 | EmptyStruct {},
| ^^^^^^^^^^^
error: transparent structs and variants can only have 1 field
--> tests/ui/invalid_intopy_derive.rs:48:35
|
48 | struct TransparentTupTooManyFields(String, String);
| ^^^^^^^^^^^^^^^^
error: transparent structs and variants can only have 1 field
--> tests/ui/invalid_intopy_derive.rs:52:39
|
52 | struct TransparentStructTooManyFields {
| _______________________________________^
53 | | foo: String,
54 | | bar: String,
55 | | }
| |_^
error: transparent structs and variants can only have 1 field
--> tests/ui/invalid_intopy_derive.rs:60:15
|
60 | EmptyTuple(String, String),
| ^^^^^^^^^^^^^^^^
error: transparent structs and variants can only have 1 field
--> tests/ui/invalid_intopy_derive.rs:67:17
|
67 | EmptyStruct {
| _________________^
68 | | foo: String,
69 | | bar: String,
70 | | },
| |_____^
error: expected `transparent` or `crate`
--> tests/ui/invalid_intopy_derive.rs:75:8
|
75 | #[pyo3(unknown = "should not work")]
| ^^^^^^^
error: #[derive(`IntoPyObject`)] is not supported for unions
--> tests/ui/invalid_intopy_derive.rs:81:1
|
81 | union Union {
| ^^^^^
error: cannot derive `IntoPyObject` for empty variants
--> tests/ui/invalid_intopy_derive.rs:87:5
|
87 | Unit,
| ^^^^
error: `attribute` is not supported by `IntoPyObject`
--> tests/ui/invalid_intopy_derive.rs:91:30
|
91 | struct TupleAttribute(#[pyo3(attribute)] String, usize);
| ^^^^^^^^^
error: `item` is not permitted on tuple struct elements.
--> tests/ui/invalid_intopy_derive.rs:94:25
|
94 | struct TupleItem(#[pyo3(item)] String, usize);
| ^^^^
error: `attribute` is not supported by `IntoPyObject`
--> tests/ui/invalid_intopy_derive.rs:98:12
|
98 | #[pyo3(attribute)]
| ^^^^^^^^^
error: `transparent` structs may not have `item` for the inner field
--> tests/ui/invalid_intopy_derive.rs:105:12
|
105 | #[pyo3(item)]
| ^^^^
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_result_conversion.stderr | error[E0277]: the trait bound `PyErr: From<MyError>` is not satisfied
--> tests/ui/invalid_result_conversion.rs:22:25
|
22 | fn should_not_work() -> Result<(), MyError> {
| ^^^^^^ the trait `From<MyError>` is not implemented for `PyErr`, which is required by `MyError: Into<PyErr>`
|
= help: the following other types implement trait `From<T>`:
`PyErr` implements `From<AddrParseError>`
`PyErr` implements `From<DecodeUtf16Error>`
`PyErr` implements `From<DowncastError<'_, '_>>`
`PyErr` implements `From<DowncastIntoError<'_>>`
`PyErr` implements `From<FromUtf16Error>`
`PyErr` implements `From<FromUtf8Error>`
`PyErr` implements `From<Infallible>`
`PyErr` implements `From<IntoInnerError<W>>`
and $N others
= note: required for `MyError` to implement `Into<PyErr>`
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pyfunctions.rs | use pyo3::prelude::*;
use pyo3::types::{PyDict, PyString, PyTuple};
#[pyfunction]
fn generic_function<T>(_value: T) {}
#[pyfunction]
fn impl_trait_function(_impl_trait: impl AsRef<PyAny>) {}
#[pyfunction]
fn wildcard_argument(_: i32) {}
#[pyfunction]
fn destructured_argument((_a, _b): (i32, i32)) {}
#[pyfunction]
fn function_with_required_after_option(_opt: Option<i32>, _x: i32) {}
#[pyfunction]
#[pyo3(signature=(*args))]
fn function_with_optional_args(args: Option<Bound<'_, PyTuple>>) {
let _ = args;
}
#[pyfunction]
#[pyo3(signature=(**kwargs))]
fn function_with_required_kwargs(kwargs: Bound<'_, PyDict>) {
let _ = kwargs;
}
#[pyfunction(pass_module)]
fn pass_module_but_no_arguments<'py>() {}
#[pyfunction(pass_module)]
fn first_argument_not_module<'a, 'py>(
_string: &str,
module: &'a Bound<'py, PyModule>,
) -> PyResult<Bound<'py, PyString>> {
module.name()
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_intopy_derive.rs | use pyo3::{IntoPyObject, IntoPyObjectRef};
#[derive(IntoPyObject, IntoPyObjectRef)]
struct Foo();
#[derive(IntoPyObject, IntoPyObjectRef)]
struct Foo2 {}
#[derive(IntoPyObject, IntoPyObjectRef)]
enum EmptyEnum {}
#[derive(IntoPyObject, IntoPyObjectRef)]
enum EnumWithEmptyTupleVar {
EmptyTuple(),
Valid(String),
}
#[derive(IntoPyObject, IntoPyObjectRef)]
enum EnumWithEmptyStructVar {
EmptyStruct {},
Valid(String),
}
#[derive(IntoPyObject, IntoPyObjectRef)]
#[pyo3(transparent)]
struct EmptyTransparentTup();
#[derive(IntoPyObject, IntoPyObjectRef)]
#[pyo3(transparent)]
struct EmptyTransparentStruct {}
#[derive(IntoPyObject, IntoPyObjectRef)]
enum EnumWithTransparentEmptyTupleVar {
#[pyo3(transparent)]
EmptyTuple(),
Valid(String),
}
#[derive(IntoPyObject, IntoPyObjectRef)]
enum EnumWithTransparentEmptyStructVar {
#[pyo3(transparent)]
EmptyStruct {},
Valid(String),
}
#[derive(IntoPyObject, IntoPyObjectRef)]
#[pyo3(transparent)]
struct TransparentTupTooManyFields(String, String);
#[derive(IntoPyObject, IntoPyObjectRef)]
#[pyo3(transparent)]
struct TransparentStructTooManyFields {
foo: String,
bar: String,
}
#[derive(IntoPyObject, IntoPyObjectRef)]
enum EnumWithTransparentTupleTooMany {
#[pyo3(transparent)]
EmptyTuple(String, String),
Valid(String),
}
#[derive(IntoPyObject, IntoPyObjectRef)]
enum EnumWithTransparentStructTooMany {
#[pyo3(transparent)]
EmptyStruct {
foo: String,
bar: String,
},
Valid(String),
}
#[derive(IntoPyObject, IntoPyObjectRef)]
#[pyo3(unknown = "should not work")]
struct UnknownContainerAttr {
a: String,
}
#[derive(IntoPyObject, IntoPyObjectRef)]
union Union {
a: usize,
}
#[derive(IntoPyObject, IntoPyObjectRef)]
enum UnitEnum {
Unit,
}
#[derive(IntoPyObject, IntoPyObjectRef)]
struct TupleAttribute(#[pyo3(attribute)] String, usize);
#[derive(IntoPyObject, IntoPyObjectRef)]
struct TupleItem(#[pyo3(item)] String, usize);
#[derive(IntoPyObject, IntoPyObjectRef)]
struct StructAttribute {
#[pyo3(attribute)]
foo: String,
}
#[derive(IntoPyObject, IntoPyObjectRef)]
#[pyo3(transparent)]
struct StructTransparentItem {
#[pyo3(item)]
foo: String,
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/static_ref.rs | use pyo3::prelude::*;
use pyo3::types::PyList;
#[pyfunction]
fn static_ref(list: &'static Bound<'_, PyList>) -> usize {
list.len()
}
#[pyfunction]
fn static_py(list: &Bound<'static, PyList>) -> usize {
list.len()
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pyclass_item.rs | use pyo3::prelude::*;
#[pyclass]
fn foo() {}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_argument_attributes.stderr | error: expected `cancel_handle` or `from_py_with`
--> tests/ui/invalid_argument_attributes.rs:4:29
|
4 | fn invalid_attribute(#[pyo3(get)] _param: String) {}
| ^^^
error: expected `=`
--> tests/ui/invalid_argument_attributes.rs:7:45
|
7 | fn from_py_with_no_value(#[pyo3(from_py_with)] _param: String) {}
| ^
error: expected `cancel_handle` or `from_py_with`
--> tests/ui/invalid_argument_attributes.rs:10:31
|
10 | fn from_py_with_string(#[pyo3("from_py_with")] _param: String) {}
| ^^^^^^^^^^^^^^
error: expected string literal
--> tests/ui/invalid_argument_attributes.rs:13:58
|
13 | fn from_py_with_value_not_a_string(#[pyo3(from_py_with = func)] _param: String) {}
| ^^^^
error: `from_py_with` may only be specified once per argument
--> tests/ui/invalid_argument_attributes.rs:16:56
|
16 | fn from_py_with_repeated(#[pyo3(from_py_with = "func", from_py_with = "func")] _param: String) {}
| ^^^^^^^^^^^^
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/reject_generics.stderr | error: #[pyclass] cannot have generic parameters. For an explanation, see https://pyo3.rs/v0.23.0-dev/class.html#no-generic-parameters
--> tests/ui/reject_generics.rs:4:25
|
4 | struct ClassWithGenerics<A> {
| ^
error: #[pyclass] cannot have lifetime parameters. For an explanation, see https://pyo3.rs/v0.23.0-dev/class.html#no-lifetime-parameters
--> tests/ui/reject_generics.rs:9:27
|
9 | struct ClassWithLifetimes<'a> {
| ^^
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pymethod_enum.stderr | error[E0271]: type mismatch resolving `<ComplexEnum as PyClass>::Frozen == False`
--> tests/ui/invalid_pymethod_enum.rs:11:24
|
11 | fn mutate_in_place(&mut self) {
| ^ expected `False`, found `True`
|
note: required by a bound in `extract_pyclass_ref_mut`
--> src/impl_/extract_argument.rs
|
| pub fn extract_pyclass_ref_mut<'a, 'py: 'a, T: PyClass<Frozen = False>>(
| ^^^^^^^^^^^^^^ required by this bound in `extract_pyclass_ref_mut`
error[E0271]: type mismatch resolving `<ComplexEnum as PyClass>::Frozen == False`
--> tests/ui/invalid_pymethod_enum.rs:9:1
|
9 | #[pymethods]
| ^^^^^^^^^^^^ expected `False`, found `True`
|
note: required by a bound in `PyRefMut`
--> src/pycell.rs
|
| pub struct PyRefMut<'p, T: PyClass<Frozen = False>> {
| ^^^^^^^^^^^^^^ required by this bound in `PyRefMut`
= note: this error originates in the attribute macro `pymethods` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0271]: type mismatch resolving `<TupleEnum as PyClass>::Frozen == False`
--> tests/ui/invalid_pymethod_enum.rs:27:24
|
27 | fn mutate_in_place(&mut self) {
| ^ expected `False`, found `True`
|
note: required by a bound in `extract_pyclass_ref_mut`
--> src/impl_/extract_argument.rs
|
| pub fn extract_pyclass_ref_mut<'a, 'py: 'a, T: PyClass<Frozen = False>>(
| ^^^^^^^^^^^^^^ required by this bound in `extract_pyclass_ref_mut`
error[E0271]: type mismatch resolving `<TupleEnum as PyClass>::Frozen == False`
--> tests/ui/invalid_pymethod_enum.rs:25:1
|
25 | #[pymethods]
| ^^^^^^^^^^^^ expected `False`, found `True`
|
note: required by a bound in `PyRefMut`
--> src/pycell.rs
|
| pub struct PyRefMut<'p, T: PyClass<Frozen = False>> {
| ^^^^^^^^^^^^^^ required by this bound in `PyRefMut`
= note: this error originates in the attribute macro `pymethods` (in Nightly builds, run with -Z macro-backtrace for more info)
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_closure.stderr | error[E0597]: `local_data` does not live long enough
--> tests/ui/invalid_closure.rs:7:27
|
6 | let local_data = vec![0, 1, 2, 3, 4];
| ---------- binding `local_data` declared here
7 | let ref_: &[u8] = &local_data;
| ^^^^^^^^^^^ borrowed value does not live long enough
...
14 | PyCFunction::new_closure(py, None, None, closure_fn)
| ---------------------------------------------------- argument requires that `local_data` is borrowed for `'static`
...
17 | });
| - `local_data` dropped here while still borrowed
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/abi3_dict.stderr | error: `dict` requires Python >= 3.9 when using the `abi3` feature
--> tests/ui/abi3_dict.rs:4:11
|
4 | #[pyclass(dict)]
| ^^^^
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/abi3_weakref.stderr | error: `weakref` requires Python >= 3.9 when using the `abi3` feature
--> tests/ui/abi3_weakref.rs:4:11
|
4 | #[pyclass(weakref)]
| ^^^^^^^
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_base_class.stderr | error[E0277]: pyclass `PyBool` cannot be subclassed
--> tests/ui/invalid_base_class.rs:4:19
|
4 | #[pyclass(extends=PyBool)]
| ^^^^^^ required for `#[pyclass(extends=PyBool)]`
|
= help: the trait `PyClassBaseType` is not implemented for `PyBool`
= note: `PyBool` must have `#[pyclass(subclass)]` to be eligible for subclassing
= help: the following other types implement trait `PyClassBaseType`:
PyAny
PyArithmeticError
PyAssertionError
PyAttributeError
PyBaseException
PyBaseExceptionGroup
PyBlockingIOError
PyBrokenPipeError
and $N others
note: required by a bound in `PyClassImpl::BaseType`
--> src/impl_/pyclass.rs
|
| type BaseType: PyTypeInfo + PyClassBaseType;
| ^^^^^^^^^^^^^^^ required by this bound in `PyClassImpl::BaseType`
error[E0277]: pyclass `PyBool` cannot be subclassed
--> tests/ui/invalid_base_class.rs:4:1
|
4 | #[pyclass(extends=PyBool)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required for `#[pyclass(extends=PyBool)]`
|
= help: the trait `PyClassBaseType` is not implemented for `PyBool`
= note: `PyBool` must have `#[pyclass(subclass)]` to be eligible for subclassing
= help: the following other types implement trait `PyClassBaseType`:
PyAny
PyArithmeticError
PyAssertionError
PyAttributeError
PyBaseException
PyBaseExceptionGroup
PyBlockingIOError
PyBrokenPipeError
and $N others
= note: this error originates in the attribute macro `pyclass` (in Nightly builds, run with -Z macro-backtrace for more info)
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pymethod_names.stderr | error: `name` may only be specified once
--> tests/ui/invalid_pymethod_names.rs:11:14
|
11 | #[getter(number)]
| ^^^^^^
error: `name` may only be specified once
--> tests/ui/invalid_pymethod_names.rs:18:12
|
18 | #[pyo3(name = "bar")]
| ^^^^
error: `name` not allowed with `#[new]`
--> tests/ui/invalid_pymethod_names.rs:24:19
|
24 | #[pyo3(name = "makenew")]
| ^^^^^^^^^
error: expected ident or string literal for property name
--> tests/ui/invalid_pymethod_names.rs:31:14
|
31 | #[getter(1)]
| ^
error: expected `#[getter(name)]` to set the name
--> tests/ui/invalid_pymethod_names.rs:37:14
|
37 | #[getter = 1]
| ^
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/wrong_aspyref_lifetimes.stderr | error: lifetime may not live long enough
--> tests/ui/wrong_aspyref_lifetimes.rs:7:58
|
7 | let dict: &Bound<'_, PyDict> = Python::with_gil(|py| dict.bind(py));
| --- ^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'2`
| | |
| | return type of closure is &'2 pyo3::Bound<'_, PyDict>
| has type `Python<'1>`
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/reject_generics.rs | use pyo3::prelude::*;
#[pyclass]
struct ClassWithGenerics<A> {
a: A,
}
#[pyclass]
struct ClassWithLifetimes<'a> {
a: &'a str,
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_frompy_derive.stderr | error: cannot derive FromPyObject for empty structs and variants
--> tests/ui/invalid_frompy_derive.rs:4:11
|
4 | struct Foo();
| ^^
error: cannot derive FromPyObject for empty structs and variants
--> tests/ui/invalid_frompy_derive.rs:7:13
|
7 | struct Foo2 {}
| ^^
error: cannot derive FromPyObject for empty enum
--> tests/ui/invalid_frompy_derive.rs:10:6
|
10 | enum EmptyEnum {}
| ^^^^^^^^^
error: cannot derive FromPyObject for empty structs and variants
--> tests/ui/invalid_frompy_derive.rs:14:15
|
14 | EmptyTuple(),
| ^^
error: cannot derive FromPyObject for empty structs and variants
--> tests/ui/invalid_frompy_derive.rs:20:17
|
20 | EmptyStruct {},
| ^^
error: cannot derive FromPyObject for empty structs and variants
--> tests/ui/invalid_frompy_derive.rs:26:27
|
26 | struct EmptyTransparentTup();
| ^^
error: cannot derive FromPyObject for empty structs and variants
--> tests/ui/invalid_frompy_derive.rs:30:31
|
30 | struct EmptyTransparentStruct {}
| ^^
error: cannot derive FromPyObject for empty structs and variants
--> tests/ui/invalid_frompy_derive.rs:35:15
|
35 | EmptyTuple(),
| ^^
error: cannot derive FromPyObject for empty structs and variants
--> tests/ui/invalid_frompy_derive.rs:42:17
|
42 | EmptyStruct {},
| ^^
error: transparent structs and variants can only have 1 field
--> tests/ui/invalid_frompy_derive.rs:48:35
|
48 | struct TransparentTupTooManyFields(String, String);
| ^^^^^^^^^^^^^^^^
error: transparent structs and variants can only have 1 field
--> tests/ui/invalid_frompy_derive.rs:52:39
|
52 | struct TransparentStructTooManyFields {
| _______________________________________^
53 | | foo: String,
54 | | bar: String,
55 | | }
| |_^
error: transparent structs and variants can only have 1 field
--> tests/ui/invalid_frompy_derive.rs:60:15
|
60 | EmptyTuple(String, String),
| ^^^^^^^^^^^^^^^^
error: transparent structs and variants can only have 1 field
--> tests/ui/invalid_frompy_derive.rs:67:17
|
67 | EmptyStruct {
| _________________^
68 | | foo: String,
69 | | bar: String,
70 | | },
| |_____^
error: expected one of: `attribute`, `item`, `from_py_with`
--> tests/ui/invalid_frompy_derive.rs:76:12
|
76 | #[pyo3(attr)]
| ^^^^
error: expected string literal
--> tests/ui/invalid_frompy_derive.rs:82:22
|
82 | #[pyo3(attribute(1))]
| ^
error: expected at most one argument: `attribute` or `attribute("name")`
--> tests/ui/invalid_frompy_derive.rs:88:25
|
88 | #[pyo3(attribute("a", "b"))]
| ^
error: attribute name cannot be empty
--> tests/ui/invalid_frompy_derive.rs:94:22
|
94 | #[pyo3(attribute(""))]
| ^^
error: unexpected end of input, expected string literal
--> tests/ui/invalid_frompy_derive.rs:100:22
|
100 | #[pyo3(attribute())]
| ^
error: expected at most one argument: `item` or `item(key)`
--> tests/ui/invalid_frompy_derive.rs:106:20
|
106 | #[pyo3(item("a", "b"))]
| ^
error: unexpected end of input, expected literal
--> tests/ui/invalid_frompy_derive.rs:112:17
|
112 | #[pyo3(item())]
| ^
error: only one of `attribute` or `item` can be provided
--> tests/ui/invalid_frompy_derive.rs:118:5
|
118 | #[pyo3(item, attribute)]
| ^
error: expected one of: `transparent`, `from_item_all`, `annotation`, `crate`
--> tests/ui/invalid_frompy_derive.rs:123:8
|
123 | #[pyo3(unknown = "should not work")]
| ^^^^^^^
error: `annotation` is unsupported for structs
--> tests/ui/invalid_frompy_derive.rs:129:21
|
129 | #[pyo3(annotation = "should not work")]
| ^^^^^^^^^^^^^^^^^
error: expected string literal
--> tests/ui/invalid_frompy_derive.rs:136:25
|
136 | #[pyo3(annotation = 1)]
| ^
error: FromPyObject can be derived with at most one lifetime parameter
--> tests/ui/invalid_frompy_derive.rs:141:22
|
141 | enum TooManyLifetimes<'a, 'b> {
| ^
error: #[derive(FromPyObject)] is not supported for unions
--> tests/ui/invalid_frompy_derive.rs:147:1
|
147 | union Union {
| ^^^^^
error: cannot derive FromPyObject for empty structs and variants
--> tests/ui/invalid_frompy_derive.rs:151:10
|
151 | #[derive(FromPyObject)]
| ^^^^^^^^^^^^
|
= note: this error originates in the derive macro `FromPyObject` (in Nightly builds, run with -Z macro-backtrace for more info)
error: expected `=`
--> tests/ui/invalid_frompy_derive.rs:158:24
|
158 | #[pyo3(from_py_with)]
| ^
error: expected string literal
--> tests/ui/invalid_frompy_derive.rs:164:27
|
164 | #[pyo3(from_py_with = func)]
| ^^^^
error: `getter` is not permitted on tuple struct elements.
--> tests/ui/invalid_frompy_derive.rs:169:27
|
169 | struct InvalidTupleGetter(#[pyo3(item("foo"))] String);
| ^
error: `transparent` structs may not have a `getter` for the inner field
--> tests/ui/invalid_frompy_derive.rs:175:5
|
175 | field: String,
| ^^^^^
error: `transparent` structs may not have a `getter` for the inner field
--> tests/ui/invalid_frompy_derive.rs:186:5
|
186 | field: String,
| ^^^^^
error: `from_item_all` may only be provided once
--> tests/ui/invalid_frompy_derive.rs:190:23
|
190 | #[pyo3(from_item_all, from_item_all)]
| ^^^^^^^^^^^^^
error: Useless `item` - the struct is already annotated with `from_item_all`
--> tests/ui/invalid_frompy_derive.rs:196:8
|
196 | #[pyo3(from_item_all)]
| ^^^^^^^^^^^^^
error: The struct is already annotated with `from_item_all`, `attribute` is not allowed
--> tests/ui/invalid_frompy_derive.rs:203:8
|
203 | #[pyo3(from_item_all)]
| ^^^^^^^^^^^^^
error: The struct is already annotated with `from_item_all`, `attribute` is not allowed
--> tests/ui/invalid_frompy_derive.rs:210:8
|
210 | #[pyo3(from_item_all)]
| ^^^^^^^^^^^^^
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/abi3_nativetype_inheritance.rs | //! With abi3, we cannot inherit native types.
use pyo3::prelude::*;
use pyo3::types::PyDict;
#[pyclass(extends=PyDict)]
struct TestClass {}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pymodule_in_root.rs | use pyo3::prelude::*;
#[pymodule]
#[path = "empty.rs"] // to silence error related to missing file
mod invalid_pymodule_in_root_module;
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_argument_attributes.rs | use pyo3::prelude::*;
#[pyfunction]
fn invalid_attribute(#[pyo3(get)] _param: String) {}
#[pyfunction]
fn from_py_with_no_value(#[pyo3(from_py_with)] _param: String) {}
#[pyfunction]
fn from_py_with_string(#[pyo3("from_py_with")] _param: String) {}
#[pyfunction]
fn from_py_with_value_not_a_string(#[pyo3(from_py_with = func)] _param: String) {}
#[pyfunction]
fn from_py_with_repeated(#[pyo3(from_py_with = "func", from_py_with = "func")] _param: String) {}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/abi3_dict.rs | //! With abi3, dict not supported until python 3.9 or greater
use pyo3::prelude::*;
#[pyclass(dict)]
struct TestClass {}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/missing_intopy.stderr | error[E0277]: `Blah` cannot be converted to a Python object
--> tests/ui/missing_intopy.rs:4:14
|
4 | fn blah() -> Blah {
| ^^^^ the trait `IntoPyObject<'_>` is not implemented for `Blah`
|
= note: `IntoPyObject` is automatically implemented by the `#[pyclass]` macro
= note: if you do not wish to have a corresponding Python type, implement it manually
= note: if you do not own `Blah` you can perform a manual conversion to one of the types in `pyo3::types::*`
= help: the following other types implement trait `IntoPyObject<'py>`:
&&'a T
&&OsStr
&&Path
&&str
&'a (T0, T1)
&'a (T0, T1, T2)
&'a (T0, T1, T2, T3)
&'a (T0, T1, T2, T3, T4)
and $N others
note: required by a bound in `UnknownReturnType::<T>::wrap`
--> src/impl_/wrap.rs
|
| pub fn wrap<'py>(&self, _: T) -> T
| ---- required by a bound in this associated function
| where
| T: IntoPyObject<'py>,
| ^^^^^^^^^^^^^^^^^ required by this bound in `UnknownReturnType::<T>::wrap`
error[E0599]: no method named `map_err` found for struct `Blah` in the current scope
--> tests/ui/missing_intopy.rs:4:14
|
1 | struct Blah;
| ----------- method `map_err` not found for this struct
...
4 | fn blah() -> Blah {
| ^^^^ method not found in `Blah`
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pymodule_args.rs | use pyo3::prelude::*;
#[pymodule(some_arg)]
fn module(m: &Bound<'_, PyModule>) -> PyResult<()> {
Ok(())
}
fn main(){}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/empty.rs | // see invalid_pymodule_in_root.rs
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pymethods_buffer.stderr | error: `__getbuffer__` must be `unsafe fn`
--> tests/ui/invalid_pymethods_buffer.rs:9:8
|
9 | fn getbuffer_must_be_unsafe(&self, _view: *mut pyo3::ffi::Py_buffer, _flags: std::os::raw::c_int) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: `__releasebuffer__` must be `unsafe fn`
--> tests/ui/invalid_pymethods_buffer.rs:15:8
|
15 | fn releasebuffer_must_be_unsafe(&self, _view: *mut pyo3::ffi::Py_buffer) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pymodule_args.stderr | error: expected one of: `name`, `crate`, `module`, `submodule`, `gil_used`
--> tests/ui/invalid_pymodule_args.rs:3:12
|
3 | #[pymodule(some_arg)]
| ^^^^^^^^
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_proto_pymethods.stderr | error: Expected 1 arguments, got 0
--> tests/ui/invalid_proto_pymethods.rs:19:8
|
19 | fn truediv_expects_one_argument(&self) -> PyResult<()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Expected 1 arguments, got 0
--> tests/ui/invalid_proto_pymethods.rs:27:8
|
27 | fn truediv_expects_one_argument_py(&self, _py: Python<'_>) -> PyResult<()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: `signature` cannot be used with magic method `__bool__`
--> tests/ui/invalid_proto_pymethods.rs:38:31
|
38 | #[pyo3(name = "__bool__", signature = ())]
| ^^^^^^^^^
error: `text_signature` cannot be used with magic method `__bool__`
--> tests/ui/invalid_proto_pymethods.rs:46:31
|
46 | #[pyo3(name = "__bool__", text_signature = "")]
| ^^^^^^^^^^^^^^
error[E0034]: multiple applicable items in scope
--> tests/ui/invalid_proto_pymethods.rs:55:1
|
55 | #[pymethods]
| ^^^^^^^^^^^^ multiple `__pymethod___richcmp____` found
|
note: candidate #1 is defined in an impl for the type `EqAndRichcmp`
--> tests/ui/invalid_proto_pymethods.rs:55:1
|
55 | #[pymethods]
| ^^^^^^^^^^^^
note: candidate #2 is defined in an impl for the type `EqAndRichcmp`
--> tests/ui/invalid_proto_pymethods.rs:55:1
|
55 | #[pymethods]
| ^^^^^^^^^^^^
= note: this error originates in the macro `::pyo3::impl_::pyclass::generate_pyclass_richcompare_slot` which comes from the expansion of the attribute macro `pymethods` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0119]: conflicting implementations of trait `HasCustomRichCmp` for type `EqAndRichcmp`
--> tests/ui/invalid_proto_pymethods.rs:55:1
|
55 | #[pymethods]
| ^^^^^^^^^^^^
| |
| first implementation here
| conflicting implementation for `EqAndRichcmp`
|
= note: this error originates in the macro `::pyo3::impl_::pyclass::generate_pyclass_richcompare_slot` which comes from the expansion of the attribute macro `pymethods` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0592]: duplicate definitions with name `__pymethod___richcmp____`
--> tests/ui/invalid_proto_pymethods.rs:55:1
|
55 | #[pymethods]
| ^^^^^^^^^^^^
| |
| duplicate definitions for `__pymethod___richcmp____`
| other definition for `__pymethod___richcmp____`
|
= note: this error originates in the macro `::pyo3::impl_::pyclass::generate_pyclass_richcompare_slot` which comes from the expansion of the attribute macro `pymethods` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0034]: multiple applicable items in scope
--> tests/ui/invalid_proto_pymethods.rs:55:1
|
55 | #[pymethods]
| ^^^^^^^^^^^^ multiple `__pymethod___richcmp____` found
|
note: candidate #1 is defined in an impl for the type `EqAndRichcmp`
--> tests/ui/invalid_proto_pymethods.rs:55:1
|
55 | #[pymethods]
| ^^^^^^^^^^^^
note: candidate #2 is defined in an impl for the type `EqAndRichcmp`
--> tests/ui/invalid_proto_pymethods.rs:55:1
|
55 | #[pymethods]
| ^^^^^^^^^^^^
= note: this error originates in the attribute macro `pymethods` (in Nightly builds, run with -Z macro-backtrace for more info)
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/duplicate_pymodule_submodule.rs | #[pyo3::pymodule]
mod mymodule {
#[pyo3::pymodule(submodule)]
mod submod {}
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pyclass_item.stderr | error: #[pyclass] only supports structs and enums.
--> tests/ui/invalid_pyclass_item.rs:4:1
|
4 | fn foo() {}
| ^^^^^^^^^^^
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/missing_intopy.rs | struct Blah;
#[pyo3::pyfunction]
fn blah() -> Blah {
Blah
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/abi3_weakref.rs | //! With abi3, weakref not supported until python 3.9 or greater
use pyo3::prelude::*;
#[pyclass(weakref)]
struct TestClass {}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/pyclass_send.rs | use pyo3::prelude::*;
use std::os::raw::c_void;
#[pyclass]
struct NotSyncNotSend(*mut c_void);
#[pyclass]
struct SendNotSync(*mut c_void);
unsafe impl Send for SendNotSync {}
#[pyclass]
struct SyncNotSend(*mut c_void);
unsafe impl Sync for SyncNotSend {}
// None of the `unsendable` forms below should fail to compile
#[pyclass(unsendable)]
struct NotSyncNotSendUnsendable(*mut c_void);
#[pyclass(unsendable)]
struct SendNotSyncUnsendable(*mut c_void);
unsafe impl Send for SendNotSyncUnsendable {}
#[pyclass(unsendable)]
struct SyncNotSendUnsendable(*mut c_void);
unsafe impl Sync for SyncNotSendUnsendable {}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_closure.rs | use pyo3::prelude::*;
use pyo3::types::{PyCFunction, PyDict, PyTuple};
fn main() {
let fun: Py<PyCFunction> = Python::with_gil(|py| {
let local_data = vec![0, 1, 2, 3, 4];
let ref_: &[u8] = &local_data;
let closure_fn =
|_args: &Bound<'_, PyTuple>, _kwargs: Option<&Bound<'_, PyDict>>| -> PyResult<()> {
println!("This is five: {:?}", ref_.len());
Ok(())
};
PyCFunction::new_closure(py, None, None, closure_fn)
.unwrap()
.into()
});
Python::with_gil(|py| {
fun.call0(py).unwrap();
});
}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/forbid_unsafe.rs | #![forbid(unsafe_code)]
#![forbid(unsafe_op_in_unsafe_fn)]
use pyo3::*;
#[allow(unexpected_cfgs)]
#[path = "../../src/tests/hygiene/mod.rs"]
mod hygiene;
mod gh_4394 {
use pyo3::prelude::*;
#[derive(Eq, Ord, PartialEq, PartialOrd, Clone)]
#[pyclass(get_all)]
pub struct VersionSpecifier {
pub(crate) operator: Operator,
pub(crate) version: Version,
}
#[derive(Eq, Ord, PartialEq, PartialOrd, Debug, Hash, Clone, Copy)]
#[pyo3::pyclass(eq, eq_int)]
pub enum Operator {
Equal,
}
#[derive(Clone, Eq, PartialEq, PartialOrd, Ord)]
#[pyclass]
pub struct Version;
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pymodule_two_pymodule_init.rs | use pyo3::prelude::*;
#[pymodule]
mod module {
use pyo3::prelude::*;
#[pymodule_init]
fn init(_m: &Bound<'_, PyModule>) -> PyResult<()> {
Ok(())
}
#[pymodule_init]
fn init2(_m: &Bound<'_, PyModule>) -> PyResult<()> {
Ok(())
}
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pyclass_args.rs | use pyo3::prelude::*;
use std::fmt::{Display, Formatter};
#[pyclass(extend=pyo3::types::PyDict)]
struct TypoIntheKey {}
#[pyclass(extends = "PyDict")]
struct InvalidExtends {}
#[pyclass(name = m::MyClass)]
struct InvalidName {}
#[pyclass(name = "Custom Name")]
struct InvalidName2 {}
#[pyclass(name = CustomName)]
struct DeprecatedName {}
#[pyclass(rename_all = camelCase)]
struct InvalidRenamingRule {}
#[pyclass(rename_all = "Camel-Case")]
struct InvalidRenamingRule2 {}
#[pyclass(module = my_module)]
struct InvalidModule {}
#[pyclass(weakrev)]
struct InvalidArg {}
#[pyclass(mapping, sequence)]
struct CannotBeMappingAndSequence {}
#[pyclass(eq)]
struct EqOptRequiresEq {}
#[pyclass(eq)]
#[derive(PartialEq)]
struct EqOptAndManualRichCmp {}
#[pymethods]
impl EqOptAndManualRichCmp {
fn __richcmp__(
&self,
_py: Python,
_other: Bound<'_, PyAny>,
_op: pyo3::pyclass::CompareOp,
) -> PyResult<PyObject> {
todo!()
}
}
#[pyclass(eq_int)]
struct NoEqInt {}
#[pyclass(frozen, eq, hash)]
#[derive(PartialEq)]
struct HashOptRequiresHash;
#[pyclass(hash)]
#[derive(Hash)]
struct HashWithoutFrozenAndEq;
#[pyclass(frozen, eq, hash)]
#[derive(PartialEq, Hash)]
struct HashOptAndManualHash {}
#[pymethods]
impl HashOptAndManualHash {
fn __hash__(&self) -> u64 {
todo!()
}
}
#[pyclass(ord)]
struct InvalidOrderedStruct {
inner: i32,
}
#[pyclass]
struct MultipleErrors {
#[pyo3(foo)]
#[pyo3(blah)]
x: i32,
#[pyo3(pop)]
y: i32,
}
#[pyclass(str)]
struct StrOptAndManualStr {}
impl Display for StrOptAndManualStr {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self)
}
}
#[pymethods]
impl StrOptAndManualStr {
fn __str__(&self) -> String {
todo!()
}
}
#[pyclass(str = "{")]
#[derive(PartialEq)]
struct Coord(u32, u32, u32);
#[pyclass(str = "{$}")]
#[derive(PartialEq)]
struct Coord2(u32, u32, u32);
#[pyclass(str = "X: {aaaa}, Y: {y}, Z: {z}")]
#[derive(PartialEq, Eq, Clone, PartialOrd)]
pub struct Point {
x: i32,
y: i32,
z: i32,
}
#[pyclass(str = "X: {x}, Y: {y}}}, Z: {zzz}")]
#[derive(PartialEq, Eq, Clone, PartialOrd)]
pub struct Point2 {
x: i32,
y: i32,
z: i32,
}
#[pyclass(str = "{0}, {162543}, {2}")]
#[derive(PartialEq)]
struct Coord3(u32, u32, u32);
#[pyclass(name = "aaa", str = "unsafe: {unsafe_variable}")]
struct StructRenamingWithStrFormatter {
#[pyo3(name = "unsafe", get, set)]
unsafe_variable: usize,
}
#[pyclass(name = "aaa", str = "unsafe: {unsafe_variable}")]
struct StructRenamingWithStrFormatter2 {
unsafe_variable: usize,
}
#[pyclass(str = "unsafe: {unsafe_variable}")]
struct StructRenamingWithStrFormatter3 {
#[pyo3(name = "unsafe", get, set)]
unsafe_variable: usize,
}
#[pyclass(rename_all = "SCREAMING_SNAKE_CASE", str = "{a_a}, {b_b}, {c_d_e}")]
struct RenameAllVariantsStruct {
a_a: u32,
b_b: u32,
c_d_e: String,
}
#[pyclass(str = "{:?}")]
#[derive(Debug)]
struct StructWithNoMember {
a: String,
b: String,
}
#[pyclass(str = "{}")]
#[derive(Debug)]
struct StructWithNoMember2 {
a: String,
b: String,
}
#[pyclass(eq, str = "Stuff...")]
#[derive(Debug, PartialEq)]
pub enum MyEnumInvalidStrFmt {
Variant,
OtherVariant,
}
impl Display for MyEnumInvalidStrFmt {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_intern_arg.rs | use pyo3::Python;
fn main() {
let _foo = if true { "foo" } else { "bar" };
Python::with_gil(|py| py.import(pyo3::intern!(py, _foo)).unwrap());
}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pymodule_trait.rs | use pyo3::prelude::*;
#[pymodule]
mod module {
#[pymodule_export]
trait Foo {}
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/traverse.rs | use pyo3::prelude::*;
use pyo3::PyTraverseError;
use pyo3::PyVisit;
#[pyclass]
struct TraverseTriesToTakePyRef {}
#[pymethods]
impl TraverseTriesToTakePyRef {
fn __traverse__(_slf: PyRef<Self>, _visit: PyVisit) -> Result<(), PyTraverseError> {
Ok(())
}
}
#[pyclass]
struct TraverseTriesToTakePyRefMut {}
#[pymethods]
impl TraverseTriesToTakePyRefMut {
fn __traverse__(_slf: PyRefMut<Self>, _visit: PyVisit) -> Result<(), PyTraverseError> {
Ok(())
}
}
#[pyclass]
struct TraverseTriesToTakeBound {}
#[pymethods]
impl TraverseTriesToTakeBound {
fn __traverse__(_slf: Bound<'_, Self>, _visit: PyVisit) -> Result<(), PyTraverseError> {
Ok(())
}
}
#[pyclass]
struct TraverseTriesToTakeMutSelf {}
#[pymethods]
impl TraverseTriesToTakeMutSelf {
fn __traverse__(&mut self, _visit: PyVisit) -> Result<(), PyTraverseError> {
Ok(())
}
}
#[pyclass]
struct TraverseTriesToTakeSelf {}
#[pymethods]
impl TraverseTriesToTakeSelf {
fn __traverse__(&self, _visit: PyVisit) -> Result<(), PyTraverseError> {
Ok(())
}
}
#[pyclass]
struct Class;
#[pymethods]
impl Class {
fn __traverse__(&self, _py: Python<'_>, _visit: PyVisit<'_>) -> Result<(), PyTraverseError> {
Ok(())
}
fn __clear__(&mut self) {}
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/pyclass_send.stderr | error[E0277]: `*mut c_void` cannot be shared between threads safely
--> tests/ui/pyclass_send.rs:5:8
|
5 | struct NotSyncNotSend(*mut c_void);
| ^^^^^^^^^^^^^^ `*mut c_void` cannot be shared between threads safely
|
= help: within `NotSyncNotSend`, the trait `Sync` is not implemented for `*mut c_void`, which is required by `NotSyncNotSend: Sync`
note: required because it appears within the type `NotSyncNotSend`
--> tests/ui/pyclass_send.rs:5:8
|
5 | struct NotSyncNotSend(*mut c_void);
| ^^^^^^^^^^^^^^
note: required by a bound in `pyo3::impl_::pyclass::assertions::assert_pyclass_sync`
--> src/impl_/pyclass/assertions.rs
|
| pub const fn assert_pyclass_sync<T>()
| ------------------- required by a bound in this function
| where
| T: PyClassSync + Sync,
| ^^^^ required by this bound in `assert_pyclass_sync`
error[E0277]: `*mut c_void` cannot be sent between threads safely
--> tests/ui/pyclass_send.rs:4:1
|
4 | #[pyclass]
| ^^^^^^^^^^ `*mut c_void` cannot be sent between threads safely
|
= help: within `NotSyncNotSend`, the trait `Send` is not implemented for `*mut c_void`, which is required by `SendablePyClass<NotSyncNotSend>: pyo3::impl_::pyclass::PyClassThreadChecker<NotSyncNotSend>`
= help: the trait `pyo3::impl_::pyclass::PyClassThreadChecker<T>` is implemented for `SendablePyClass<T>`
note: required because it appears within the type `NotSyncNotSend`
--> tests/ui/pyclass_send.rs:5:8
|
5 | struct NotSyncNotSend(*mut c_void);
| ^^^^^^^^^^^^^^
= note: required for `SendablePyClass<NotSyncNotSend>` to implement `pyo3::impl_::pyclass::PyClassThreadChecker<NotSyncNotSend>`
note: required by a bound in `PyClassImpl::ThreadChecker`
--> src/impl_/pyclass.rs
|
| type ThreadChecker: PyClassThreadChecker<Self>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `PyClassImpl::ThreadChecker`
= note: this error originates in the attribute macro `pyclass` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: `*mut c_void` cannot be shared between threads safely
--> tests/ui/pyclass_send.rs:8:8
|
8 | struct SendNotSync(*mut c_void);
| ^^^^^^^^^^^ `*mut c_void` cannot be shared between threads safely
|
= help: within `SendNotSync`, the trait `Sync` is not implemented for `*mut c_void`, which is required by `SendNotSync: Sync`
note: required because it appears within the type `SendNotSync`
--> tests/ui/pyclass_send.rs:8:8
|
8 | struct SendNotSync(*mut c_void);
| ^^^^^^^^^^^
note: required by a bound in `pyo3::impl_::pyclass::assertions::assert_pyclass_sync`
--> src/impl_/pyclass/assertions.rs
|
| pub const fn assert_pyclass_sync<T>()
| ------------------- required by a bound in this function
| where
| T: PyClassSync + Sync,
| ^^^^ required by this bound in `assert_pyclass_sync`
error[E0277]: `*mut c_void` cannot be sent between threads safely
--> tests/ui/pyclass_send.rs:11:1
|
11 | #[pyclass]
| ^^^^^^^^^^ `*mut c_void` cannot be sent between threads safely
|
= help: within `SyncNotSend`, the trait `Send` is not implemented for `*mut c_void`, which is required by `SendablePyClass<SyncNotSend>: pyo3::impl_::pyclass::PyClassThreadChecker<SyncNotSend>`
= help: the trait `pyo3::impl_::pyclass::PyClassThreadChecker<T>` is implemented for `SendablePyClass<T>`
note: required because it appears within the type `SyncNotSend`
--> tests/ui/pyclass_send.rs:12:8
|
12 | struct SyncNotSend(*mut c_void);
| ^^^^^^^^^^^
= note: required for `SendablePyClass<SyncNotSend>` to implement `pyo3::impl_::pyclass::PyClassThreadChecker<SyncNotSend>`
note: required by a bound in `PyClassImpl::ThreadChecker`
--> src/impl_/pyclass.rs
|
| type ThreadChecker: PyClassThreadChecker<Self>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `PyClassImpl::ThreadChecker`
= note: this error originates in the attribute macro `pyclass` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: `*mut c_void` cannot be sent between threads safely
--> tests/ui/pyclass_send.rs:4:1
|
4 | #[pyclass]
| ^^^^^^^^^^ `*mut c_void` cannot be sent between threads safely
|
= help: within `NotSyncNotSend`, the trait `Send` is not implemented for `*mut c_void`, which is required by `NotSyncNotSend: Send`
note: required because it appears within the type `NotSyncNotSend`
--> tests/ui/pyclass_send.rs:5:8
|
5 | struct NotSyncNotSend(*mut c_void);
| ^^^^^^^^^^^^^^
note: required by a bound in `SendablePyClass`
--> src/impl_/pyclass.rs
|
| pub struct SendablePyClass<T: Send>(PhantomData<T>);
| ^^^^ required by this bound in `SendablePyClass`
= note: this error originates in the attribute macro `pyclass` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: `*mut c_void` cannot be sent between threads safely
--> tests/ui/pyclass_send.rs:11:1
|
11 | #[pyclass]
| ^^^^^^^^^^ `*mut c_void` cannot be sent between threads safely
|
= help: within `SyncNotSend`, the trait `Send` is not implemented for `*mut c_void`, which is required by `SyncNotSend: Send`
note: required because it appears within the type `SyncNotSend`
--> tests/ui/pyclass_send.rs:12:8
|
12 | struct SyncNotSend(*mut c_void);
| ^^^^^^^^^^^
note: required by a bound in `SendablePyClass`
--> src/impl_/pyclass.rs
|
| pub struct SendablePyClass<T: Send>(PhantomData<T>);
| ^^^^ required by this bound in `SendablePyClass`
= note: this error originates in the attribute macro `pyclass` (in Nightly builds, run with -Z macro-backtrace for more info)
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pymodule_trait.stderr | error: `#[pymodule_export]` may only be used on `use` statements
--> tests/ui/invalid_pymodule_trait.rs:5:5
|
5 | #[pymodule_export]
| ^
error: cannot find attribute `pymodule_export` in this scope
--> tests/ui/invalid_pymodule_trait.rs:5:7
|
5 | #[pymodule_export]
| ^^^^^^^^^^^^^^^
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pymethods_buffer.rs | use pyo3::prelude::*;
#[pyclass]
struct MyClass {}
#[pymethods]
impl MyClass {
#[pyo3(name = "__getbuffer__")]
fn getbuffer_must_be_unsafe(&self, _view: *mut pyo3::ffi::Py_buffer, _flags: std::os::raw::c_int) {}
}
#[pymethods]
impl MyClass {
#[pyo3(name = "__releasebuffer__")]
fn releasebuffer_must_be_unsafe(&self, _view: *mut pyo3::ffi::Py_buffer) {}
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/not_send.rs | use pyo3::prelude::*;
fn test_not_send_allow_threads(py: Python<'_>) {
py.allow_threads(|| { drop(py); });
}
fn main() {
Python::with_gil(|py| {
test_not_send_allow_threads(py);
})
}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_cancel_handle.stderr | error: `cancel_handle` may only be specified once per argument
--> tests/ui/invalid_cancel_handle.rs:4:55
|
4 | async fn cancel_handle_repeated(#[pyo3(cancel_handle, cancel_handle)] _param: String) {}
| ^^^^^^^^^^^^^
error: `cancel_handle` may only be specified once
--> tests/ui/invalid_cancel_handle.rs:9:28
|
9 | #[pyo3(cancel_handle)] _param2: String,
| ^^^^^^^
error: `cancel_handle` attribute can only be used with `async fn`
--> tests/ui/invalid_cancel_handle.rs:14:53
|
14 | fn cancel_handle_synchronous(#[pyo3(cancel_handle)] _param: String) {}
| ^^^^^^
error: `from_py_with` and `cancel_handle` cannot be specified together
--> tests/ui/invalid_cancel_handle.rs:24:12
|
24 | #[pyo3(cancel_handle, from_py_with = "cancel_handle")] _param: pyo3::coroutine::CancelHandle,
| ^^^^^^^^^^^^^
error[E0308]: mismatched types
--> tests/ui/invalid_cancel_handle.rs:16:1
|
16 | #[pyfunction]
| ^^^^^^^^^^^^^
| |
| expected `String`, found `CancelHandle`
| arguments to this function are incorrect
|
note: function defined here
--> tests/ui/invalid_cancel_handle.rs:17:10
|
17 | async fn cancel_handle_wrong_type(#[pyo3(cancel_handle)] _param: String) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^ --------------
= note: this error originates in the attribute macro `pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `CancelHandle: PyFunctionArgument<'_, '_>` is not satisfied
--> tests/ui/invalid_cancel_handle.rs:20:50
|
20 | async fn missing_cancel_handle_attribute(_param: pyo3::coroutine::CancelHandle) {}
| ^^^^ the trait `PyClass` is not implemented for `CancelHandle`, which is required by `CancelHandle: PyFunctionArgument<'_, '_>`
|
= help: the trait `PyClass` is implemented for `pyo3::coroutine::Coroutine`
= note: required for `CancelHandle` to implement `FromPyObject<'_>`
= note: required for `CancelHandle` to implement `FromPyObjectBound<'_, '_>`
= note: required for `CancelHandle` to implement `PyFunctionArgument<'_, '_>`
note: required by a bound in `extract_argument`
--> src/impl_/extract_argument.rs
|
| pub fn extract_argument<'a, 'py, T>(
| ---------------- required by a bound in this function
...
| T: PyFunctionArgument<'a, 'py>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `extract_argument`
error[E0277]: the trait bound `CancelHandle: PyFunctionArgument<'_, '_>` is not satisfied
--> tests/ui/invalid_cancel_handle.rs:20:50
|
20 | async fn missing_cancel_handle_attribute(_param: pyo3::coroutine::CancelHandle) {}
| ^^^^ the trait `Clone` is not implemented for `CancelHandle`, which is required by `CancelHandle: PyFunctionArgument<'_, '_>`
|
= help: the following other types implement trait `PyFunctionArgument<'a, 'py>`:
&'a mut pyo3::coroutine::Coroutine
&'a pyo3::Bound<'py, T>
&'a pyo3::coroutine::Coroutine
Option<&'a pyo3::Bound<'py, T>>
= note: required for `CancelHandle` to implement `FromPyObject<'_>`
= note: required for `CancelHandle` to implement `FromPyObjectBound<'_, '_>`
= note: required for `CancelHandle` to implement `PyFunctionArgument<'_, '_>`
note: required by a bound in `extract_argument`
--> src/impl_/extract_argument.rs
|
| pub fn extract_argument<'a, 'py, T>(
| ---------------- required by a bound in this function
...
| T: PyFunctionArgument<'a, 'py>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `extract_argument`
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_frozen_pyclass_borrow.rs | use pyo3::prelude::*;
#[pyclass(frozen)]
pub struct Foo {
#[pyo3(get)]
field: u32,
}
#[pymethods]
impl Foo {
fn mut_method(&mut self) {}
}
fn borrow_mut_fails(foo: Py<Foo>, py: Python) {
let borrow = foo.bind(py).borrow_mut();
}
#[pyclass(subclass)]
struct MutableBase;
#[pyclass(frozen, extends = MutableBase)]
struct ImmutableChild;
fn borrow_mut_of_child_fails(child: Py<ImmutableChild>, py: Python) {
let borrow = child.bind(py).borrow_mut();
}
fn py_get_of_mutable_class_fails(class: Py<MutableBase>) {
class.get();
}
fn pyclass_get_of_mutable_class_fails(class: &Bound<'_, MutableBase>) {
class.get();
}
#[pyclass(frozen)]
pub struct SetOnFrozenClass {
#[pyo3(set)]
field: u32,
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/not_send2.rs | use pyo3::prelude::*;
use pyo3::types::PyString;
fn main() {
Python::with_gil(|py| {
let string = PyString::new(py, "foo");
py.allow_threads(|| {
println!("{:?}", string);
});
});
}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pymethod_names.rs | use pyo3::prelude::*;
#[pyclass]
struct TestClass {
num: u32,
}
#[pymethods]
impl TestClass {
#[pyo3(name = "num")]
#[getter(number)]
fn get_num(&self) -> u32 { self.num }
}
#[pymethods]
impl TestClass {
#[pyo3(name = "foo")]
#[pyo3(name = "bar")]
fn qux(&self) -> u32 { self.num }
}
#[pymethods]
impl TestClass {
#[pyo3(name = "makenew")]
#[new]
fn new(&self) -> Self { Self { num: 0 } }
}
#[pymethods]
impl TestClass {
#[getter(1)]
fn get_one(&self) -> Self { Self { num: 0 } }
}
#[pymethods]
impl TestClass {
#[getter = 1]
fn get_two(&self) -> Self { Self { num: 0 } }
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/not_send.stderr | error[E0277]: `*mut pyo3::Python<'static>` cannot be shared between threads safely
--> tests/ui/not_send.rs:4:22
|
4 | py.allow_threads(|| { drop(py); });
| ------------- ^^^^^^^^^^^^^^^^ `*mut pyo3::Python<'static>` cannot be shared between threads safely
| |
| required by a bound introduced by this call
|
= help: within `pyo3::Python<'_>`, the trait `Sync` is not implemented for `*mut pyo3::Python<'static>`, which is required by `{closure@$DIR/tests/ui/not_send.rs:4:22: 4:24}: Ungil`
note: required because it appears within the type `PhantomData<*mut pyo3::Python<'static>>`
--> $RUST/core/src/marker.rs
|
| pub struct PhantomData<T: ?Sized>;
| ^^^^^^^^^^^
note: required because it appears within the type `impl_::not_send::NotSend`
--> src/impl_/not_send.rs
|
| pub(crate) struct NotSend(PhantomData<*mut Python<'static>>);
| ^^^^^^^
= note: required because it appears within the type `(&pyo3::gil::GILGuard, impl_::not_send::NotSend)`
note: required because it appears within the type `PhantomData<(&pyo3::gil::GILGuard, impl_::not_send::NotSend)>`
--> $RUST/core/src/marker.rs
|
| pub struct PhantomData<T: ?Sized>;
| ^^^^^^^^^^^
note: required because it appears within the type `pyo3::Python<'_>`
--> src/marker.rs
|
| pub struct Python<'py>(PhantomData<(&'py GILGuard, NotSend)>);
| ^^^^^^
= note: required for `&pyo3::Python<'_>` to implement `Send`
note: required because it's used within this closure
--> tests/ui/not_send.rs:4:22
|
4 | py.allow_threads(|| { drop(py); });
| ^^
= note: required for `{closure@$DIR/tests/ui/not_send.rs:4:22: 4:24}` to implement `Ungil`
note: required by a bound in `pyo3::Python::<'py>::allow_threads`
--> src/marker.rs
|
| pub fn allow_threads<T, F>(self, f: F) -> T
| ------------- required by a bound in this associated function
| where
| F: Ungil + FnOnce() -> T,
| ^^^^^ required by this bound in `Python::<'py>::allow_threads`
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/wrong_aspyref_lifetimes.rs | use pyo3::{types::PyDict, Bound, Py, Python};
fn main() {
let dict: Py<PyDict> = Python::with_gil(|py| PyDict::new(py).unbind());
// Should not be able to get access to Py contents outside of with_gil.
let dict: &Bound<'_, PyDict> = Python::with_gil(|py| dict.bind(py));
let _py: Python = dict.py(); // Obtain a Python<'p> without GIL.
}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_property_args.rs | use pyo3::prelude::*;
#[pyclass]
struct ClassWithGetter {}
#[pymethods]
impl ClassWithGetter {
#[getter]
fn getter_with_arg(&self, _py: Python<'_>, _index: u32) {}
}
#[pyclass]
struct ClassWithSetter {}
#[pymethods]
impl ClassWithSetter {
#[setter]
fn setter_with_no_arg(&mut self, _py: Python<'_>) {}
}
#[pymethods]
impl ClassWithSetter {
#[setter]
fn setter_with_too_many_args(&mut self, _py: Python<'_>, _foo: u32, _bar: u32) {}
}
#[pyclass]
struct TupleGetterSetterNoName(#[pyo3(get, set)] i32);
#[pyclass]
struct MultipleGet(#[pyo3(get, get)] i32);
#[pyclass]
struct MultipleSet(#[pyo3(set, set)] i32);
#[pyclass]
struct MultipleName(#[pyo3(name = "foo", name = "bar")] i32);
#[pyclass]
struct NameWithoutGetSet(#[pyo3(name = "value")] i32);
#[pyclass]
struct InvalidGetterType {
#[pyo3(get)]
value: ::std::marker::PhantomData<i32>,
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_proto_pymethods.rs | //! Check that some magic methods edge cases error as expected.
//!
//! For convenience use #[pyo3(name = "__some_dunder__")] to create the methods,
//! so that the function names can describe the edge case to be rejected.
use pyo3::prelude::*;
use pyo3::pyclass::CompareOp;
#[pyclass]
struct MyClass {}
//
// Argument counts
//
#[pymethods]
impl MyClass {
#[pyo3(name = "__truediv__")]
fn truediv_expects_one_argument(&self) -> PyResult<()> {
Ok(())
}
}
#[pymethods]
impl MyClass {
#[pyo3(name = "__truediv__")]
fn truediv_expects_one_argument_py(&self, _py: Python<'_>) -> PyResult<()> {
Ok(())
}
}
//
// Forbidden attributes
//
#[pymethods]
impl MyClass {
#[pyo3(name = "__bool__", signature = ())]
fn signature_is_forbidden(&self) -> bool {
true
}
}
#[pymethods]
impl MyClass {
#[pyo3(name = "__bool__", text_signature = "")]
fn text_signature_is_forbidden(&self) -> bool {
true
}
}
#[pyclass]
struct EqAndRichcmp;
#[pymethods]
impl EqAndRichcmp {
fn __eq__(&self, _other: &Self) -> bool {
true
}
fn __richcmp__(&self, _other: &Self, _op: CompareOp) -> bool {
true
}
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pyfunctions.stderr | error: Python functions cannot have generic type parameters
--> tests/ui/invalid_pyfunctions.rs:5:21
|
5 | fn generic_function<T>(_value: T) {}
| ^
error: Python functions cannot have `impl Trait` arguments
--> tests/ui/invalid_pyfunctions.rs:8:37
|
8 | fn impl_trait_function(_impl_trait: impl AsRef<PyAny>) {}
| ^^^^
error: wildcard argument names are not supported
--> tests/ui/invalid_pyfunctions.rs:11:22
|
11 | fn wildcard_argument(_: i32) {}
| ^
error: destructuring in arguments is not supported
--> tests/ui/invalid_pyfunctions.rs:14:26
|
14 | fn destructured_argument((_a, _b): (i32, i32)) {}
| ^^^^^^^^
error: required arguments after an `Option<_>` argument are ambiguous
= help: add a `#[pyo3(signature)]` annotation on this function to unambiguously specify the default values for all optional parameters
--> tests/ui/invalid_pyfunctions.rs:17:63
|
17 | fn function_with_required_after_option(_opt: Option<i32>, _x: i32) {}
| ^^^
error: args cannot be optional
--> tests/ui/invalid_pyfunctions.rs:21:32
|
21 | fn function_with_optional_args(args: Option<Bound<'_, PyTuple>>) {
| ^^^^
error: kwargs must be Option<_>
--> tests/ui/invalid_pyfunctions.rs:27:34
|
27 | fn function_with_required_kwargs(kwargs: Bound<'_, PyDict>) {
| ^^^^^^
error: expected `&PyModule` or `Py<PyModule>` as first argument with `pass_module`
--> tests/ui/invalid_pyfunctions.rs:32:37
|
32 | fn pass_module_but_no_arguments<'py>() {}
| ^^
error[E0277]: the trait bound `&str: From<BoundRef<'_, '_, pyo3::types::PyModule>>` is not satisfied
--> tests/ui/invalid_pyfunctions.rs:36:14
|
36 | _string: &str,
| ^ the trait `From<BoundRef<'_, '_, pyo3::types::PyModule>>` is not implemented for `&str`, which is required by `BoundRef<'_, '_, pyo3::types::PyModule>: Into<_>`
|
= help: the following other types implement trait `From<T>`:
`String` implements `From<&String>`
`String` implements `From<&mut str>`
`String` implements `From<&str>`
`String` implements `From<Box<str>>`
`String` implements `From<Cow<'a, str>>`
`String` implements `From<char>`
= note: required for `BoundRef<'_, '_, pyo3::types::PyModule>` to implement `Into<&str>`
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/not_send2.stderr | error[E0277]: `*mut pyo3::Python<'static>` cannot be shared between threads safely
--> tests/ui/not_send2.rs:8:26
|
8 | py.allow_threads(|| {
| ____________-------------_^
| | |
| | required by a bound introduced by this call
9 | | println!("{:?}", string);
10 | | });
| |_________^ `*mut pyo3::Python<'static>` cannot be shared between threads safely
|
= help: within `pyo3::Bound<'_, PyString>`, the trait `Sync` is not implemented for `*mut pyo3::Python<'static>`, which is required by `{closure@$DIR/tests/ui/not_send2.rs:8:26: 8:28}: Ungil`
note: required because it appears within the type `PhantomData<*mut pyo3::Python<'static>>`
--> $RUST/core/src/marker.rs
|
| pub struct PhantomData<T: ?Sized>;
| ^^^^^^^^^^^
note: required because it appears within the type `impl_::not_send::NotSend`
--> src/impl_/not_send.rs
|
| pub(crate) struct NotSend(PhantomData<*mut Python<'static>>);
| ^^^^^^^
= note: required because it appears within the type `(&pyo3::gil::GILGuard, impl_::not_send::NotSend)`
note: required because it appears within the type `PhantomData<(&pyo3::gil::GILGuard, impl_::not_send::NotSend)>`
--> $RUST/core/src/marker.rs
|
| pub struct PhantomData<T: ?Sized>;
| ^^^^^^^^^^^
note: required because it appears within the type `pyo3::Python<'_>`
--> src/marker.rs
|
| pub struct Python<'py>(PhantomData<(&'py GILGuard, NotSend)>);
| ^^^^^^
note: required because it appears within the type `pyo3::Bound<'_, PyString>`
--> src/instance.rs
|
| pub struct Bound<'py, T>(Python<'py>, ManuallyDrop<Py<T>>);
| ^^^^^
= note: required for `&pyo3::Bound<'_, PyString>` to implement `Send`
note: required because it's used within this closure
--> tests/ui/not_send2.rs:8:26
|
8 | py.allow_threads(|| {
| ^^
= note: required for `{closure@$DIR/tests/ui/not_send2.rs:8:26: 8:28}` to implement `Ungil`
note: required by a bound in `pyo3::Python::<'py>::allow_threads`
--> src/marker.rs
|
| pub fn allow_threads<T, F>(self, f: F) -> T
| ------------- required by a bound in this associated function
| where
| F: Ungil + FnOnce() -> T,
| ^^^^^ required by this bound in `Python::<'py>::allow_threads`
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_property_args.stderr | error: getter function can only have one argument (of type pyo3::Python)
--> tests/ui/invalid_property_args.rs:9:56
|
9 | fn getter_with_arg(&self, _py: Python<'_>, _index: u32) {}
| ^^^
error: setter function expected to have one argument
--> tests/ui/invalid_property_args.rs:18:8
|
18 | fn setter_with_no_arg(&mut self, _py: Python<'_>) {}
| ^^^^^^^^^^^^^^^^^^
error: setter function can have at most two arguments ([pyo3::Python,] and value)
--> tests/ui/invalid_property_args.rs:24:79
|
24 | fn setter_with_too_many_args(&mut self, _py: Python<'_>, _foo: u32, _bar: u32) {}
| ^^^
error: `get` and `set` with tuple struct fields require `name`
--> tests/ui/invalid_property_args.rs:28:50
|
28 | struct TupleGetterSetterNoName(#[pyo3(get, set)] i32);
| ^^^
error: `get` may only be specified once
--> tests/ui/invalid_property_args.rs:31:32
|
31 | struct MultipleGet(#[pyo3(get, get)] i32);
| ^^^
error: `set` may only be specified once
--> tests/ui/invalid_property_args.rs:34:32
|
34 | struct MultipleSet(#[pyo3(set, set)] i32);
| ^^^
error: `name` may only be specified once
--> tests/ui/invalid_property_args.rs:37:42
|
37 | struct MultipleName(#[pyo3(name = "foo", name = "bar")] i32);
| ^^^^
error: `name` is useless without `get` or `set`
--> tests/ui/invalid_property_args.rs:40:33
|
40 | struct NameWithoutGetSet(#[pyo3(name = "value")] i32);
| ^^^^^^^^^^^^^^
error[E0277]: `PhantomData<i32>` cannot be converted to a Python object
--> tests/ui/invalid_property_args.rs:45:12
|
45 | value: ::std::marker::PhantomData<i32>,
| ^ required by `#[pyo3(get)]` to create a readable property from a field of type `PhantomData<i32>`
|
= help: the trait `IntoPyObject<'_>` is not implemented for `PhantomData<i32>`, which is required by `for<'py> PhantomData<i32>: PyO3GetField<'py>`
= note: implement `IntoPyObject` for `&PhantomData<i32>` or `IntoPyObject + Clone` for `PhantomData<i32>` to define the conversion
= help: the following other types implement trait `IntoPyObject<'py>`:
&&'a T
&&OsStr
&&Path
&&str
&'a (T0, T1)
&'a (T0, T1, T2)
&'a (T0, T1, T2, T3)
&'a (T0, T1, T2, T3, T4)
and $N others
= note: required for `PhantomData<i32>` to implement `for<'py> PyO3GetField<'py>`
note: required by a bound in `PyClassGetterGenerator::<ClassT, FieldT, Offset, false, false, false, false, false>::generate`
--> src/impl_/pyclass.rs
|
| pub const fn generate(&self, _name: &'static CStr, _doc: &'static CStr) -> PyMethodDefType
| -------- required by a bound in this associated function
...
| for<'py> FieldT: PyO3GetField<'py>,
| ^^^^^^^^^^^^^^^^^ required by this bound in `PyClassGetterGenerator::<ClassT, FieldT, Offset, false, false, false, false, false>::generate`
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pyfunction_definition.stderr | error: functions inside #[pymethods] do not need to be annotated with #[pyfunction]
--> tests/ui/invalid_pyfunction_definition.rs:11:9
|
11 | fn bug() {}
| ^^
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/abi3_inheritance.rs | use pyo3::exceptions::PyException;
use pyo3::prelude::*;
#[pyclass(extends=PyException)]
#[derive(Clone)]
struct MyException {
code: u32,
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/duplicate_pymodule_submodule.stderr | error: `submodule` may only be specified once (it is implicitly always specified for nested modules)
--> tests/ui/duplicate_pymodule_submodule.rs:4:2
|
4 | mod submod {}
| ^^^
error[E0425]: cannot find value `_PYO3_DEF` in module `submod`
--> tests/ui/duplicate_pymodule_submodule.rs:1:1
|
1 | #[pyo3::pymodule]
| ^^^^^^^^^^^^^^^^^ not found in `submod`
|
= note: this error originates in the attribute macro `pyo3::pymodule` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this static
|
3 + use crate::mymodule::_PYO3_DEF;
|
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pyfunction_signatures.stderr | error: missing signature entry for argument `_x`
--> tests/ui/invalid_pyfunction_signatures.rs:5:8
|
5 | #[pyo3(signature = ())]
| ^^^^^^^^^
error: signature entry does not have a corresponding function argument
--> tests/ui/invalid_pyfunction_signatures.rs:9:21
|
9 | #[pyo3(signature = (x))]
| ^
error: expected argument from function definition `y` but got argument `x`
--> tests/ui/invalid_pyfunction_signatures.rs:13:21
|
13 | #[pyo3(signature = (x))]
| ^
error: expected one of: `name`, `pass_module`, `signature`, `text_signature`, `crate`
--> tests/ui/invalid_pyfunction_signatures.rs:18:14
|
18 | #[pyfunction(x)]
| ^
error: `*args` not allowed after `*`
--> tests/ui/invalid_pyfunction_signatures.rs:25:24
|
25 | #[pyo3(signature = (*, *args))]
| ^
error: `*` not allowed after `*`
--> tests/ui/invalid_pyfunction_signatures.rs:31:24
|
31 | #[pyo3(signature = (*, *))]
| ^
error: `*args` not allowed after `**kwargs`
--> tests/ui/invalid_pyfunction_signatures.rs:35:31
|
35 | #[pyo3(signature = (**kwargs, *args))]
| ^
error: `**kwargs_b` not allowed after `**kwargs_a`
--> tests/ui/invalid_pyfunction_signatures.rs:42:33
|
42 | #[pyo3(signature = (**kwargs_a, **kwargs_b))]
| ^
error: arguments of type `Python` must not be part of the signature
--> tests/ui/invalid_pyfunction_signatures.rs:48:27
|
48 | #[pyfunction(signature = (py))]
| ^^
error: cannot find attribute `args` in this scope
--> tests/ui/invalid_pyfunction_signatures.rs:58:7
|
58 | #[args(x)]
| ^^^^
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pyfunction_signatures.rs | use pyo3::prelude::*;
use pyo3::types::{PyDict, PyTuple};
#[pyfunction]
#[pyo3(signature = ())]
fn function_with_one_argument_empty_signature(_x: i32) {}
#[pyfunction]
#[pyo3(signature = (x))]
fn function_with_one_entry_signature_no_args() {}
#[pyfunction]
#[pyo3(signature = (x))]
fn function_with_incorrect_argument_names(y: i32) {
let _ = y;
}
#[pyfunction(x)]
#[pyo3(signature = (x))]
fn function_with_both_args_and_signature(x: i32) {
let _ = x;
}
#[pyfunction]
#[pyo3(signature = (*, *args))]
fn function_with_args_after_args_sep(args: &PyTuple) {
let _ = args;
}
#[pyfunction]
#[pyo3(signature = (*, *))]
fn function_with_args_sep_after_args_sep() {}
#[pyfunction]
#[pyo3(signature = (**kwargs, *args))]
fn function_with_args_after_kwargs(kwargs: Option<&PyDict>, args: &PyTuple) {
let _ = args;
let _ = kwargs;
}
#[pyfunction]
#[pyo3(signature = (**kwargs_a, **kwargs_b))]
fn function_with_kwargs_after_kwargs(kwargs_a: Option<&PyDict>, kwargs_b: Option<&PyDict>) {
let _ = kwargs_a;
let _ = kwargs_b;
}
#[pyfunction(signature = (py))]
fn signature_contains_py(py: Python<'_>) {
let _ = py;
}
#[pyclass]
struct MyClass;
#[pymethods]
impl MyClass {
#[args(x)]
#[pyo3(signature = (x))]
fn method_with_both_args_and_signature(&self, x: i32) {
let _ = x;
}
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/deprecations.stderr | error: use of deprecated constant `__pyfunction_pyfunction_option_2::SIGNATURE`: this function has implicit defaults for the trailing `Option<T>` arguments
= note: these implicit defaults are being phased out
= help: add `#[pyo3(signature = (_i, _any=None))]` to this function to silence this warning and keep the current behavior
--> tests/ui/deprecations.rs:15:4
|
15 | fn pyfunction_option_2(_i: u32, _any: Option<i32>) {}
| ^^^^^^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> tests/ui/deprecations.rs:1:9
|
1 | #![deny(deprecated)]
| ^^^^^^^^^^
error: use of deprecated constant `__pyfunction_pyfunction_option_3::SIGNATURE`: this function has implicit defaults for the trailing `Option<T>` arguments
= note: these implicit defaults are being phased out
= help: add `#[pyo3(signature = (_i, _any=None, _foo=None))]` to this function to silence this warning and keep the current behavior
--> tests/ui/deprecations.rs:18:4
|
18 | fn pyfunction_option_3(_i: u32, _any: Option<i32>, _foo: Option<String>) {}
| ^^^^^^^^^^^^^^^^^^^
error: use of deprecated constant `__pyfunction_pyfunction_option_4::SIGNATURE`: this function has implicit defaults for the trailing `Option<T>` arguments
= note: these implicit defaults are being phased out
= help: add `#[pyo3(signature = (_i, _any=None, _foo=None))]` to this function to silence this warning and keep the current behavior
--> tests/ui/deprecations.rs:21:4
|
21 | fn pyfunction_option_4(
| ^^^^^^^^^^^^^^^^^^^
error: use of deprecated method `pyo3::impl_::pyclass::Deprecation::autogenerated_equality`: Implicit equality for simple enums is deprecated. Use `#[pyclass(eq, eq_int)]` to keep the current behavior.
--> tests/ui/deprecations.rs:28:1
|
28 | #[pyclass]
| ^^^^^^^^^^
|
= note: this error originates in the attribute macro `pyclass` (in Nightly builds, run with -Z macro-backtrace for more info)
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/pymodule_missing_docs.rs | #![deny(missing_docs)]
//! Some crate docs
use pyo3::prelude::*;
/// Some module documentation
#[pymodule]
pub fn python_module(_m: &Bound<'_, PyModule>) -> PyResult<()> {
Ok(())
}
/// Some module documentation
#[pymodule]
pub mod declarative_python_module {}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pymethod_receiver.rs | use pyo3::prelude::*;
#[pyclass]
struct MyClass {}
#[pymethods]
impl MyClass {
fn method_with_invalid_self_type(_slf: i32, _py: Python<'_>, _index: u32) {}
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pymodule_glob.stderr | error: #[pymodule] cannot import glob statements
--> tests/ui/invalid_pymodule_glob.rs:13:16
|
13 | use super::*;
| ^
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pymodule_in_root.stderr | error[E0658]: non-inline modules in proc macro input are unstable
--> tests/ui/invalid_pymodule_in_root.rs:5:1
|
5 | mod invalid_pymodule_in_root_module;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #54727 <https://github.com/rust-lang/rust/issues/54727> for more information
error: `#[pymodule]` can only be used on inline modules
--> tests/ui/invalid_pymodule_in_root.rs:5:1
|
5 | mod invalid_pymodule_in_root_module;
| ^^^
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pymethods_duplicates.stderr | error[E0119]: conflicting implementations of trait `pyo3::impl_::pyclass::PyClassNewTextSignature<TwoNew>` for type `pyo3::impl_::pyclass::PyClassImplCollector<TwoNew>`
--> tests/ui/invalid_pymethods_duplicates.rs:9:1
|
9 | #[pymethods]
| ^^^^^^^^^^^^
| |
| first implementation here
| conflicting implementation for `pyo3::impl_::pyclass::PyClassImplCollector<TwoNew>`
|
= note: this error originates in the attribute macro `pymethods` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0592]: duplicate definitions with name `__pymethod___new____`
--> tests/ui/invalid_pymethods_duplicates.rs:9:1
|
9 | #[pymethods]
| ^^^^^^^^^^^^
| |
| duplicate definitions for `__pymethod___new____`
| other definition for `__pymethod___new____`
|
= note: this error originates in the attribute macro `pymethods` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0592]: duplicate definitions with name `__pymethod_func__`
--> tests/ui/invalid_pymethods_duplicates.rs:25:1
|
25 | #[pymethods]
| ^^^^^^^^^^^^
| |
| duplicate definitions for `__pymethod_func__`
| other definition for `__pymethod_func__`
|
= note: this error originates in the attribute macro `pymethods` (in Nightly builds, run with -Z macro-backtrace for more info)
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/abi3_inheritance.stderr | error[E0277]: pyclass `PyException` cannot be subclassed
--> tests/ui/abi3_inheritance.rs:4:19
|
4 | #[pyclass(extends=PyException)]
| ^^^^^^^^^^^ required for `#[pyclass(extends=PyException)]`
|
= help: the trait `PyClassBaseType` is not implemented for `PyException`
= note: `PyException` must have `#[pyclass(subclass)]` to be eligible for subclassing
= note: with the `abi3` feature enabled, PyO3 does not support subclassing native types
= help: the trait `PyClassBaseType` is implemented for `PyAny`
note: required by a bound in `PyClassImpl::BaseType`
--> src/impl_/pyclass.rs
|
| type BaseType: PyTypeInfo + PyClassBaseType;
| ^^^^^^^^^^^^^^^ required by this bound in `PyClassImpl::BaseType`
error[E0277]: pyclass `PyException` cannot be subclassed
--> tests/ui/abi3_inheritance.rs:4:1
|
4 | #[pyclass(extends=PyException)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required for `#[pyclass(extends=PyException)]`
|
= help: the trait `PyClassBaseType` is not implemented for `PyException`
= note: `PyException` must have `#[pyclass(subclass)]` to be eligible for subclassing
= note: with the `abi3` feature enabled, PyO3 does not support subclassing native types
= help: the trait `PyClassBaseType` is implemented for `PyAny`
= note: this error originates in the attribute macro `pyclass` (in Nightly builds, run with -Z macro-backtrace for more info)
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/invalid_pyfunction_definition.rs | #[pyo3::pymodule]
mod pyo3_scratch {
use pyo3::prelude::*;
#[pyclass]
struct Foo {}
#[pymethods]
impl Foo {
#[pyfunction]
fn bug() {}
}
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/get_set_all.rs | use pyo3::prelude::*;
#[pyclass(set_all)]
struct Foo;
#[pyclass(set_all)]
struct Foo2{
#[pyo3(set)]
field: u8,
}
#[pyclass(get_all)]
struct Foo3;
#[pyclass(get_all)]
struct Foo4{
#[pyo3(get)]
field: u8,
}
fn main() {}
|
0 | lc_public_repos/langsmith-sdk/vendor/pyo3/tests | lc_public_repos/langsmith-sdk/vendor/pyo3/tests/ui/get_set_all.stderr | error: `set_all` on an unit struct does nothing, because unit structs have no fields
--> tests/ui/get_set_all.rs:3:11
|
3 | #[pyclass(set_all)]
| ^^^^^^^
error: useless `set` - the struct is already annotated with `set_all`
--> tests/ui/get_set_all.rs:8:12
|
8 | #[pyo3(set)]
| ^^^
error: `get_all` on an unit struct does nothing, because unit structs have no fields
--> tests/ui/get_set_all.rs:12:11
|
12 | #[pyclass(get_all)]
| ^^^^^^^
error: useless `get` - the struct is already annotated with `get_all`
--> tests/ui/get_set_all.rs:17:12
|
17 | #[pyo3(get)]
| ^^^
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.