Author terry.reedy
Recipients chepner, corona10, rhettinger, terry.reedy
Date 2018-07-21.03:31:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1532143888.25.0.56676864532.issue34169@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-07-21 03:31:28terry.reedysetrecipients: + terry.reedy, rhettinger, chepner, corona10
2018-07-21 03:31:28terry.reedysetmessageid: <1532143888.25.0.56676864532.issue34169@psf.upfronthosting.co.za>
2018-07-21 03:31:28terry.reedylinkissue34169 messages
2018-07-21 03:31:28terry.reedycreate