[Python-Dev] PEP 409 and the stdlib
ncoghlan at gmail.com
Mon May 20 23:37:38 CEST 2013
On 21 May 2013 05:01, "Ethan Furman" <ethan at stoneleaf.us> wrote:
> On 05/20/2013 11:32 AM, Terry Jan Reedy wrote:
>> On 5/20/2013 11:39 AM, Steven D'Aprano wrote:
>>> On 21/05/13 00:12, Ethan Furman wrote:
>>>> As a case in point, base64.py is currently getting a bug fix, and also
>>>> contains this code:
>>>> def b32decode(s, casefold=False, map01=None):
>>>> for i in range(0, len(s), 8):
>>>> quanta = s[i: i + 8]
>>>> acc = 0
>>>> for c in quanta:
>>>> acc = (acc << 5) + b32rev[c]
>>>> except KeyError:
>>>> raise binascii.Error('Non-base32 digit found')
>>>> raise binascii.Error('Incorrect padding')
>>>> Does the KeyError qualify as irrelevant noise?
>>> IMO, it is irrelevant noise, and obviously so. The binascii.Error raised
>>> is not a bug to be fixed, it is a deliberate exception and part of the
>>> API of the binascii module. That it occurs inside an "except KeyError"
>>> block is a mere implementation detail.
>> Yes, the code could be revised to make a check on c before the indexing.
>> This would be redundant (and a slowdown) in that the check is already
done by the indexing mechanism. The whole point of
>> the above is to *replace* the default KeyError with a custom
binascii.Error for too-large chars.
>> And I agree with Georg, please say which bad digit was found.
> Actually, that was Antoine, but I'm sure Georg also agrees. ;)
Indeed, a good question to ask when making use of PEP 409 is what debugging
info is being lost by suppressing the original exception, and then making
sure that info is captured and reported by the outer exception.
There's probably a new PEP 8 guideline in this thread - perhaps something
based on the above paragraph.
> Python-Dev mailing list
> Python-Dev at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev