-
Notifications
You must be signed in to change notification settings - Fork 893
Char support #1282
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
Char support #1282
Conversation
davidhewitt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 nice! I think the lifetime can maybe also be anonymous
| impl<'a, T: ?Sized + ToPyObject> ToPyObject for &'a T { | |
| impl<T: ?Sized + ToPyObject> ToPyObject for &'_ T { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
src/types/string.rs
Outdated
| impl<'source> FromPyObject<'source> for char { | ||
| fn extract(obj: &'source PyAny) -> PyResult<Self> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly can skip the lifetime here:
| 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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo sting -> string, and I think the recommendation in #1212 (comment) was that it's better for us to make errors start with lowercase
| "Expected a sting of length 1", | |
| "expected a string of length 1", |
| #[test] | ||
| fn test_extract_char() { | ||
| Python::with_gil(|py| { | ||
| let ch = '😃'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😃
|
I'm working on a PR to fix the clippy errors with new Rust 1.48. |
| let ch = '😃'; | ||
| let py_string = ch.to_object(py); | ||
| let ch2: char = FromPyObject::extract(py_string.as_ref(py)).unwrap(); | ||
| assert_eq!(ch, ch2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a test for the error case (string with len > 1)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 good idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
|
Rebase on master to fix CI (see #1284). |
davidhewitt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
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.