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-42218: Check for the error indicator when expecting a new token by isidentical · Pull Request #23058 · python/cpython

Conversation

@isidentical

@isidentical isidentical commented Oct 31, 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/issue42218

Sorry, something went wrong.

Uh oh!

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

All reactions
@isidentical
bpo-42218: Check for the error indicator when expecting a new token
e911f2d
@isidentical
isidentical requested review from lysnikolaou and pablogsal as code owners October 31, 2020 12:06
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Oct 31, 2020
@bedevere-bot bedevere-bot added the awaiting review label Oct 31, 2020
@isidentical
isidentical marked this pull request as draft October 31, 2020 12:07
@Zac-HD Zac-HD mentioned this pull request Oct 31, 2020
New failure on Python3.9 Zac-HD/hypothesmith#12
Closed
@serhiy-storchaka
serhiy-storchaka self-requested a review October 31, 2020 13:07
serhiy-storchaka
serhiy-storchaka reviewed Oct 31, 2020
View reviewed changes
Comment thread Parser/pegen.c
{
Token *t = _PyPegen_expect_token(p, NAME);
if (t == NULL) {
if (t == NULL || p->error_indicator) {

@serhiy-storchaka serhiy-storchaka Oct 31, 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.

How can _PyPegen_expect_token() return non-NULL if error is set?

Either _PyPegen_name_token() is called when error is set (it should not, it should be checked earlier), or the problem is in _PyPegen_fill_token().

Add assert(!PyErr_Occurred()) at the top of _PyPegen_expect_token() and if it does not crash, search bug in _PyPegen_fill_token().

Sorry, something went wrong.

Uh oh!

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

All reactions

@isidentical isidentical Oct 31, 2020 •
edited
Loading

Uh oh!

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

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.

How can _PyPegen_expect_token() return non-NULL if error is set?

As far as I understand, _PyPegen_expect_token returns NULL on 2 different cases. If there is an error, it returns NULL and if the given type is not matched (e.g: NAME given but NUMBER is the next token) it also returns NULL. But on the latter, it returns NULL without setting an error. So when parser is trying alternatives and backtracking, it assumes it got a different type of token and continues.

One thing that I thought was adding

    if (p->error_indicator) {
        return NULL;
    }

at the begging of _PyPegen_expect_token but I failed to find another case where the error didn't propagate except the one that author suggested so this might be enough.

Sorry, something went wrong.

Uh oh!

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

All reactions
serhiy-storchaka
serhiy-storchaka reviewed Oct 31, 2020
View reviewed changes
Comment thread Lib/test/test_syntax.py
self._check_error(code, "invalid syntax")

def test_unexpected_line_continuation(self):
self._check_error('A.\u018a\\ ', "unexpected character after line continuation character")

@serhiy-storchaka serhiy-storchaka Oct 31, 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 would test two cases: \\\n and \\ followed by non-\n character. They are two slightly different errors.

Instead \u018a you can use any non-ascii character.

Sorry, something went wrong.

Uh oh!

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

All reactions
@lysnikolaou

lysnikolaou commented Oct 31, 2020

Copy link
Copy Markdown
Member

I think that this is too specialized a fix for this specific situation. I've investigated a bit more in depth and I think I found a problem there is with left-recursive rules, not handling p->error_indicator correctly. I've got a patch ready. @isidentical Would it be okay to close this PR?

All reactions

Sorry, something went wrong.

Uh oh!

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

@isidentical

isidentical commented Oct 31, 2020

Copy link
Copy Markdown
Member Author

Sure!

All reactions

Sorry, something went wrong.

Uh oh!

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

@isidentical isidentical closed this Oct 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@serhiy-storchaka serhiy-storchaka serhiy-storchaka left review comments
@lysnikolaou lysnikolaou Awaiting requested review from lysnikolaou
@pablogsal pablogsal Awaiting requested review from pablogsal

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.

5 participants

@isidentical @lysnikolaou @serhiy-storchaka @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.