support lazy batching again, support general iterators #76
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.
Fixes #75.
dtml-in
's lazy batching was broken by listifying the incoming sequence in order to support some iterators (e.g.dict
key views).This PR replaces the listifying by a
sequence_ensure_subscription
wrapper ensuring that the returned object has sequence like behavior sufficient fordtml-in
. It uses the original object if this already fulfills the requirement, otherwise a wrapper which lazily emulates sequence behavior for an arbitrary iterator.The main problem with the approach is the recognition whether the incoming sequence already fulfills the requirements. For this it uses the following heuristics:
seq[0]
. If this raisesIndexError
it assumes "sufficiently sequence like"; if it raisesAttributeError
,TypeError
orKeyError
it assumes "not sufficiently sequence like"seq
is not a mapping. For this it accessesseq[None]
. Most sequence types will raise an exception if the index is not an integer or a slice. The heuristics checks forTypeError
,ValueError
andRuntimeError
(the latter becauseZTUtils.Lazy.Lazy
used this exception. If one of those exceptions is raised, it assumes "sufficuetly sequence like".The approach is not very robust as it makes assumptions about the raised exceptions. Nevertheless, the PR relies on explicit exception enumeration because in the context of
Zope
temporary exceptions can arise which we do not want to catch. I am open for other heuristics.