Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:

Your functions test1 and test2 are irrelevant to the bug report. The driver 
code using eval() to pick which function to call is unneeded. The business of 
simulating a file is complexity for no purpose.

Those ignore, count, unique functions are also irrelevant.

Removing all the irrelevant and extraneous complexity that obfuscates the 
problem, we get to two lines of simplified code sufficient to demonstrate the 
issue:

    each = "name = "
    [code.strip()[0] for func, code in [each.split('=')]]

which sure enough raises IndexError.

The hint was looking at your fix() function, which made it clear that you are 
getting an IndexError because the string is an empty string. Well of course you 
do, that is expected behaviour.

Why do you get an empty string? Because you split the line "name = " on the 
equals sign, giving

    func = "name "
    code = " "

then you strip the whitespace from code giving:

    code = ""

then you try to extract the first character of code using code[0], which raises 
IndexError, because that's what it is supposed to do.

So there is no bug here, Python is working correctly.

----------
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

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

Reply via email to