GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||
GeezerVison is showing github.com — gh-122461: Document that compile() and ast.parse() raise SyntaxError for null bytes by devdanzin · Pull Request #122462 · python/cpython Conversation
|
|
Requesting review from @JelleZijlstra. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Thank you both for the reviews! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Note that UnicodeEncodeError (which is a subclass of ValueError) can still be raised if the source string is not encodable.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
There are also mentions of ValueError in the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Yes, for code such as Plus MemoryError and RecursionError are possible for too deeply nested code. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
OverflowError is documented in >>> import ast >>> try: ast.parse('x'*2**31, '?', 'exec') ... except BaseException as err: e = err ... >>> str(e) 'Parser column offset overflow - source line is too big' >>> type(e) <class 'OverflowError'> I do not know whether ValueError other than UnicodeEncodeError can be raised, but it is safer to document ValueError, OverflowError and RecursionError in all these places. I do not think that it is worth to document MemoryError or say KeyboardInterrupt specially, because they depend rather on the environment than on the input and you cannot fix them. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Would this count? >>> ast.parse("", feature_version=(2,2)) Traceback (most recent call last): File "<python-input-2>", line 1, in <module> ast.parse("", feature_version=(2,2)) ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "~\PycharmProjects\cpython\Lib\ast.py", line 50, in parse raise ValueError(f"Unsupported major version: {major}") ValueError: Unsupported major version: 2 Edit: here's another one: >>> ast.parse("", "\0") Traceback (most recent call last): File "<python-input-9>", line 1, in <module> ast.parse("", "\0") ~~~~~~~~~^^^^^^^^^^ File "~\PycharmProjects\cpython\Lib\ast.py", line 53, in parse return compile(source, filename, mode, flags, _feature_version=feature_version, optimize=optimize) ValueError: embedded null character |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…wError and RecursionError.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This PR is stale because it has been open for 30 days with no activity. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This PR is stale because it has been open for 90 days with no activity. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.