Merged
Conversation
davidhewitt
approved these changes
Nov 19, 2020
Member
davidhewitt
left a comment
There was a problem hiding this comment.
👍 looks great, thanks! I made some minor nitpicks, only one I'd definitely like to see is the error message formatting.
Also CHANGELOG entry 😉
src/conversion.rs
Outdated
| where | ||
| T: ToPyObject, | ||
| { | ||
| impl<'a, T: ?Sized + ToPyObject> ToPyObject for &'a T { |
Member
There was a problem hiding this comment.
👍 nice! I think the lifetime can maybe also be anonymous
Suggested change
| impl<'a, T: ?Sized + ToPyObject> ToPyObject for &'a T { | |
| impl<T: ?Sized + ToPyObject> ToPyObject for &'_ T { |
src/types/string.rs
Outdated
Comment on lines
+188
to
+189
| impl<'source> FromPyObject<'source> for char { | ||
| fn extract(obj: &'source PyAny) -> PyResult<Self> { |
Member
There was a problem hiding this comment.
Similarly can skip the lifetime here:
Suggested change
| impl<'source> FromPyObject<'source> for char { | |
| fn extract(obj: &'source PyAny) -> PyResult<Self> { | |
| impl FromPyObject<'_> for char { | |
| fn extract(obj: &PyAny) -> PyResult<Self> { |
src/types/string.rs
Outdated
| Ok(ch) | ||
| } else { | ||
| Err(crate::exceptions::PyValueError::new_err(format!( | ||
| "Expected a sting of length 1", |
Member
There was a problem hiding this comment.
typo sting -> string, and I think the recommendation in #1212 (comment) was that it's better for us to make errors start with lowercase
Suggested change
| "Expected a sting of length 1", | |
| "expected a string of length 1", |
| #[test] | ||
| fn test_extract_char() { | ||
| Python::with_gil(|py| { | ||
| let ch = '😃'; |
Member
|
I'm working on a PR to fix the clippy errors with new Rust 1.48. |
birkenfeld
reviewed
Nov 19, 2020
| let ch = '😃'; | ||
| let py_string = ch.to_object(py); | ||
| let ch2: char = FromPyObject::extract(py_string.as_ref(py)).unwrap(); | ||
| assert_eq!(ch, ch2); |
Member
There was a problem hiding this comment.
Is there a test for the error case (string with len > 1)?
Member
|
Rebase on master to fix CI (see #1284). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolve #1281. Support char and
PyStringconversion.I'm sorry this PR includes some unrelated cleanups. Since recently I don't have much time for PyO3, I think it would be better to do some cleanups when I find the necessity.