Documentation
Documentation
In Doc/library/functions.rst, the sentences that describe the source parameter for the exec() function read:
This function supports dynamic execution of Python code. source must be either a string or a code object. If it is a string, the string is parsed as a suite of Python statements which is then executed (unless a syntax error occurs). [1]_ If it is a code object, it is simply executed.
This explicitly restricts the source parameter to a string or a code object. However, the actual implementation accepts bytes-like objects (such as bytes, bytearray, and memoryview) as well, parsing them internally via the buffer protocol. Because the sentence omits this, users can easily misunderstand that passing bytes is unsupported.
Suggested change
This function supports dynamic execution of Python code. source must be a string, a bytes-like object, or a code object. If it is a string or a bytes-like object, it is parsed as a suite of Python statements which is then executed (unless a syntax error occurs). [1]_ If it is a code object, it is simply executed.
Adding "a bytes-like object" makes the documentation accurately reflect the underlying implementation. Changing the subsequent sentence ensures logical consistency for how these types are parsed.
Linked PRs
Documentation
Documentation
In
Doc/library/functions.rst, the sentences that describe thesourceparameter for theexec()function read:This explicitly restricts the
sourceparameter to a string or a code object. However, the actual implementation acceptsbytes-like objects(such asbytes,bytearray, andmemoryview) as well, parsing them internally via the buffer protocol. Because the sentence omits this, users can easily misunderstand that passing bytes is unsupported.Suggested change
Adding "a bytes-like object" makes the documentation accurately reflect the underlying implementation. Changing the subsequent sentence ensures logical consistency for how these types are parsed.
Linked PRs