Enable slf: PyRef<'py, Self>
This commit is contained in:
parent
a4c9fb96a3
commit
3d821b7f47
|
@ -5,6 +5,7 @@ use crate::pyfunction::PyFunctionAttr;
|
|||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
use quote::ToTokens;
|
||||
use syn::spanned::Spanned;
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub struct FnArg<'a> {
|
||||
|
@ -390,14 +391,24 @@ fn replace_self(path: &syn::TypePath) -> syn::TypePath {
|
|||
let mut res = path.to_owned();
|
||||
for seg in &mut res.path.segments {
|
||||
if let syn::PathArguments::AngleBracketed(ref mut g) = seg.arguments {
|
||||
for arg in &mut g.args {
|
||||
let mut args = syn::punctuated::Punctuated::new();
|
||||
for arg in &g.args {
|
||||
let mut add_arg = true;
|
||||
if let syn::GenericArgument::Lifetime(_) = arg {
|
||||
add_arg = false;
|
||||
}
|
||||
if let syn::GenericArgument::Type(syn::Type::Path(p)) = arg {
|
||||
if p.path.segments.len() == 1 && p.path.segments[0].ident == "Self" {
|
||||
*arg = infer(p.path.segments[0].ident.span());
|
||||
args.push(infer(p.span()));
|
||||
add_arg = false;
|
||||
}
|
||||
}
|
||||
if add_arg {
|
||||
args.push(arg.clone());
|
||||
}
|
||||
}
|
||||
g.args = args;
|
||||
}
|
||||
}
|
||||
res
|
||||
}
|
||||
|
|
|
@ -20,6 +20,9 @@ impl Reader {
|
|||
fn clone_ref(slf: PyRef<Self>) -> PyRef<Self> {
|
||||
slf
|
||||
}
|
||||
fn clone_ref_with_py<'py>(slf: PyRef<'py, Self>, _py: Python<'py>) -> PyRef<'py, Self> {
|
||||
slf
|
||||
}
|
||||
fn get_iter(slf: PyRef<Self>, keys: Py<PyBytes>) -> PyResult<Iter> {
|
||||
Ok(Iter {
|
||||
reader: slf.into(),
|
||||
|
@ -98,6 +101,7 @@ fn test_clone_ref() {
|
|||
let py = gil.python();
|
||||
let reader: PyObject = reader().into_py(py);
|
||||
py_assert!(py, reader, "reader == reader.clone_ref()");
|
||||
py_assert!(py, reader, "reader == reader.clone_ref_with_py()");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue