Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Implement IncrementalNewlineDecoder in rust #5443

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

Conversation

coolreader18
Copy link
Member

No description provided.

@coolreader18 coolreader18 force-pushed the incremental-newline-decoder branch from 1d8c3e8 to fbd0c7a Compare November 15, 2024 05:06
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.

Great, finally we have rust implementation of newline decoder.
Please check comment if you need TryFromBorrowedObject for PyObject.

@@ -138,7 +139,7 @@ fn generate_field((i, field): (usize, &Field)) -> Result<TokenStream> {
};

let name = field.ident.as_ref();
let name_string = name.map(Ident::to_string);
let name_string = name.map(|ident| ident.unraw().to_string());
Copy link
Member

Choose a reason for hiding this comment

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

👍

}
}

// TODO: figure out a way to let PyObjectRef implement TryFromBorrowedObject, and
Copy link
Member

Choose a reason for hiding this comment

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

PyObjectRef cannot, but PyObject can. Since PyObject can always be borrowed from PyObjectRef, I expect it has same effect.

impl<'a> TryFromBorrowedObject<'a> for &'a PyObject {
    fn try_from_borrowed_object(_vm: &VirtualMachine, obj: &'a PyObject) -> PyResult<Self> {
        Ok(obj)
    }
}

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 is possible, but not allowing PyObjectRef to be extracted isn't ideal, and I'd rather allow that and disallow &PyObject than the other way around.

Copy link
Member

Choose a reason for hiding this comment

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

Could you explain more about it?
For me, it doesn't seem possible without increasing refcount. And increasing a refcount is something not expected from TryFromBorrowedObject

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I didn't realize that was part of the contract for TryFromBorrowedObject. It seems useful to me to have some way of generalizing over a type that can be extracted from a borrowed pyobj, but doesn't necessarily have to borrow from it - like serde's Deserialize vs DeserializeOwned. Like this case - the T in extract_tuple() should be able to borrow from the pyobjectref in the tuple, but there's no reason we should enforce it - a (PyObjectRef,) is a perfectly reasonable thing to put there.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, I think I am going to catch up.

@coolreader18 coolreader18 merged commit adc05e6 into RustPython:main Dec 3, 2024
11 checks passed
@coolreader18 coolreader18 deleted the incremental-newline-decoder branch December 3, 2024 22:28
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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.