8000 object.__getstate__ by youknowone · Pull Request #5342 · RustPython/RustPython · GitHub
[go: up one dir, main page]

Skip to content

object.__getstate__ #5342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
pymethod(raw)
  • Loading branch information
youknowone committed Jun 21, 2024
commit 64cff172a1ddb04bb61977dd7d47967623fa5dd1
15 changes: 13 additions & 2 deletions derive-impl/src/pyclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ where
let item_meta = MethodItemMeta::from_attr(ident.clone(), &item_attr)?;

let py_name = item_meta.method_name()?;
let raw = item_meta.raw()?;
let sig_doc = text_signature(func.sig(), &py_name);

let doc = args.attrs.doc().map(|doc| format_doc(&sig_doc, &doc));
Expand All @@ -760,6 +761,7 @@ where
cfgs: args.cfgs.to_vec(),
ident: ident.to_owned(),
doc,
raw,
attr_name: self.inner.attr_name,
});
Ok(())
Expand Down Expand Up @@ -954,6 +956,7 @@ struct MethodNurseryItem {
py_name: String,
cfgs: Vec<Attribute>,
ident: Ident,
raw: bool,
doc: Option<String>,
attr_name: AttrName,
}
Expand Down Expand Up @@ -1005,9 +1008,14 @@ impl ToTokens for MethodNursery {
// } else {
// quote_spanned! { ident.span() => #py_name }
// };
let method_new = if item.raw {
quote!(new_raw_const)
} else {
quote!(new_const)
};
inner_tokens.extend(quote! [
#(#cfgs)*
rustpython_vm::function::PyMethodDef::new_const(
rustpython_vm::function::PyMethodDef::#method_new(
#py_name,
Self::#ident,
#flags,
Expand Down Expand Up @@ -1203,7 +1211,7 @@ impl ToTokens for MemberNursery {
struct MethodItemMeta(ItemMetaInner);

impl ItemMeta for MethodItemMeta {
const ALLOWED_NAMES: &'static [&'static str] = &["name", "magic"];
const ALLOWED_NAMES: &'static [&'static str] = &["name", "magic", "raw"];

fn from_inner(inner: ItemMetaInner) -> Self {
Self(inner)
Expand All @@ -1214,6 +1222,9 @@ impl ItemMeta for MethodItemMeta {
}

impl MethodItemMeta {
fn raw(&self) -> Result<bool> {
self.inner()._bool("raw")
}
fn method_name(&self) -> Result<String> {
let inner = self.inner();
let name = inner._optional_str("name")?;
Expand Down
5 changes: 5 additions & 0 deletions vm/src/function/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ pub const fn static_func<Kind, F: IntoPyNativeFn<Kind>>(f: F) -> &'static dyn Py
zst_ref_out_of_thin_air(into_func(f))
}

#[inline(always)]
pub const fn static_raw_func<F: PyNativeFn>(f: F) -> &'static dyn PyNativeFn {
zst_ref_out_of_thin_air(f)
}

// TODO: once higher-rank trait bounds are stabilized, remove the `Kind` type
// parameter and impl for F where F: for<T, R, VM> PyNativeFnInternal<T, R, VM>
impl<F, T, R, VM> IntoPyNativeFn<(T, R, VM)> for F
Expand Down
15 changes: 15 additions & 0 deletions vm/src/function/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ impl PyMethodDef {
}
}

#[inline]
pub const fn new_raw_const(
name: &'static str,
func: impl PyNativeFn,
flags: PyMethodFlags,
doc: Option<&'static str>,
) -> Self {
Self {
name,
func: super::static_raw_func(func),
flags,
doc,
}
}

pub fn to_proper_method(
&'static self,
class: &'static Py<PyType>,
Expand Down
2 changes: 1 addition & 1 deletion vm/src/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub use argument::{
};
pub use arithmetic::{PyArithmeticValue, PyComparisonValue};
pub use buffer::{ArgAsciiBuffer, ArgBytesLike, ArgMemoryBuffer, ArgStrOrBytesLike};
pub use builtin::{static_func, IntoPyNativeFn, PyNativeFn};
pub use builtin::{static_func, static_raw_func, IntoPyNativeFn, PyNativeFn};
pub use either::Either;
pub use fspath::FsPath;
pub use getset::PySetterValue;
Expand Down
0