Terry J. Reedy <tjre...@udel.edu> added the comment:

The 'roughly equivalent' Python code is real code that really runs, and in that 
sense not pseudocode.  itertools is coded in C, which allows optional args with 
no default.  To have optional args when coding in Python, either a default is 
needed or the argument has to be turned into a residual args tuple of length 0 
or 1.  In the former case, 'var is None' should be read as being the equivalent 
of 'var is undefined' in the C code.

In the latter case, the best equivalent, which has its own noise, might be 

def repeat(object, *times):
    if not times:
        while True:
            yield object
    elif len(times) == 1:
        for i in range(times[0]):
            yield object
    else:
        raise TypeError(f'There can be at most 1 times argument, not 
{len(times)}')

I prefer what we have.

----------
nosy: +terry.reedy
type:  -> enhancement
versions:  -Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue34169>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to