The Wayback Machine - https://web.archive.org/web/20250522034721/https://github.com/RustPython/RustPython/pull/2163
Skip to content

Make class.slots completely immutable #2163

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 7 commits into from
Sep 5, 2020

Conversation

coolreader18
Copy link
Member

No description provided.

@coolreader18
Copy link
Member Author

Ooh, better idea: make PyStructSequence a trait that you add with pyimpl(with()). Then we make pystruct_sequence just a derive rather than a sort of duplicate pyclass

@youknowone
Copy link
Member

oh, that sounds great

@coolreader18 coolreader18 force-pushed the coolreader18/immutable-slots branch 2 times, most recently from 356d500 to d0573a6 Compare August 30, 2020 19:11
@coolreader18 coolreader18 force-pushed the coolreader18/immutable-slots branch from 943db39 to d7bdaf1 Compare August 30, 2020 20:03
@coolreader18 coolreader18 force-pushed the coolreader18/immutable-slots branch from d7bdaf1 to 43b7a7b Compare August 30, 2020 20:47
@coolreader18
Copy link
Member Author

@youknowone can you review?

@youknowone
Copy link
Member

I will do it soon. I had a few busy days 😵

@coolreader18
Copy link
Member Author

No problem, take your time :)

Copy link
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything is pyclass, good!

}
iter_chain![
parse_quote! {
fn __extend_py_class(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this also become #[extend_class]?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extend_class works by just calling the #[extend_class]-marked method in the generated extend_class method; for a PyClassImpl that's the impl_extend_class method and for a trait/interface that's this "magic" method; extend_class can't substitute for the actual generated method.

Comment on lines +50 to +59
(@extract_slots($ctx:expr, $slots:expr, (slot $slot_name:ident), $value:expr)) => {
$slots.$slot_name = Some(
$crate::function::IntoPyNativeFunc::into_func($value)
);
};
(@extract_slots($ctx:expr, $class:expr, $name:expr, $value:expr)) => {};
(@extract_attrs($ctx:expr, $slots:expr, (slot $slot_name:ident), $value:expr)) => {};
(@extract_attrs($ctx:expr, $class:expr, $name:expr, $value:expr)) => {
$class.set_str_attr($name, $value);
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there benefits to keep these parts in the same macro? i am curious if this is a sort of recommended convention or not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort of; I know that tokio does that with their macros; I think it keeps the logic encapsulated so that when there's a @extract_slots inside you know that it's in the same macro definition.

@youknowone youknowone merged commit a1a8d03 into master Sep 5, 2020
@youknowone youknowone deleted the coolreader18/immutable-slots branch September 5, 2020 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants