Expose wrapped iterator in SerializationIterator
Change Summary
We're currently working around pydantic#8907 by parsing the pointer out of the repr(). To make this workaround slightly better, we'd like to expose the wrapped iterator in SerializationIterator via .iterator.
Related issue number
- Related to: https://github.com/pydantic/pydantic/issues/8907
Checklist
- [x] Unit tests for the changes exist
- [ ] Documentation reflects the changes where applicable
- [ ] Pydantic tests pass with this
pydantic-core(except for expected changes) - [x] My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 89.54%. Comparing base (
ab503cb) to head (6e3ed61). Report is 211 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #1399 +/- ##
==========================================
- Coverage 90.21% 89.54% -0.68%
==========================================
Files 106 109 +3
Lines 16339 17348 +1009
Branches 36 41 +5
==========================================
+ Hits 14740 15534 +794
- Misses 1592 1794 +202
- Partials 7 20 +13
| Files with missing lines | Coverage Δ | |
|---|---|---|
| src/serializers/type_serializers/generator.rs | 81.39% <ø> (-13.46%) |
:arrow_down: |
... and 39 files with indirect coverage changes
Continue to review full report in Codecov by Sentry.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 39a6b10...6e3ed61. Read the comment docs.
Test failure looks unrelated.
CodSpeed Performance Report
Merging #1399 will not alter performance
Comparing yorickvP:yorickvp/expose-sit-iterator (6e3ed61) with main (39a6b10)
Summary
✅ 155 untouched benchmarks
I'm not convinced this is a good idea; it seems like it's part of the same old pattern that SerializationIterator is lazy validation that this has become a problem.
Why I don't think this is a good idea: if you call next(my_model.field.iterator) you'll be consuming a value from the underlying iterator without ever validating it. I don't think we want that.
I'd prefer we actually fixed the root problem rather than exposing a backdoor to make workarounds easier.
Agreed with @davidhewitt here. We're planning a rework of Iterable stuff in v2.11, so going to close this for now.
Here's the workaround for anyone else running into this issue in the meantime:
from ctypes import *
import re
def unwrap_SerializationIterator(x: SerializationIterator) -> Any:
return cast(int(re.findall(r'0x[0-9A-F]+', repr(x), re.I)[0], 16), py_object).value