8000 update: Write certain errors to stderr · python/mypy@a978ec0 · GitHub
[go: up one dir, main page]

Skip to content

Commit a978ec0

Browse files
committed
update: Write certain errors to stderr
* As described and requested in #1202, this commit makes errors on command line syntax and files not found to go to stderr rather than stdout. Signed-off-by: mr.Shu <mr@shu.io>
1 parent ac9f59b commit a978ec0

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
@@ -56,7 +56,7 @@ def main(script_path: str) -> None:
5656
raise RuntimeError('unsupported target %d' % options.target)
5757
except CompileError as e:
5858
for m in e.messages:
59-
sys.stdout.write(m + '\n')
59+
sys.stderr.write(m + '\n')
6060
sys.exit(1)
6161

6262

mypy/parse.py

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

19801980
def usage():
1981-
print('Usage: parse.py [--py2] [--quiet] FILE [...]')
1981+
print('Usage: parse.py [--py2] [--quiet] FILE [...]', file=sys.stderr)
19821982
sys.exit(2)
19831983

19841984
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)
0