7
7
from typing import Tuple , List , TypeVar , Set , Dict , Iterator , Optional
8
8
9
9
from mypy .options import Options
10
+ from mypy .version import __version__ as mypy_version
10
11
11
12
12
13
T = TypeVar ('T' )
@@ -514,40 +515,45 @@ def remove_path_prefix(path: str, prefix: str) -> str:
514
515
515
516
516
517
def report_internal_error (err : Exception , file : str , line : int ,
517
- errors : Errors , options : Options ) -> None :
518
+ errors : Errors = None , options : Options = None ) -> None :
518
519
"""Report internal error and exit.
519
520
520
521
This optionally starts pdb or shows a traceback.
521
522
"""
522
523
# Dump out errors so far, they often provide a clue.
523
524
# But catch unexpected errors rendering them.
524
- try :
525
- for msg in errors .messages ():
526
- print (msg )
527
- except Exception as e :
528
- print ("Failed to dump errors:" , repr (e ), file = sys .stderr )
525
+ if errors :
526
+ try :
527
+ for msg in errors .messages ():
528
+ print (msg )
529
+ except Exception as e :
530
+ print ("Failed to dump errors:" , repr (e ), file = sys .stderr )
529
531
530
532
# Compute file:line prefix for official-looking error messages.
531
533
if line :
532
- prefix = '{}:{}' .format (file , line )
534
+ prefix = '{}:{}: ' .format (file , line )
535
+ elif file :
536
+ prefix = '{}: ' .format (file )
533
537
else :
534
- prefix = file
538
+ prefix = ''
539
+
535
540
536
541
# Print "INTERNAL ERROR" message.
537
- print ('{}: error: INTERNAL ERROR --' .format (prefix ),
542
+ print ('{}error: INTERNAL ERROR --' .format (prefix ),
543
+ 'mypy version: {}' .format (mypy_version ),
538
544
'please report a bug at https://github.com/python/mypy/issues' ,
539
545
file = sys .stderr )
540
546
541
547
# If requested, drop into pdb. This overrides show_tb.
542
- if options .pdb :
548
+ if options and options .pdb :
543
549
print ('Dropping into pdb' , file = sys .stderr )
544
550
import pdb
545
551
pdb .post_mortem (sys .exc_info ()[2 ])
546
552
547
553
# If requested, print traceback, else print note explaining how to get one.
548
- if not options .show_traceback :
554
+ if options and not options .show_traceback :
549
555
if not options .pdb :
550
- print ('{}: note: please use --show-traceback to print a traceback '
556
+ print ('{}note: please use --show-traceback to print a traceback '
551
557
'when reporting a bug' .format (prefix ),
552
558
file = sys .stderr )
553
559
else :
@@ -557,7 +563,7 @@ def report_internal_error(err: Exception, file: str, line: int,
557
563
for s in traceback .format_list (tb + tb2 ):
558
564
print (s .rstrip ('\n ' ))
559
565
print ('{}: {}' .format (type (err ).__name__ , err ))
560
- print ('{}: note: use --pdb to drop into pdb' .format (prefix ), file = sys .stderr )
566
+ print ('{}note: use --pdb to drop into pdb' .format (prefix ), file = sys .stderr )
561
567
562
568
# Exit. The caller has nothing more to say.
563
569
raise SystemExit (1 )
0 commit comments