Skip to content

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

Merged
fanninpm merged 2 commits into
RustPython:mainfrom
youknowone:into-exact-or
Mar 27, 2023
Merged

Fix str.__str__ and PyRef::into_exact_or for int() or str() pattern#4732
fanninpm merged 2 commits into
RustPython:mainfrom
youknowone:into-exact-or

Conversation

@youknowone

Copy link
Copy Markdown
Member

disallowing subclass is a repeatitive pattern

Comment thread vm/src/builtins/int.rs
#[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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@DimitrisJim DimitrisJim left a comment

Copy link
Copy Markdown
Member

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