{{ message }}
Repository navigation
Conversation
compile() resolved mode with getParserInputType only inside the string compile path, after sourceAsString had converted the source and checkSource had looked for null bytes, and checked that func_type comes with PyCF_ONLY_AST later still. So compile(None, 'f', 'x') raised TypeError, a source with a null byte or bytes that fail to decode raised SyntaxError, and an AST source with mode 'func_type' but no PyCF_ONLY_AST reached obj2sst and hit ShouldNotReachHere. CPython reports all of these as ValueError. CPython's builtin_compile_impl validates mode, including the func_type flag requirement, right after the flags and optimize checks and before it touches the source. getParserInputType now does the func_type check, generic resolves the input type at that point and reuses it for the AST path, and compile() resolves it before checkSource. Signed-off-by: Jeongseop Lim <jeongseop_lim@korea.ac.kr>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
Fixes #1224
compile()readmodeonly after converting and checking the source, so an invalid source hid an invalid mode. Thefunc_typemode'sPyCF_ONLY_ASTrequirement was checked later still, so an AST source with that mode and no flag reachedobj2sstand failed withShouldNotReachHere. CPython'sbuiltin_compile_impldispatches onmoderight after the flags and optimize checks (bltinmodule.c#L776-L798), before it converts the source (#L826).AS-IS
TO-BE
(matching CPython)
Changes
CompileNode.generic, resolve the input type withgetParserInputTyperight aftercheckOptimizeand reuse it for the AST path.CompileNode.compile, callgetParserInputTypebeforecheckSource, which covers astrsource that arrives throughdoCompile.func_typerequiresPyCF_ONLY_ASTcheck fromcompileintogetParserInputType, so both paths raise it with the other mode errors.test_compile_checks_mode_before_sourcetotests/test_parser.py, with the file's firstassert_raiseshelper.Testing
mx python-jvmon linux-aarch64, thenmx graalpytest test_parser.py test_exec.py test_ast.py test_code.py(108 passed).test.test_compile,test.test_builtinandtest.test_astfromlib-pythonreport the same failures and errors as on master. The new test fails on the unpatched build. Twentycompile()call shapes, including validexec,eval,singleandfunc_typecompiles, AST sources, andfunc_typewithout the flag, print the same as CPython 3.12.13 exceptcompile(None, 'f', 'x', optimize=5), which raisesTypeErrorinstead ofValueErrorbefore and after this change.