mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	[3.14] gh-130077: Properly match full soft keywords in the parser (GH-135317) (#135348)
gh-130077: Properly match full soft keywords in the parser (GH-135317)
(cherry picked from commit ff2b5f40c2)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
			
			
This commit is contained in:
		
							parent
							
								
									4b96a34978
								
							
						
					
					
						commit
						77c4b5d413
					
				
					 3 changed files with 11 additions and 1 deletions
				
			
		| 
						 | 
					@ -382,6 +382,13 @@
 | 
				
			||||||
Traceback (most recent call last):
 | 
					Traceback (most recent call last):
 | 
				
			||||||
SyntaxError: invalid syntax
 | 
					SyntaxError: invalid syntax
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# But prefixes of soft keywords should
 | 
				
			||||||
 | 
					# still raise specialized errors
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					>>> (mat x)
 | 
				
			||||||
 | 
					Traceback (most recent call last):
 | 
				
			||||||
 | 
					SyntaxError: invalid syntax. Perhaps you forgot a comma?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
From compiler_complex_args():
 | 
					From compiler_complex_args():
 | 
				
			||||||
 | 
					
 | 
				
			||||||
>>> def f(None=1):
 | 
					>>> def f(None=1):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,2 @@
 | 
				
			||||||
 | 
					Properly raise custom syntax errors when incorrect syntax containing names
 | 
				
			||||||
 | 
					that are prefixes of soft keywords is encountered.  Patch by Pablo Galindo.
 | 
				
			||||||
| 
						 | 
					@ -610,7 +610,8 @@ expr_ty _PyPegen_soft_keyword_token(Parser *p) {
 | 
				
			||||||
    Py_ssize_t size;
 | 
					    Py_ssize_t size;
 | 
				
			||||||
    PyBytes_AsStringAndSize(t->bytes, &the_token, &size);
 | 
					    PyBytes_AsStringAndSize(t->bytes, &the_token, &size);
 | 
				
			||||||
    for (char **keyword = p->soft_keywords; *keyword != NULL; keyword++) {
 | 
					    for (char **keyword = p->soft_keywords; *keyword != NULL; keyword++) {
 | 
				
			||||||
        if (strncmp(*keyword, the_token, (size_t)size) == 0) {
 | 
					        if (strlen(*keyword) == (size_t)size &&
 | 
				
			||||||
 | 
					            strncmp(*keyword, the_token, (size_t)size) == 0) {
 | 
				
			||||||
            return _PyPegen_name_from_token(p, t);
 | 
					            return _PyPegen_name_from_token(p, t);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue