GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-77069: add context info to ast.literal_eval error messages by isidentical · Pull Request #17662 · python/cpython

Conversation

@isidentical

@isidentical isidentical commented Dec 19, 2019 •
edited by serhiy-storchaka
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Based on changes from #340.

https://bugs.python.org/issue32888

  • Issue: Improve exception message in ast.literal_eval #77069

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Dec 19, 2019
@bedevere-bot bedevere-bot added the awaiting review label Dec 19, 2019
@csabella csabella mentioned this pull request Jan 12, 2020
bpo-32888: Improve exception message in ast.literal_eval #340
Closed
merwok
merwok reviewed Jan 12, 2020
View reviewed changes
Comment thread Lib/test/test_fstring.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@isidentical
isidentical force-pushed the bpo-32888 branch from 4a0b97c to 29324a5 Compare April 12, 2020 19:21
@isidentical
isidentical requested a review from serhiy-storchaka April 14, 2020 16:01
@isidentical
isidentical force-pushed the bpo-32888 branch from 29324a5 to 5dc90fe Compare May 13, 2020 21:47
@isidentical isidentical changed the title bpo-32888: improve wording for ast.literal_eval error messages bpo-32888: enhance ast.literal_eval error messagess with context information May 13, 2020
@isidentical
bpo-32888: enhance error messages for ast.literal_eval with context i…
14c5c02
…nformation
@isidentical
isidentical force-pushed the bpo-32888 branch from 5dc90fe to 14c5c02 Compare May 15, 2020 00:17
iritkatriel
iritkatriel reviewed Aug 22, 2020
View reviewed changes
Comment thread Lib/ast.py
def _convert_num(node):
def _raise_malformed_node(node, context = None):
message = "malformed node or string"
if context is not None and isinstance(node, AST):

@iritkatriel iritkatriel Aug 22, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it necessary to check here that node is an AST and not just that context is not None?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iritkatriel iritkatriel Aug 22, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if 'context' is overloaded. Maybe it's better not to add it here to the string passed in, and let the context arg be complete, like "literal expression" or "unary expression arg".

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@isidentical isidentical Aug 27, 2020

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it necessary to check here that node is an AST and not just that context is not None?

For malformed nodes (manually constructed), it might not be an AST type, example (already presented in tests);

            ast.BinOp(
                ast.Constant(1), ast.Add(), "oops"
            ): "malformed node or string: 'oops'",

I wonder if 'context' is overloaded. Maybe it's better not to add it here to the string passed in, and let the context arg be complete, like "literal expression" or "unary expression arg".

I am not a native speaker, but from the point of messages, it satisfies the expectations and gives the precise location. (+a => ValueError: malformed node or string in binary operation context: <ast.Name object at 0x7f02f058d5f0>). What would you prefer instead of the message above? By the way thanks for your bump on this old PR! I completely forgot it existed since there was no activity :)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iritkatriel iritkatriel Aug 27, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I see about the first point.
  • On the wording - would it work to simply have "malformed binary operation" in this case?
  • My pleasure 👍

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ezio-melotti ezio-melotti removed the CLA signed label Jul 13, 2022
@github-actions

github-actions Bot commented Apr 7, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 7, 2026
@merwok merwok changed the title bpo-32888: enhance ast.literal_eval error messagess with context information bpo-32888: add context info to ast.literal_eval error messages Apr 7, 2026
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label May 10, 2026
@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Aug 11, 2026
@serhiy-storchaka serhiy-storchaka changed the title bpo-32888: add context info to ast.literal_eval error messages gh-77069: add context info to ast.literal_eval error messages Aug 12, 2026
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Aug 14, 2026
@ambv

ambv commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

This PR has not been touched by a human in more than 5 years. Closing to cull the number of open pull requests. Do not reopen this pull request without getting a go-ahead from a triager or core developer on the related issue.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ambv ambv closed this Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@merwok merwok merwok left review comments
@iritkatriel iritkatriel iritkatriel left review comments
@serhiy-storchaka serhiy-storchaka Awaiting requested review from serhiy-storchaka

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@isidentical @ambv @merwok @iritkatriel @the-knights-who-say-ni @ezio-melotti @bedevere-bot
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.