-
-
Notifications
You must be signed in to change notification settings - Fork 36
Fix deserializing set
and frozenset
.
#39
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
`set` and `frozenset` don't support the Sequence protocol, but they do support the Iterator protocol, so let's use that instead.
let mut item_de = Depythonizer::from_object(self.seq.get_item(self.index)?); | ||
let item = match self.seq.next() { | ||
Some(item) => item?, | ||
None => return Ok(None), |
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.
This branch shouldn't happen for set
or frozenset
, since the length is known.
It might not be necessary to have the index checks any more, as long as we still check the length
is finite.
@@ -289,13 +289,13 @@ impl<'a, 'de> de::Deserializer<'de> for &'a mut Depythonizer<'de> { | |||
} | |||
|
|||
struct PySequenceAccess<'a> { |
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.
It might be appropriate to rename this too, perhaps to PyIteratorAccess
.
Codecov ReportPatch coverage:
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## main #39 +/- ##
==========================================
+ Coverage 80.99% 81.40% +0.40%
==========================================
Files 4 4
Lines 1021 1038 +17
==========================================
+ Hits 827 845 +18
+ Misses 194 193 -1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Thanks for this! This seems reasonable, though I'm also slightly cautious. What's the use case for this? I'm split down the middle on whether allowing To be fair, |
While I was trying to work out what the best way to handle my use case (see #38) I discovered that the
Yeah - the alternatives I can think of are:
Yeah, the serde docs (https://serde.rs/data-model.html#types) suggest this handling too, so it's consistent with rust stuff in general. But it does lose a bit of information, so I'm also not certain what's best. |
For my use case, an error immediately with #38 or something with |
Adding these tests shows the following errors: