-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
fix with python parsing seen on pydantic-core #54
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,10 @@ struct PythonParser<'j> { | |
impl<'j> PythonParser<'j> { | ||
fn py_take_value<StringCache: StringMaybeCache>(&mut self, py: Python, peek: Peek) -> JsonResult<PyObject> { | ||
match peek { | ||
Peek::Null => { | ||
self.parser.consume_null()?; | ||
Ok(py.None()) | ||
} | ||
Peek::True => { | ||
self.parser.consume_true()?; | ||
Ok(true.to_object(py)) | ||
|
@@ -67,9 +71,15 @@ impl<'j> PythonParser<'j> { | |
self.parser.consume_false()?; | ||
Ok(false.to_object(py)) | ||
} | ||
Peek::Null => { | ||
self.parser.consume_null()?; | ||
Ok(py.None()) | ||
Peek::Minus | Peek::Infinity | Peek::NaN => { | ||
let n = self | ||
.parser | ||
.consume_number::<NumberAny>(peek.into_inner(), self.allow_inf_nan)?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe one solution is to remove |
||
match n { | ||
NumberAny::Int(NumberInt::Int(int)) => Ok(int.to_object(py)), | ||
NumberAny::Int(NumberInt::BigInt(big_int)) => Ok(big_int.to_object(py)), | ||
NumberAny::Float(float) => Ok(float.to_object(py)), | ||
} | ||
} | ||
Peek::String => { | ||
let s = self.parser.consume_string::<StringDecoder>(&mut self.tape)?; | ||
|
@@ -117,16 +127,6 @@ impl<'j> PythonParser<'j> { | |
} | ||
Ok(dict.to_object(py)) | ||
} | ||
_ => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, removing this clause did cause errors to fire here about non-exhaustive matching 😉. But I take your point about it not enforcing all datatypes. I think part of the performance win in #48 was that it effectively removed a large set of branches (from It's definitely possible that there's another way to express this which keeps the same performance property, might require a play and a think. |
||
let n = self | ||
.parser | ||
.consume_number::<NumberAny>(peek.into_inner(), self.allow_inf_nan)?; | ||
match n { | ||
NumberAny::Int(NumberInt::Int(int)) => Ok(int.to_object(py)), | ||
NumberAny::Int(NumberInt::BigInt(big_int)) => Ok(big_int.to_object(py)), | ||
NumberAny::Float(float) => Ok(float.to_object(py)), | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
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.
For what it's worth the compiler will probably reorder branches in a match for what it thinks makes most sense anyway (as long as they're not gated by conditionals, only one of these branches will be traversed), so moving this likely does nothing.