Skip to content

Commit 0ec0cb4

Browse files
committed
Merge pull request #1251 from mrshu/mrshu/errors-to-stderr
update: Write certain errors to stderr
2 parents 5cd8319 + a978ec0 commit 0ec0cb4

File tree

5 files changed

+9
-7
lines changed

5 files changed

+9
-7
lines changed

mypy/errors.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,10 @@ def report_internal_error(err: Exception, file: str, line: int) -> None:
374374
for s in traceback.format_list(tb + tb2):
375375
print(s.rstrip('\n'))
376376
print('{}: {}'.format(type(err).__name__, err))
377-
print('\n*** INTERNAL ERROR ***')
377+
print('\n*** INTERNAL ERROR ***', file=sys.stderr)
378378
print('\n{}:{}: error: Internal error --'.format(file, line),
379-
'please report a bug at https://github.com/JukkaL/mypy/issues')
380-
print('\nNOTE: you can use "mypy --pdb ..." to drop into the debugger when this happens.')
379+
'please report a bug at https://github.com/JukkaL/mypy/issues',
380+
file=sys.stderr)
381+
print('\nNOTE: you can use "mypy --pdb ..." to drop into the debugger when this happens.',
382+
file=sys.stderr)
381383
sys.exit(1)

mypy/lex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ def ignore_break(self) -> bool:
880880
# Lexically analyze a file and dump the tokens to stdout.
881881
import sys
882882
if len(sys.argv) != 2:
883-
print('Usage: lex.py FILE')
883+
print('Usage: lex.py FILE', file=sys.stderr)
884884
sys.exit(2)
885885
fnam = sys.argv[1]
886886
s = open(fnam, 'rb').read()

mypy/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def main(script_path: str) -> None:
5252
raise RuntimeError('unsupported target %d' % options.target)
5353
except CompileError as e:
5454
for m in e.messages:
55-
sys.stdout.write(m + '\n')
55+
sys.stderr.write(m + '\n')
5656
sys.exit(1)
5757

5858

mypy/parse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1990,7 +1990,7 @@ def token_repr(tok: Token) -> str:
19901990
import sys
19911991

19921992
def usage():
1993-
print('Usage: parse.py [--py2] [--quiet] FILE [...]')
1993+
print('Usage: parse.py [--py2] [--quiet] FILE [...]', file=sys.stderr)
19941994
sys.exit(2)
19951995

19961996
args = sys.argv[1:]

mypy/stubgen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def load_python_module_info(module: str, interpreter: str) -> Tuple[str, Optiona
148148
try:
149149
output_bytes = subprocess.check_output(cmd_template % code, shell=True)
150150
except subprocess.CalledProcessError:
151-
print("Can't import module %s" % module)
151+
print("Can't import module %s" % module, file=sys.stderr)
152152
sys.exit(1)
153153
output = output_bytes.decode('ascii').strip().splitlines()
154154
module_path = output[0]

0 commit comments

Comments
 (0)