Skip to content

update: Write certain errors to stderr #1251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions mypy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,10 @@ def report_internal_error(err: Exception, file: str, line: int) -> None:
for s in traceback.format_list(tb + tb2):
print(s.rstrip('\n'))
print('{}: {}'.format(type(err).__name__, err))
print('\n*** INTERNAL ERROR ***')
print('\n*** INTERNAL ERROR ***', file=sys.stderr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue that it is intentional that the traceback is written to stdout but the final two messages are written to stderr. Though I don't feel strongly.

print('\n{}:{}: error: Internal error --'.format(file, line),
'please report a bug at https://github.com/JukkaL/mypy/issues')
print('\nNOTE: you can use "mypy --pdb ..." to drop into the debugger when this happens.')
'please report a bug at https://github.com/JukkaL/mypy/issues',
file=sys.stderr)
print('\nNOTE: you can use "mypy --pdb ..." to drop into the debugger when this happens.',
file=sys.stderr)
sys.exit(1)
2 changes: 1 addition & 1 deletion mypy/lex.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ def ignore_break(self) -> bool:
# Lexically analyze a file and dump the tokens to stdout.
import sys
if len(sys.argv) != 2:
print('Usage: lex.py FILE')
print('Usage: lex.py FILE', file=sys.stderr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You realize this is just a bit of manual test code right? :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gvanrossum I do now but I still feel this deserves to be written to stderr =)

sys.exit(2)
fnam = sys.argv[1]
s = open(fnam, 'rb').read()
Expand Down
2 changes: 1 addition & 1 deletion mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def main(script_path: str) -> None:
raise RuntimeError('unsupported target %d' % options.target)
except CompileError as e:
for m in e.messages:
sys.stdout.write(m + '\n')
sys.stderr.write(m + '\n')
sys.exit(1)


Expand Down
2 changes: 1 addition & 1 deletion mypy/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1978,7 +1978,7 @@ def token_repr(tok: Token) -> str:
import sys

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

args = sys.argv[1:]
Expand Down
2 changes: 1 addition & 1 deletion mypy/stubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def load_python_module_info(module: str, interpreter: str) -> Tuple[str, Optiona
try:
output_bytes = subprocess.check_output(cmd_template % code, shell=True)
except subprocess.CalledProcessError:
print("Can't import module %s" % module)
print("Can't import module %s" % module, file=sys.stderr)
sys.exit(1)
output = output_bytes.decode('ascii').strip().splitlines()
module_path = output[0]
Expand Down