Skip to content

Commit c2e20b6

Browse files
committed
gh-159672: Fix keyword diagnostics across build environments
1 parent 739c85e commit c2e20b6

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

‎Lib/test/test_traceback.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1962,6 +1962,7 @@ def test_keyword_hint_in_interactive_interpreter(self):
19621962
self.assertIn("Did you mean 'import'", output.getvalue())
19631963

19641964
@requires_subprocess()
1965+
@force_not_colorized
19651966
def test_keyword_hint_does_not_reopen_source(self):
19661967
with tempfile.TemporaryDirectory() as script_dir:
19671968
make_script(script_dir, "sitecustomize", textwrap.dedent('''
@@ -1981,7 +1982,8 @@ def audit(event, args):
19811982
if keyword is not None:
19821983
self.assertIn(f"Did you mean '{keyword}'".encode(), error)
19831984
if keyword == "and":
1984-
self.assertIn(b"line 1\n result = (one\n", error)
1985+
self.assertIn(b"line 1\n result = (one\n",
1986+
error.replace(b"\r\n", b"\n"))
19851987
self.assertGreater(counts[0], 0)
19861988
self.assertEqual(counts, [counts[0]] * len(cases))
19871989

‎Parser/pegen.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,11 @@ typedef struct {
10861086
int is_alias;
10871087
} KeywordTypo;
10881088

1089+
typedef struct {
1090+
const char * const name;
1091+
const char * const keyword;
1092+
} KeywordAlias;
1093+
10891094
#define MAX_KEYWORD_TYPO_CANDIDATES 32
10901095
#define MAX_KEYWORD_TYPO_STEPS 5000000
10911096

@@ -1303,10 +1308,7 @@ collect_keyword_typos(Parser *p, PySyntaxErrorObject *error, KeywordTypo *candid
13031308
start = i + 1;
13041309
}
13051310
}
1306-
static const struct {
1307-
const char *name;
1308-
const char *keyword;
1309-
} aliases[] = {
1311+
static const KeywordAlias aliases[] = {
13101312
{"switch", "match"},
13111313
{"delete", "del"},
13121314
{"function", "def"},

0 commit comments

Comments
 (0)