Skip to content

Remove weird implementation of --show_traceback and --pdb. #2216

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
Oct 4, 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
4 changes: 2 additions & 2 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ def wrap_context(self) -> Iterator[None]:
except CompileError:
raise
except Exception as err:
report_internal_error(err, self.path, 0, self.manager.errors)
report_internal_error(err, self.path, 0, self.manager.errors, self.options)
self.manager.errors.set_import_context(save_import_context)
self.check_blockers()

Expand Down Expand Up @@ -1405,7 +1405,7 @@ def semantic_analysis(self) -> None:

def semantic_analysis_pass_three(self) -> None:
with self.wrap_context():
self.manager.semantic_analyzer_pass3.visit_file(self.tree, self.xpath)
self.manager.semantic_analyzer_pass3.visit_file(self.tree, self.xpath, self.options)
if self.options.dump_type_stats:
dump_type_stats(self.tree, self.xpath)

Expand Down
2 changes: 1 addition & 1 deletion mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def accept(self, node: Node, type_context: Type = None) -> Type:
try:
typ = node.accept(self)
except Exception as err:
report_internal_error(err, self.errors.file, node.line, self.errors)
report_internal_error(err, self.errors.file, node.line, self.errors, self.options)
self.type_context.pop()
self.store_type(node, typ)
if self.typing_mode_none():
Expand Down
28 changes: 7 additions & 21 deletions mypy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from typing import Tuple, List, TypeVar, Set, Dict, Optional

from mypy.options import Options


T = TypeVar('T')

Expand Down Expand Up @@ -420,24 +422,8 @@ def remove_path_prefix(path: str, prefix: str) -> str:
return path


# Corresponds to command-line flag --pdb.
drop_into_pdb = False

# Corresponds to command-line flag --show-traceback.
show_tb = False


def set_drop_into_pdb(flag: bool) -> None:
global drop_into_pdb
drop_into_pdb = flag


def set_show_tb(flag: bool) -> None:
global show_tb
show_tb = flag


def report_internal_error(err: Exception, file: str, line: int, errors: Errors) -> None:
def report_internal_error(err: Exception, file: str, line: int,
errors: Errors, options: Options) -> None:
"""Report internal error and exit.

This optionally starts pdb or shows a traceback.
Expand All @@ -462,14 +448,14 @@ def report_internal_error(err: Exception, file: str, line: int, errors: Errors)
file=sys.stderr)

# If requested, drop into pdb. This overrides show_tb.
if drop_into_pdb:
if options.pdb:
print('Dropping into pdb', file=sys.stderr)
import pdb
pdb.post_mortem(sys.exc_info()[2])

# If requested, print traceback, else print note explaining how to get one.
if not show_tb:
if not drop_into_pdb:
if not options.show_traceback:
if not options.pdb:
print('{}: note: please use --show-traceback to print a traceback '
'when reporting a bug'.format(prefix),
file=sys.stderr)
Expand Down
6 changes: 1 addition & 5 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from mypy import git
from mypy import experiments
from mypy.build import BuildSource, BuildResult, PYTHON_EXTENSIONS
from mypy.errors import CompileError, set_drop_into_pdb, set_show_tb
from mypy.errors import CompileError
from mypy.options import Options, BuildType
from mypy.report import reporter_classes

Expand All @@ -33,10 +33,6 @@ def main(script_path: str) -> None:
else:
bin_dir = None
sources, options = process_options(sys.argv[1:])
if options.pdb:
set_drop_into_pdb(True)
if options.show_traceback:
set_show_tb(True)
f = sys.stdout
try:
res = type_check_only(sources, bin_dir, options)
Expand Down
7 changes: 4 additions & 3 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2559,7 +2559,7 @@ def accept(self, node: Node) -> None:
try:
node.accept(self)
except Exception as err:
report_internal_error(err, self.errors.file, node.line, self.errors)
report_internal_error(err, self.errors.file, node.line, self.errors, self.options)


class FirstPass(NodeVisitor):
Expand Down Expand Up @@ -2768,15 +2768,16 @@ def __init__(self, modules: Dict[str, MypyFile], errors: Errors) -> None:
self.modules = modules
self.errors = errors

def visit_file(self, file_node: MypyFile, fnam: str) -> None:
def visit_file(self, file_node: MypyFile, fnam: str, options: Options) -> None:
self.errors.set_file(fnam)
self.options = options
self.accept(file_node)

def accept(self, node: Node) -> None:
try:
node.accept(self)
except Exception as err:
report_internal_error(err, self.errors.file, node.line, self.errors)
report_internal_error(err, self.errors.file, node.line, self.errors, self.options)

def visit_block(self, b: Block) -> None:
if b.is_unreachable:
Expand Down
4 changes: 2 additions & 2 deletions mypy/test/testcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
assert_string_arrays_equal, normalize_error_messages,
testcase_pyversion, update_testcase_output,
)
from mypy.errors import CompileError, set_show_tb
from mypy.errors import CompileError
from mypy.options import Options

from mypy import experiments
Expand Down Expand Up @@ -118,7 +118,7 @@ def run_case_once(self, testcase: DataDrivenTestCase, incremental=0) -> None:

options = self.parse_options(original_program_text, testcase)
options.use_builtins_fixtures = True
set_show_tb(True) # Show traceback on crash.
options.show_traceback = True
if 'optional' in testcase.file:
options.strict_optional = True

Expand Down
2 changes: 1 addition & 1 deletion mypy/test/testcmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_python_evaluation(testcase: DataDrivenTestCase) -> None:
for s in testcase.input:
file.write('{}\n'.format(s))
args = parse_args(testcase.input[0])
args.append('--tb') # Show traceback on crash.
args.append('--show-traceback')
# Type check the program.
fixed = [python3_path,
os.path.join(testcase.old_cwd, 'scripts', 'mypy')]
Expand Down
2 changes: 1 addition & 1 deletion mypy/test/testpythoneval.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_python_evaluation(testcase):
interpreter = python3_path
args = []
py2 = False
args.append('--tb') # Show traceback on crash.
args.append('--show-traceback')
# Write the program to a file.
program = '_program.py'
program_path = os.path.join(test_temp_dir, program)
Expand Down
1 change: 1 addition & 0 deletions mypy/test/testsemanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def get_semanal_options():
options = Options()
options.use_builtins_fixtures = True
options.semantic_analysis_only = True
options.show_traceback = True
return options


Expand Down
1 change: 1 addition & 0 deletions mypy/test/testtransform.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def test_transform(testcase):
options = Options()
options.use_builtins_fixtures = True
options.semantic_analysis_only = True
options.show_traceback = True
options.python_version = testfile_pyversion(testcase.file)
result = build.build(sources=[BuildSource('main', None, src)],
options=options,
Expand Down
1 change: 1 addition & 0 deletions mypy/test/testtypegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def run_test(self, testcase):
src = '\n'.join(testcase.input)
options = Options()
options.use_builtins_fixtures = True
options.show_traceback = True
result = build.build(sources=[BuildSource('main', None, src)],
options=options,
alt_lib_path=config.test_temp_dir)
Expand Down
2 changes: 1 addition & 1 deletion runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def add_mypy_cmd(self, name: str, mypy_args: List[str], cwd: Optional[str] = Non
if not self.allow(full_name):
return
args = [sys.executable, self.mypy] + mypy_args
args.append('--tb') # Show traceback on crash.
args.append('--show-traceback')
self.waiter.add(LazySubprocess(full_name, args, cwd=cwd, env=self.env))

def add_mypy(self, name: str, *args: str, cwd: Optional[str] = None) -> None:
Expand Down