@@ -376,6 +376,30 @@ def f():
376376 ' ValueError: 0\n ' ,
377377 ])
378378
379+ def test_format_exception_group_syntax_error_with_custom_values (self ):
380+ # See https://github.com/python/cpython/issues/128894
381+ for exc in [
382+ SyntaxError ('error' , 'abcd' ),
383+ SyntaxError ('error' , [None ] * 4 ),
384+ SyntaxError ('error' , (1 , 2 , 3 , 4 )),
385+ SyntaxError ('error' , (1 , 2 , 3 , 4 )),
386+ SyntaxError ('error' , (1 , 'a' , 'b' , 2 )),
387+ # with end_lineno and end_offset:
388+ SyntaxError ('error' , 'abcdef' ),
389+ SyntaxError ('error' , [None ] * 6 ),
390+ SyntaxError ('error' , (1 , 2 , 3 , 4 , 5 , 6 )),
391+ SyntaxError ('error' , (1 , 'a' , 'b' , 2 , 'c' , 'd' )),
392+ ]:
393+ with self .subTest (exc = exc ):
394+ err = traceback .format_exception_only (exc , show_group = True )
395+ # Should not raise an exception:
396+ if exc .lineno is not None :
397+ self .assertEqual (len (err ), 2 )
398+ self .assertTrue (err [0 ].startswith (' File' ))
399+ else :
400+ self .assertEqual (len (err ), 1 )
401+ self .assertEqual (err [- 1 ], 'SyntaxError: error\n ' )
402+
379403 @requires_subprocess ()
380404 @force_not_colorized
381405 def test_encoded_file (self ):
0 commit comments