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-99891: Fix infinite recursion in the tokenizer when showing warnings by pablogsal · Pull Request #99893 · python/cpython

gh-99891: Fix infinite recursion in the tokenizer when showing warnings #99893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
miss-islington merged 1 commit into python:main from pablogsal:gh-99891
Nov 30, 2022

Uh oh!

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

Merged

gh-99891: Fix infinite recursion in the tokenizer when showing warnings #99893

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
3e41198
gh-99891: Fix infinite recursion in the tokenizer when showing warnings
pablogsal Nov 30, 2022
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

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

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

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

Diff view
Diff view

There are no files selected for viewing

12 changes: 12 additions & 0 deletions 12 Lib/test/test_source_encoding.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ def test_file_parse_error_multiline(self):
finally:
os.unlink(TESTFN)

def test_tokenizer_fstring_warning_in_first_line(self):
source = "0b1and 2"
with open(TESTFN, "w") as fd:
fd.write("{}".format(source))
try:
retcode, stdout, stderr = script_helper.assert_python_ok(TESTFN)
self.assertIn(b"SyntaxWarning: invalid binary litera", stderr)
self.assertEqual(stderr.count(source.encode()), 1)
finally:
os.unlink(TESTFN)


class AbstractSourceEncodingTest:

def test_default_coding(self):
Expand Down
3 changes: 3 additions & 0 deletions 3 Misc/NEWS.d/next/Core and Builtins/2022-11-30-11-09-40.gh-issue-99891.9VomwB.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a bug in the tokenizer that could cause infinite recursion when showing
syntax warnings that happen in the first line of the source. Patch by Pablo
Galindo
8 changes: 8 additions & 0 deletions 8 Parser/tokenizer.c
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ tok_new(void)
tok->async_def_nl = 0;
tok->interactive_underflow = IUNDERFLOW_NORMAL;
tok->str = NULL;
tok->report_warnings = 1;
#ifdef Py_DEBUG
tok->debug = _Py_GetConfig()->parser_debug;
#endif
Expand Down Expand Up @@ -1201,6 +1202,10 @@ indenterror(struct tok_state *tok)
static int
parser_warn(struct tok_state *tok, PyObject *category, const char *format, ...)
{
if (!tok->report_warnings) {
return 0;
}

PyObject *errmsg;
va_list vargs;
va_start(vargs, format);
Expand Down Expand Up @@ -2239,6 +2244,9 @@ _PyTokenizer_FindEncodingFilename(int fd, PyObject *filename)
}
}
struct token token;
// We don't want to report warnings here because it could cause infinite recursion
// if fetching the encoding shows a warning.
tok->report_warnings = 0;
while (tok->lineno < 2 && tok->done == E_OK) {
_PyTokenizer_Get(tok, &token);
}
Expand Down
1 change: 1 addition & 0 deletions 1 Parser/tokenizer.h
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ struct tok_state {
NEWLINE token after it. */
/* How to proceed when asked for a new token in interactive mode */
enum interactive_underflow_t interactive_underflow;
int report_warnings;
#ifdef Py_DEBUG
int debug;
#endif
Expand Down
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.