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 — bpo-39159: Declare errors that might be raised from literal_eval by isidentical · Pull Request #19899 · python/cpython

Conversation

@isidentical

@isidentical isidentical commented May 4, 2020 •
edited by bedevere-bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

https://bugs.python.org/issue39159

Sorry, something went wrong.

Uh oh!

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

All reactions
@isidentical
bpo-39159: Declare error that might be raised from literal_eval
97d12b1
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label May 4, 2020
@bedevere-bot bedevere-bot added docs Documentation in the Doc dir awaiting review labels May 4, 2020
@isidentical isidentical added the skip news label May 4, 2020
@isidentical isidentical changed the title bpo-39159: Declare error that might be raised from literal_eval bpo-39159: Declare errors that might be raised from literal_eval May 4, 2020
@isidentical
isidentical requested a review from rhettinger May 4, 2020 18:24
rhettinger
rhettinger reviewed May 5, 2020
View reviewed changes
Comment thread Doc/library/ast.rst
container display. The string or node provided may only consist of the
following Python literal structures: strings, bytes, numbers, tuples, lists,
dicts, sets, booleans, and ``None``.
dicts, sets, booleans, ``None`` and ``Ellipsis``.

@rhettinger rhettinger May 5, 2020

Copy link
Copy Markdown
Contributor

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.

Let's also take this opportunity to be more specific about what is meant by "numbers". Replace that with "ints, floats, complex numbers".

Also, please make the same update to the docstring for ast.literal_eval().

Sorry, something went wrong.

Uh oh!

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

All reactions
rhettinger
rhettinger reviewed May 5, 2020
View reviewed changes
Comment thread Doc/library/ast.rst
It can raise :exc:`ValueError`, :exc:`TypeError`, :exc:`SyntaxError`,
:exc:`MemoryError` and :exc:`RecursionError` depending on the malformed
input.

@rhettinger rhettinger May 5, 2020

Copy link
Copy Markdown
Contributor

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.

Just for my edification and for future reference, can you add a non-displayed in-line documentation comment showing an example of how each of these could happen.

Sorry, something went wrong.

Uh oh!

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

All reactions

@isidentical isidentical May 5, 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.

import ast

recursion_tuple = ast.Tuple(elts=[], ctx=ast.Load())
recursion_tuple.elts.append(recursion_tuple)
INPUTS = [
    ("invalid syntax", SyntaxError),
    ("test", ValueError),
    (ast.List(elts=None, ctx=ast.Load()), TypeError),
    (recursion_tuple, RecursionError),
]

for inp, exc_type in INPUTS:
    try:
        ast.literal_eval(inp)
    except exc_type:
        continue
    else:
        assert False

does something like this suits?

Sorry, something went wrong.

Uh oh!

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

All reactions

@isidentical isidentical May 7, 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.

@rhettinger or maybe we can put this in an actual test in test_ast and refer it? How does that sounds?

Sorry, something went wrong.

Uh oh!

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

All reactions
@taleinat

taleinat commented Oct 18, 2020

Copy link
Copy Markdown
Contributor

Ping, @rhettinger?

All reactions

Sorry, something went wrong.

Uh oh!

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

@rhettinger

rhettinger commented Dec 21, 2020

Copy link
Copy Markdown
Contributor

Triggering a rebuild.

All reactions

Sorry, something went wrong.

Uh oh!

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

@rhettinger rhettinger closed this Dec 21, 2020
@rhettinger rhettinger reopened this Dec 21, 2020
@rhettinger
rhettinger merged commit fbc7723 into python:master Dec 22, 2020
@bedevere-bot bedevere-bot removed the awaiting review label Dec 22, 2020
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 13, 2021
@isidentical @adorilson
bpo-39159: Declare error that might be raised from literal_eval (pyth…
e93e423
…onGH-19899)
@rhettinger rhettinger mentioned this pull request Apr 14, 2022
Ideas for making ast.literal_eval() usable #83340
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@rhettinger rhettinger rhettinger left review comments

Uh oh!

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

Assignees

No one assigned

Labels

docs Documentation in the Doc dir skip news

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.

5 participants

@isidentical @taleinat @rhettinger @the-knights-who-say-ni @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.