IjHVSrSSKrSSKJr SSKJr SSKJr Sr"SS5r "S S \ 5r "S S \ \R5r "S S\ \R5r "SS\ \R5r"SS\ \R5r"SS\ \R5r"SS\ \R5r"SS\ \R5r"SS\ \R5r"SS\ \R5r"SS\ \R5r"SS \ \R5r"S!S"\ \R5r"S#S$\5r"S%S&\5r"S'S(\5r"S)S*\R5r\S+:Xa\R<"5 gg),aTest Iterator Length Transparency Some functions or methods which accept general iterable arguments have optional, more efficient code paths if they know how many items to expect. For instance, map(func, iterable), will pre-allocate the exact amount of space required whenever the iterable can report its length. The desired invariant is: len(it)==len(list(it)). A complication is that an iterable and iterator can be the same object. To maintain the invariant, an iterator needs to dynamically update its length. For instance, an iterable such as range(10) always reports its length as ten, but it=iter(range(10)) starts at ten, and then goes to nine after next(it). Having this capability means that map() can ignore the distinction between map(func, iterable) and map(func, iter(iterable)). When the iterable is immutable, the implementation can straight-forwardly report the original length minus the cumulative number of calls to next(). This is the case for tuples, range objects, and itertools.repeat(). Some containers become temporarily immutable during iteration. This includes dicts, sets, and collections.deque. Their implementation is equally simple though they need to permanently set their length to zero whenever there is an attempt to iterate after a length mutation. The situation slightly more involved whenever an object allows length mutation during iteration. Lists and sequence iterators are dynamically updatable. So, if a list is extended during iteration, the iterator will continue through the new items. If it shrinks to a point before the most recent iteration, then no further items are available and the length is reported at zero. Reversed objects can also be wrapped around mutable objects; however, any appends after the current position are ignored. Any other approach leads to confusion and possibly returning the same item more than once. The iterators not listed above, such as enumerate and the other itertools, are not length transparent because they have no way to distinguish between iterables that report static length and iterators whose length changes with each call (i.e. the difference between enumerate('abc') and enumerate(iter('abc')). N)repeat)deque) length_hint c\rSrSrSrSrg)TestInvariantWithoutMutations4cPURn[[S[S-55H)nUR [ U5U5 [ U5 M+ UR [ U5S5 UR[[ U5 UR [ U5S5 gNr) itreversedrangen assertEqualrnext assertRaises StopIteration)selfr is 8/opt/alt/python313/lib64/python3.13/test/test_iterlen.pytest_invariant,TestInvariantWithoutMutations.test_invariant6s{ WW%1Q3-(A   [_a 0 H) R!, -r2 R!,N)__name__ __module__ __qualname____firstlineno__r__static_attributes__rrrrr4s-rrc\rSrSrSrSrg)TestTemporarilyImmutable?c@URnUR[U5[5 [ U5 UR[U5[S- 5 UR 5 UR [[U5 UR[U5S5 gr )r rrrrmutater RuntimeError)rr s rtest_immutable_during_iteration8TestTemporarilyImmutable.test_immutable_during_iterationAsoWW R!, R R!A#.  ,b1 R!,rrN)rrrrr'r rrrr"r"?s -rr"c\rSrSrSrSrg) TestRepeatOc.[S[5UlgN)rrr rs rsetUpTestRepeat.setUpQsq/rr Nrrrrr/r rrrr*r*Os"rr*c\rSrSrSrSrg) TestXrangeTc>[[[55Ulgr-iterrrr r.s rr/TestXrange.setUpVuQx.rr1Nr2rrrr4r4Ts!rr4c\rSrSrSrSrg)TestXrangeCustomReversedYc>[[[55Ulgr-rrrr r.s rr/TestXrangeCustomReversed.setUp[58$rr1Nr2rrrr<r<Ys%rr<c\rSrSrSrSrg) TestTuple^cP[[[[555Ulgr-)r8tuplerrr r.s rr/TestTuple.setUp`suU1X'rr1Nr2rrrrCrC^s(rrCc\rSrSrSrSrg) TestDequeecv[[[55n[U5UlUR Ulgr-)rrrr8r popr%rds rr/TestDeque.setUpgs% %(Oq'ee rr r%Nr2rrrrIrIerrIc\rSrSrSrSrg)TestDequeReversedlcv[[[55n[U5UlUR Ulgr-)rrrrr rLr%rMs rr/TestDequeReversed.setUpns% %(O1+ee rrPNr2rrrrSrSlrQrrSc\rSrSrSrSrg) TestDictKeyssc[R[[55n[ U5UlUR Ulgr-)dictfromkeysrrr8r popitemr%rMs rr/TestDictKeys.setUpus* MM%( #q'ii rrPNr2rrrrXrXs rrXc\rSrSrSrSrg) TestDictItemszc[R[[55n[ UR 55UlURUlgr-) r[r\rrr8itemsr r]r%rMs rr/TestDictItems.setUp|s0 MM%( #qwwy/ii rrPNr2rrrrarazr_rrac\rSrSrSrSrg)TestDictValuesc[R[[55n[ UR 55UlURUlgr-) r[r\rrr8valuesr r]r%rMs rr/TestDictValues.setUps1 MM%( #qxxz"ii rrPNr2rrrrgrgr_rrgc\rSrSrSrSrg)TestSetcv[[[55n[U5UlUR Ulgr-)setrrr8r rLr%rMs rr/ TestSet.setUps% aMq'ee rrPNr2rrrrmrmrQrrmc \rSrSrSrSrSrg)TestListc>[[[55Ulgr-r7r.s rr/TestList.setUpr:rc[[[55n[U5n[ U5 [ U5 UR [ U5[S- 5 UR[5 UR [ U5[S- 5 /USS&UR [ U5S5 UR [U5/5 UR[S55 UR [ U5S5 gNr r) listrrr8rrrappendextendrrNr s r test_mutationTestList.test_mutations qN !W R R R!a%0   R!a%0!" R!, b2& r R!,rr1Nrrrrr/rr rrrrsrss ! -rrsc \rSrSrSrSrSrg)TestListReversedc>[[[55Ulgr-r?r.s rr/TestListReversed.setUprArc[[[55n[U5n[ U5 [ U5 UR [ U5[S- 5 UR[5 UR [ U5[S- 5 /USS&UR [ U5S5 UR [U5/5 UR[S55 UR [ U5S5 grx) r{rrrrrrr|r}r~s rrTestListReversed.test_mutations qN a[ R R R!a%0   R!a%0!" R!, b2& r R!,rr1Nrrrrrrs % -rrc \rSrSrSrSrSrg)BadLenc*[[S55$Nrr8rr.s r__iter__BadLen.__iter__E"Irc[S5eNhellor&r.s r__len__BadLen.__len__ 7##rrN)rrrrrrr rrrrr $rrc \rSrSrSrSrSrg) BadLengthHintc*[[S55$rrr.s rrBadLengthHint.__iter__rrc[S5errr.s r__length_hint__BadLengthHint.__length_hint__rrrNrrrrrrr rrrrrrrrc \rSrSrSrSrSrg)NoneLengthHintc*[[S55$rrr.s rrNoneLengthHint.__iter__rrc[$r-)NotImplementedr.s rrNoneLengthHint.__length_hint__srrNrrrrrrs rrc \rSrSrSrSrSrg)TestLengthHintExceptionscUR[[[55 UR[[[ 55 UR[/R [55 UR[/R [ 55 [ [S55nUR[UR [55 UR[UR [ 55 gr)rr&r{rrr} bytearrayr)rbs rtest_issue1242657*TestLengthHintExceptions.test_issue1242657s ,fh7 ,mo> , 68< , =?C eBi  ,&(; ,-/BrcnUR[[55[[S555 gr)rr{rrr.s rtest_invalid_hint*TestLengthHintExceptions.test_invalid_hints" n./eBiArrN)rrrrrrr rrrrrsCBrr__main__)__doc__unittest itertoolsr collectionsroperatorrrrr"TestCaser*r4r<rCrIrSrXrargrmrsrobjectrrrrrmainrrrrs)V  - - -< - ".0A0A" !.0A0A! %O>O% (-x/@/@(((*;*;0(2C2C +X->->  ,h.?.?  -x/@/@ &(9(9-,h.?.?-(-4h6G6G-,$V$$F$V Bx00 B  z MMOr