Uname: Linux web3.us.cloudlogin.co 5.10.226-xeon-hst #2 SMP Fri Sep 13 12:28:44 UTC 2024 x86_64
Software: Apache
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.210.96.117
Your Ip: 3.22.42.216
User: edustar (269686) | Group: tty (888)
Safe Mode: OFF
Disable Function:
NONE

name : test_iterlen.cpython-310.pyc
o

abb�@s�dZddlZddlmZddlmZddlmZdZGdd�d�Z	Gd	d
�d
e	�Z
Gdd�de	ej�ZGd
d�de	ej�Z
Gdd�de	ej�ZGdd�de	ej�ZGdd�de
ej�ZGdd�de
ej�ZGdd�de
ej�ZGdd�de
ej�ZGdd�de
ej�ZGdd�de
ej�ZGdd �d e	ej�ZGd!d"�d"e	ej�ZGd#d$�d$e�ZGd%d&�d&e�ZGd'd(�d(e�ZGd)d*�d*ej�Zed+kr�e��dSdS),a� Test 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@�eZdZdd�ZdS)�TestInvariantWithoutMutationscCsh|j}ttdtd��D]}|�t|�|�t|�q|�t|�d�|�tt|�|�t|�d�dS�N�r)	�it�reversed�range�n�assertEqualr�next�assertRaises�
StopIteration)�selfr
�i�r�:/usr/local/python-3.10/lib/python3.10/test/test_iterlen.py�test_invariant6s
z,TestInvariantWithoutMutations.test_invariantN)�__name__�
__module__�__qualname__rrrrrr4�rc@r)�TestTemporarilyImmutablecCs\|j}|�t|�t�t|�|�t|�td�|��|�tt|�|�t|�d�dSr)r
rrr
r�mutater�RuntimeError)rr
rrr�test_immutable_during_iterationAsz8TestTemporarilyImmutable.test_immutable_during_iterationN)rrrrrrrrr?rrc@r)�
TestRepeatcCstdt�|_dS�N)rr
r
�rrrr�setUpQszTestRepeat.setUpN�rrrr"rrrrrOrrc@r)�
TestXrangecC�ttt��|_dSr ��iterrr
r
r!rrrr"V�zTestXrange.setUpNr#rrrrr$Trr$c@r)�TestXrangeCustomReversedcCr%r �rrr
r
r!rrrr"[r(zTestXrangeCustomReversed.setUpNr#rrrrr)Yrr)c@r)�	TestTuplecCstttt���|_dSr )r'�tuplerr
r
r!rrrr"`szTestTuple.setUpNr#rrrrr+^rr+c@r)�	TestDequecC�"ttt��}t|�|_|j|_dSr )rrr
r'r
�popr�r�drrrr"g�
zTestDeque.setUpNr#rrrrr-err-c@r)�TestDequeReversedcCr.r )rrr
rr
r/rr0rrrr"nr2zTestDequeReversed.setUpNr#rrrrr3lrr3c@r)�TestDictKeyscCs$t�tt��}t|�|_|j|_dSr )�dict�fromkeysrr
r'r
�popitemrr0rrrr"us
zTestDictKeys.setUpNr#rrrrr4srr4c@r)�
TestDictItemscC�(t�tt��}t|���|_|j|_dSr )	r5r6rr
r'�itemsr
r7rr0rrrr"|�zTestDictItems.setUpNr#rrrrr8zrr8c@r)�TestDictValuescCr9r )	r5r6rr
r'�valuesr
r7rr0rrrr"�r;zTestDictValues.setUpNr#rrrrr<�rr<c@r)�TestSetcCr.r )�setrr
r'r
r/rr0rrrr"�r2z
TestSet.setUpNr#rrrrr>�rr>c@�eZdZdd�Zdd�ZdS)�TestListcCr%r r&r!rrrr"�r(zTestList.setUpcCs�ttt��}t|�}t|�t|�|�t|�td�|�t�|�t|�td�g|dd�<|�t|�d�|�t|�g�|�td��|�t|�d�dS�N�r	r�)	�listrr
r'rrr�append�extend�rr1r
rrr�
test_mutation��
zTestList.test_mutationN�rrrr"rIrrrrrA��rAc@r@)�TestListReversedcCr%r r*r!rrrr"�r(zTestListReversed.setUpcCs�ttt��}t|�}t|�t|�|�t|�td�|�t�|�t|�td�g|dd�<|�t|�d�|�t|�g�|�td��|�t|�d�dSrB)	rErr
rrrrrFrGrHrrrrI�rJzTestListReversed.test_mutationNrKrrrrrM�rLrMc@r@)�BadLencC�ttd��S�Nr�r'rr!rrr�__iter__��zBadLen.__iter__cC�td���NZhello�rr!rrr�__len__��zBadLen.__len__N)rrrrRrWrrrrrN��rNc@r@)�
BadLengthHintcCrOrPrQr!rrrrR�rSzBadLengthHint.__iter__cCrTrUrVr!rrr�__length_hint__�rXzBadLengthHint.__length_hint__N�rrrrRr[rrrrrZ�rYrZc@r@)�NoneLengthHintcCrOrPrQr!rrrrR�rSzNoneLengthHint.__iter__cCstSr )�NotImplementedr!rrrr[�szNoneLengthHint.__length_hint__Nr\rrrrr]�rYr]c@r@)�TestLengthHintExceptionscCsx|�ttt��|�ttt��|�tgjt��|�tgjt��ttd��}|�t|jt��|�t|jt��dSrP)rrrErNrZrG�	bytearrayr)r�brrr�test_issue1242657�sz*TestLengthHintExceptions.test_issue1242657cCs|�tt��ttd���dSrP)rrEr]rr!rrr�test_invalid_hint�sz*TestLengthHintExceptions.test_invalid_hintN)rrrrbrcrrrrr_�s	r_�__main__)�__doc__Zunittest�	itertoolsr�collectionsr�operatorrr
rrZTestCaserr$r)r+r-r3r4r8r<r>rArM�objectrNrZr]r_r�mainrrrr�<module>s6+	�
© 2025 GrazzMean