33from tokenize import (tokenize , untokenize , NUMBER , NAME , OP ,
44 STRING , ENDMARKER , ENCODING , tok_name , detect_encoding ,
55 open as tokenize_open , Untokenizer , generate_tokens ,
6- NEWLINE , _generate_tokens_from_c_tokenizer , DEDENT , TokenInfo )
6+ NEWLINE , _generate_tokens_from_c_tokenizer , DEDENT , TokenInfo ,
7+ TokenError )
78from io import BytesIO , StringIO
89import unittest
910from textwrap import dedent
@@ -286,7 +287,7 @@ def number_token(s):
286287 for lit in INVALID_UNDERSCORE_LITERALS :
287288 try :
288289 number_token (lit )
289- except SyntaxError :
290+ except TokenError :
290291 continue
291292 self .assertNotEqual (number_token (lit ), lit )
292293
@@ -1379,7 +1380,7 @@ def test_latin1_normalization(self):
13791380 self .assertEqual (found , "iso-8859-1" )
13801381
13811382 def test_syntaxerror_latin1 (self ):
1382- # Issue 14629: need to raise SyntaxError if the first
1383+ # Issue 14629: need to raise TokenError if the first
13831384 # line(s) have non-UTF-8 characters
13841385 lines = (
13851386 b'print("\xdf ")' , # Latin-1: LATIN SMALL LETTER SHARP S
@@ -2754,7 +2755,7 @@ def get_tokens(string):
27542755 "]" ,
27552756 ]:
27562757 with self .subTest (case = case ):
2757- self .assertRaises (SyntaxError , get_tokens , case )
2758+ self .assertRaises (TokenError , get_tokens , case )
27582759
27592760 def test_max_indent (self ):
27602761 MAXINDENT = 100
@@ -2773,7 +2774,7 @@ def generate_source(indents):
27732774
27742775 invalid = generate_source (MAXINDENT )
27752776 the_input = StringIO (invalid )
2776- self .assertRaises (SyntaxError , lambda : list (_generate_tokens_from_c_tokenizer (the_input .readline )))
2777+ self .assertRaises (IndentationError , lambda : list (_generate_tokens_from_c_tokenizer (the_input .readline )))
27772778 self .assertRaises (
27782779 IndentationError , compile , invalid , "<string>" , "exec"
27792780 )
0 commit comments