This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steven.daprano
Recipients NetAlien, Stefan Pochmann, steven.daprano
Date 2022-01-08.01:11:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1641604295.19.0.148339461247.issue46302@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2022-01-08 01:11:35steven.dapranosetrecipients: + steven.daprano, Stefan Pochmann, NetAlien
2022-01-08 01:11:35steven.dapranosetmessageid: <1641604295.19.0.148339461247.issue46302@roundup.psfhosted.org>
2022-01-08 01:11:35steven.dapranolinkissue46302 messages
2022-01-08 01:11:35steven.dapranocreate