FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-141778: add missing validation in ast.literal_eval() for non-string input by skirpichev · Pull Request #142969 · python/cpython · GitHub

Repository navigation

gh-141778: add missing validation in ast.literal_eval() for non-string input - #142969

Closed
skirpichev wants to merge 12 commits into
python:mainfrom
skirpichev:validation-of-Constants/141778
Closed

skirpichev wants to merge 12 commits into
python:mainfrom
skirpichev:validation-of-Constants/141778

Conversation

skirpichev commented Dec 19, 2025 •
edited
Loading

Copy link
Copy Markdown
Member

Also support sentinel in the literal_eval().

This also changes parsing of the private __text_signature__ attribute by inspect.signature(). Now we accept here only types, valid for ast.Constant().

The signature of _thread.interrupt_main() was marked as unsupported. I think it's a reasonable regression. Previously it was rendered with 2 as default. I think we should rather preserve repr for int's subclasses, like pure-Python methods do. See also #61005.

…-string input

This also changes parsing of the private `__text_signature__` attribute
by inspect.signature().  Now we accept here only types, valid for
ast.Constant().
Comment thread Lib/ast.py
_type_Ellipsis = type(...)


def _convert_literal(node, omit_validation=False):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Why do we need this change? It may make life harder for some users.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Could you be more precise, any example?

We need this, because literal_eval() accepts invalid AST for non-string input. Per documentation:

The string or node provided may only consist of the following Python literal structures: strings, bytes, numbers, tuples, lists, dicts, sets, booleans, None and Ellipsis.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Based on case from stdlib (_signature_fromstr()), I think that possible cases of using this undocumented feature are rare, if exist at all.

Though, we can properly deprecate old behavior for extra safety.

skirpichev closed this Dec 25, 2025
skirpichev deleted the validation-of-Constants/141778 branch December 25, 2025 21:29
skirpichev restored the validation-of-Constants/141778 branch May 23, 2026 08:18
skirpichev reopened this May 23, 2026
skirpichev marked this pull request as draft May 23, 2026 08:18
skirpichev self-assigned this May 23, 2026

Copy link
Copy Markdown

skirpichev marked this pull request as ready for review August 18, 2026 06:35

Copy link
Copy Markdown
Member Author

I can split out sentinel support to a separate pr.

skirpichev closed this Aug 18, 2026
skirpichev deleted the validation-of-Constants/141778 branch August 18, 2026 07:01
skirpichev removed their assignment Sep 9, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL