mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	decrement offset when it points to a newline (#10186 followup)
This commit is contained in:
		
							parent
							
								
									47ce965562
								
							
						
					
					
						commit
						a95e977e41
					
				
					 2 changed files with 7 additions and 1 deletions
				
			
		| 
						 | 
					@ -295,6 +295,10 @@ def e():
 | 
				
			||||||
            raise SyntaxError('', ('', 0, 5, 'hello'))
 | 
					            raise SyntaxError('', ('', 0, 5, 'hello'))
 | 
				
			||||||
        msg = self.get_report(e).splitlines()
 | 
					        msg = self.get_report(e).splitlines()
 | 
				
			||||||
        self.assertEqual(msg[-2], "        ^")
 | 
					        self.assertEqual(msg[-2], "        ^")
 | 
				
			||||||
 | 
					        def e():
 | 
				
			||||||
 | 
					            exec("x = 5 | 4 |")
 | 
				
			||||||
 | 
					        msg = self.get_report(e).splitlines()
 | 
				
			||||||
 | 
					        self.assertEqual(msg[-2], '              ^')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PyExcReportingTests(BaseExceptionReportingTests, unittest.TestCase):
 | 
					class PyExcReportingTests(BaseExceptionReportingTests, unittest.TestCase):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1344,6 +1344,8 @@ print_error_text(PyObject *f, int offset, const char *text)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    char *nl;
 | 
					    char *nl;
 | 
				
			||||||
    if (offset >= 0) {
 | 
					    if (offset >= 0) {
 | 
				
			||||||
 | 
					        if (offset > 0 && offset == strlen(text) && text[offset - 1] == '\n')
 | 
				
			||||||
 | 
					            offset--;
 | 
				
			||||||
        for (;;) {
 | 
					        for (;;) {
 | 
				
			||||||
            nl = strchr(text, '\n');
 | 
					            nl = strchr(text, '\n');
 | 
				
			||||||
            if (nl == NULL || nl-text >= offset)
 | 
					            if (nl == NULL || nl-text >= offset)
 | 
				
			||||||
| 
						 | 
					@ -1363,7 +1365,7 @@ print_error_text(PyObject *f, int offset, const char *text)
 | 
				
			||||||
    if (offset == -1)
 | 
					    if (offset == -1)
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    PyFile_WriteString("    ", f);
 | 
					    PyFile_WriteString("    ", f);
 | 
				
			||||||
    while (--offset)
 | 
					    while (--offset > 0)
 | 
				
			||||||
        PyFile_WriteString(" ", f);
 | 
					        PyFile_WriteString(" ", f);
 | 
				
			||||||
    PyFile_WriteString("^\n", f);
 | 
					    PyFile_WriteString("^\n", f);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue