Skip to content

Commit a7fe4d8

Browse files
pablogsalPranjal095
authored andcommitted
pythongh-130077: Properly match full soft keywords in the parser (python#135317)
1 parent 019e1f5 commit a7fe4d8

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

Lib/test/test_syntax.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,13 @@
382382
Traceback (most recent call last):
383383
SyntaxError: invalid syntax
384384
385+
# But prefixes of soft keywords should
386+
# still raise specialized errors
387+
388+
>>> (mat x)
389+
Traceback (most recent call last):
390+
SyntaxError: invalid syntax. Perhaps you forgot a comma?
391+
385392
From compiler_complex_args():
386393
387394
>>> def f(None=1):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Properly raise custom syntax errors when incorrect syntax containing names
2+
that are prefixes of soft keywords is encountered. Patch by Pablo Galindo.

Parser/pegen.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,8 @@ expr_ty _PyPegen_soft_keyword_token(Parser *p) {
610610
Py_ssize_t size;
611611
PyBytes_AsStringAndSize(t->bytes, &the_token, &size);
612612
for (char **keyword = p->soft_keywords; *keyword != NULL; keyword++) {
613-
if (strncmp(*keyword, the_token, (size_t)size) == 0) {
613+
if (strlen(*keyword) == (size_t)size &&
614+
strncmp(*keyword, the_token, (size_t)size) == 0) {
614615
return _PyPegen_name_from_token(p, t);
615616
}
616617
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy