[issue40670] supplying an empty string to timeit causes an IndentationError
Serhiy Storchaka
report at bugs.python.org
Thu May 21 04:29:09 EDT 2020
Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:
Accepting an empty string in CLI is just an artifact of the implementation. There was no intention to support it. It will fail if pass a space:
./python -m timeit ' '
or two empty arguments:
IndentationError:
./python -m timeit '' ''
I do not see this is an issue. Garbage in -- garbage out. IndentationError is a subclass of SyntaxError, so if you handle it programmatically, it does not matter.
Of course we try to catch some user errors and provide informative traceback. timeit now correctly handles most of code which interferes with the control flow in functions and loops: 'return', 'yield', 'break', 'await'.
But it is still possible to bypass the validation. For example:
./python -m timeit -s 'while False:' -s ' pass' ' break'
I think there is an infinite number of ways to fool timeit. And an empty string is just one of them, not special enough to add a special handling in the code.
----------
nosy: +serhiy.storchaka
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40670>
_______________________________________
More information about the Python-bugs-list
mailing list