-
Notifications
You must be signed in to change notification settings - Fork 2
Refactor pyo3 usage #27
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
Conversation
3d9cadf
to
f196892
Compare
855819c
to
e0e068d
Compare
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.
Lovely stuff!
with pytest.raises(ValueError) as exc_info: | ||
fluent.Bundle("$", []) | ||
|
||
assert str(exc_info.value) == "Invalid language: '$'" |
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.
🐼 Could do this using with pytest.raises(Value, match="..."):
.
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 could, but I don't really like it because then I have to deal with regexes and escaping. This way it's an exact match.
|
||
if let Some(variables) = variables { | ||
for variable in variables { | ||
for (python_key, python_value) in variables { |
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.
Much nicer. 😄
create_exception!(rustfluent, ParserError, pyo3::exceptions::PyException); | ||
|
||
#[pymodule] | ||
fn rustfluent(m: &Bound<'_, PyModule>) -> PyResult<()> { |
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 shout, I much prefer the new syntax.
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.
Yeah, me too!
} | ||
} | ||
} else if python_value.is_instance_of::<PyInt>() | ||
&& let Ok(int_value) = python_value.extract::<i32>() |
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 didn't know you could do this, cool!
Depends on #26.
.expect
with raising aValueError
for malformedlanguage
tuple
unpacking into thefor
loopFluentArgs
by only doing the fallback in one placeerrors
Vec
next to thebundle.format_pattern
that uses it