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 — bpo-32888: Improve exception message in ast.literal_eval by Rosuav · Pull Request #340 · python/cpython Conversation
| |||||||||||||||||||||||||||||||||||||||||||||||
|
This looks good, do you mind opening a bugs.python.org ticket and adding a news entry? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
When a non-literal is given to literal_eval, attempt to be more helpful with the message, rather than calling it 'malformed'.
b9b6e9d to
26ba98e
Compare
|
Rebased onto current master, which includes shifting where the actual change happens. NEWS entry added, issue number added. |
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.
Please add a special test in test_ast.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return node.n | ||
| elif isinstance(node, AST): | ||
| raise ValueError('%s not allowed in literal' % type(node).__name__) | ||
| raise ValueError('malformed node or string: ' + repr(node)) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
In what cases this exception is raised? Is it covered by tests?
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.
The easiest way to trigger it is to use something that isn't permitted in literal_eval, but is valid syntax. There's already one such test - proving that f-strings aren't literal_evallable - and I guess there could be more, but since this is a whitelist, the error is basically "anything else, raise". The only difference in this patch is that the message is different for "syntactically valid but not acceptable by literal_eval" and "syntactically invalid".
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.
I meant what input triggers the "malformed node or string" error now?
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.
Calling literal_eval with an AST node that has non-AST children in it. I don't think it's possible (post-patch) to trigger this error by calling literal_eval with a string, but I can't say for sure, so I don't want to say just "malformed node".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -0,0 +1,2 @@ | |||
| Improve wording of error messages from ast.literal_eval, distinguishing | |||
| valid-but-unacceptable nodes from those that are actually malformed. | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Please add "Patch by..."
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.
Should that be done by amending the current commit, or adding an additional commit?
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.
It is better for review to add a new commit. In any case all commits are squashed before merging into the repository.
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.
👍
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.
Overall this looks good, just one suggestion on the test implementation.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| ast.BinOp(ast.Num(1), ast.Add(), 'oops'): "malformed node or string: 'oops'", | ||
| } | ||
| for test, message in tests.items(): | ||
| with self.assertRaises(ValueError) as cm: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
A helpful thing to use in between lines 594 and 595 would be with self.subTest(test=test, message=message): and then indent the parts below it. That way each of these end up being tested independently rather than potentially having the items loop have a case fail and cause the rest of the cases to fail to execute.
Check out https://docs.python.org/3/library/unittest.html#distinguishing-test-iterations-using-subtests
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@Rosuav, please address the last change request by @briancurtin and also rebase to fix the conflict. Thanks! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
BPO cites another couple of issues, one of which is still open, as dependencies. And it's not really a high priority - it's nothing more than a nice-to-have. There are a lot of barriers to getting patches accepted and it's often not worth the effort unless you REALLY care about the patch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
(Note that you can rebase or do a regular merge, which is often easier! All PRs are squash merged in the end @csabella) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@serhiy-storchaka Should this wait for bpo-32893 per your last message on the ticket or could it be merged soon? (when conflicts are resolved + suggestion from Brian) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
A different approach using ast.dump(): PR #16620. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
What's the status of this PR? @Rosuav: Are you still working on this?
Oh, I just closed it since it could produce very long error message: https://bugs.python.org/issue38396#msg354132 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
No, I'm not. It was a nice-to-have but between the pushback (no core dev seemed to want it to happen) and the constant need to fix merge conflicts meant that I abandoned this proposal ages ago. If someone else wants to champion this fix, then sure, but I don't have the energy to push everything, and this one wasn't worth it. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@isidentical: Are you interested to take over this change? I'm not the good candidate to review it. Maybe @pablogsal or @serhiy-storchaka. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sure. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Closing this pull request as it is now GH-17662. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Bumps [celery](https://github.com/celery/celery) from 4.4.3 to 4.4.4. - [Release notes](https://github.com/celery/celery/releases) - [Changelog](https://github.com/celery/celery/blob/master/Changelog.rst) - [Commits](celery/celery@4.4.3...v4.4.4) Signed-off-by: dependabot-preview[bot] <[email protected]> Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
v2.1.1 single-rule extension to A10 per supervisor 01:05:42Z 2026-05-12 + pythia python#341 independent-push-window observation. Authored under structural escalation from pythia python#335(c) (POST-A10 empirical class- repeat trigger): 7th feedback_fabrication_detector_verify instance (supervisor self at 22:36Z) was the 1st POST-A10-codification instance. A10.1: when issuing CONFIRMED-FABRICATION verdict (per A10 trigger), verdict post MUST inline (a) verbatim git command output snippet supporting the accusation, (b) explicit HEAD-at-claim disambiguation distinguishing claim-time HEAD from current HEAD when they differ. Closes the python#340(2) grep-scope-mismatch gap that produced both POST-A10 incidents (librarian 21:26Z + supervisor 22:36Z self-violation). Explicit non-coverage: routine verification claims (gate posts, state reports, ABBA results, build-status, push-verify) remain governed by feedback_no_tool_execution_citation (Alex 2026-04-29 directive). A10.1 verbatim-snippet requirement is FABRICATION-VERDICT-CLASS-ONLY, not generic. The two rules coexist via claim-class distinction. Adoption record updated to note v2.1.1 amendment on top of v2.1 352cc1f.
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.