On Tue, Jan 14, 2014 at 7:59 AM, Guido van Rossum <gu...@python.org> wrote: > Here's an example of what I mean:
I sent that off without proofreading, and I also got one detail about asciistr() wrong. Here are some corrections. > def spam(a): > r = asciistr('(') > if a: r += a.strip() > r += asciistr(')') > return r > > The argument must be a string. Or a bytes object. And the point is that the return type should be the same as the argument type. > If I call spam(''), or spam(b'') > a's type is never concatenated with r, so the > return value is an asciistr. Actually, Nick explained that asciistr() + asciistr() returns str, so this would be accidentally correct if called with '', but wrong (returning a str instead of a bytes) if called with b''. > To fix this particular case, we could > drop the "if a:" part. But it could be more significant, e.g. it could > be something like "if a contains any digits". The general fix would be > to add > > else: r += a[:0] > > but that's still an example of the awkwardness that asciistr() is > trying to avoid. This is still valid. -- --Guido van Rossum (python.org/~guido) _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com