Docs: missing mention of bytes-like object in eval/exec() documentation
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
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
- gh-148943
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open Doc/library/functions.rst and locate the exec() documentation describing the source parameter. Compare the wording with the supported string, bytes-like object, and code object cases stated in the issue. Done means the documentation accurately mentions bytes-like objects and explains that strings and bytes-like objects are parsed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100