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
changes to some coercions #208
Conversation
Codecov Report
@@ Coverage Diff @@
## main #208 +/- ##
==========================================
- Coverage 98.68% 98.63% -0.05%
==========================================
Files 47 47
Lines 4936 4988 +52
Branches 34 34
==========================================
+ Hits 4871 4920 +49
- Misses 65 68 +3
Continue to review full report at Codecov.
|
24b77cd
to
8b375e8
Compare
@samuelcolvin I opened PyO3/pyo3#2527, which should help to do some checks on dict keys and values. |
Ye, I saw the PR, I'll comment. On If we don't do it now, let's create an issue to remember. |
I won't bother with dict items for the moment. Probably a good first issue. |
acc1483
to
1199e66
Compare
Hi @samuelcolvin. This should be ready for a first review. Reading commit per commit should help. |
1199e66
to
20e37a7
Compare
Ok I updated the PR without the |
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 some extra tests now.
Overall this is looking great.
src/input/input_python.rs
Outdated
} else if let Ok(iterator) = self.cast_as::<PyIterator>() { | ||
let tuple = PyTuple::new(self.py(), iterator.iter()?.flatten().collect::<Vec<_>>()); | ||
Ok(tuple.into()) | ||
} else if let Ok(dict_keys) = self.cast_as::<PyDictKeys>() { | ||
let tuple = PyTuple::new(self.py(), dict_keys.iter()?.flatten().collect::<Vec<_>>()); | ||
Ok(tuple.into()) | ||
} else if let Ok(dict_values) = self.cast_as::<PyDictValues>() { | ||
let tuple = PyTuple::new(self.py(), dict_values.iter()?.flatten().collect::<Vec<_>>()); | ||
Ok(tuple.into()) |
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 like we have this lump of code in multiple cases, could you move it into a macro (or parameterised function?) and reuse?
@PrettyWood I think I've found an error with generators (I think the error is in pyo3), WDYT? The following unit test fails: def test_generator_error():
def gen(error: bool):
yield 1
yield 2
if error:
raise RuntimeError('error')
yield 3
v = SchemaValidator({'type': 'list', 'items_schema': 'int'})
assert v.validate_python(gen(False)) == [1, 2, 3]
with pytest.raises(ValidationError, match='???'):
v.validate_python(gen(True)) Because |
src/input/_pyo3_dict.rs
Outdated
/// Represents a Python `dict_items`. | ||
#[cfg(not(PyPy))] | ||
#[repr(transparent)] | ||
pub struct PyDictItems(PyAny); | ||
|
||
#[cfg(not(PyPy))] | ||
pyobject_native_type_core!( | ||
PyDictItems, | ||
ffi::PyDictItems_Type, | ||
#checkfunction=ffi::PyDictItems_Check | ||
); |
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.
should we remove this as I think it's not used?
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.
Yes!
End of lunch break! I have meetings this afternoon. I can come back on it late at night. Feel free to make the changes you wish to see if you want to go fast |
okay, will do, thanks for your help. |
Very weird. Indeed it seems to be buggy. If the issue on pyo3 is confirmed we can open an issue and one of us can try to fix it on pyo3 side |
Yup, I'm looking into it. |
@samuelcolvin You probably already found the issue but I reckon the |
yes, just found it, fixing now. |
I mean't "pypy", not "mypy" in the last commit. I think this is ready. |
thanks @PrettyWood 🙏 |
set / frozenset
tolist / tuple
dict_key
anddict_value
closes #191