Skip to content

Commit 27fc63f

Browse files
committed
Using the fancy contextlib.suppress to suppress error
1 parent 2705463 commit 27fc63f

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

Lib/bdb.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import threading
66
import os
77
import weakref
8-
from contextlib import contextmanager
8+
from contextlib import contextmanager, suppress
99
from inspect import CO_GENERATOR, CO_COROUTINE, CO_ASYNC_GENERATOR
1010

1111
__all__ = ["BdbQuit", "Bdb", "Breakpoint"]
@@ -684,13 +684,11 @@ def set_break(self, filename, lineno, temporary=False, cond=None,
684684
return 'Line %s:%d does not exist' % (filename, lineno)
685685
source = ''.join(linecache.getlines(filename))
686686
if source:
687-
try:
687+
with suppress(SyntaxError):
688688
code = compile(source, filename, 'exec')
689689
executable_lines = _get_executable_linenos(code)
690690
if executable_lines and lineno not in executable_lines:
691691
return 'Line %d has no code associated with it' % lineno
692-
except SyntaxError:
693-
pass
694692
self._add_to_breaks(filename, lineno)
695693
bp = Breakpoint(filename, lineno, temporary, cond, funcname)
696694
# After we set a new breakpoint, we need to search through all frames

0 commit comments

Comments
 (0)