[issue20115] NUL bytes in commented lines
Terry J. Reedy
report at bugs.python.org
Mon Sep 6 19:29:59 EDT 2021
Terry J. Reedy <tjreedy at udel.edu> added the comment:
The compile() doc currently says ""This function raises SyntaxError if the compiled source is invalid, and ValueError if the source contains null bytes." And indeed, in repository 3.9, 3.10, 3.11,
>>> compile('\0','','exec')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: source code string cannot contain null bytes
Ditto when run same in a file from IDLE or command line. The exception sometimes when the null is in a comment or string within the code.
>>> '\0'
'\x00'
>>> #\0
>>> compile('#\0','','single', 0x200)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: source code string cannot contain null bytes
>>> compile('"\0"','','single', 0x200)
ValueError: source code string cannot contain null bytes
I am puzzled because "\0" and #\0 in the IDLE shell are sent as strings containing the string or comment to compiled with the call above in codeop. There must be some difference in when \0 is interpreted.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue20115>
_______________________________________
More information about the Python-bugs-list
mailing list