Skip to content

Fix str.__str__ and PyRef::into_exact_or for int() or str() pattern #4732

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 2 commits into from
Mar 27, 2023

Conversation

youknowone
Copy link
Member

disallowing subclass is a repeatitive pattern

#[pymethod(magic)]
fn int(self, vm: &VirtualMachine) -> PyRefExact<PyInt> {
self.into_exact_or(&vm.ctx, |zelf| unsafe {
// TODO: this is actually safe. we need better interface
Copy link
Member

Choose a reason for hiding this comment

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

we should definitely start documenting all the unsafe better at some point.

Copy link
Contributor

Choose a reason for hiding this comment

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

There's the allow-by-default undocumented_unsafe_blocks lint, in case we want to activate that.

Copy link
Member Author

Choose a reason for hiding this comment

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

That clippy option looks very good for us because we use a lot of unsafe blocks.

For this function, I'd like to make the basic PyRef creation functions to return PyRefExact first and turn them to PyRef later. In that case, everything will be safe by both semantics and rust grammars.

Copy link
Member

@DimitrisJim DimitrisJim left a comment

Choose a reason for hiding this comment

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

this lgtm

@fanninpm fanninpm added this pull request to the merge queue Mar 27, 2023
Merged via the queue into RustPython:main with commit 010640c Mar 27, 2023
@youknowone youknowone deleted the into-exact-or branch March 28, 2023 09:41
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.

3 participants