Change PyIterator::from_object` to return underlying TypeError #1051
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reviewing #1050 I realised that
PyIterator::from_object()
makes an unneccessaryPyIter_Check()
call as a successful result is already guaranteed to be an iterator.I simplified it so that the function now returns the error from
PyObject_GetIter()
instead of aPyDowncastError
. This helps the implementation of #1050 and I think also improves the experience here.Now this function will return the well-known
TypeError: 'Foo' object is not iterable
which comes fromPyObject_GetIter()
: (https://github.com/python/cpython/blob/8182cc2e68a3c6ea5d5342fed3f1c76b0521fbc1/Objects/abstract.c#L2624)