Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2660747

Browse files
committed
Code style cleanup in bdb.
1 parent 8175dae commit 2660747

1 file changed

Lines changed: 21 additions & 31 deletions

File tree

Lib/bdb.py

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
import fnmatch
44
import sys
55
import os
6-
import types
76

8-
__all__ = ["BdbQuit","Bdb","Breakpoint"]
7+
__all__ = ["BdbQuit", "Bdb", "Breakpoint"]
98

109
class BdbQuit(Exception):
11-
"""Exception to give up completely"""
10+
"""Exception to give up completely."""
1211

1312

1413
class Bdb:
15-
1614
"""Generic Python debugger base class.
1715
1816
This class takes care of details of the trace facility;
@@ -120,14 +118,14 @@ def stop_here(self, frame):
120118

121119
def break_here(self, frame):
122120
filename = self.canonic(frame.f_code.co_filename)
123-
if not filename in self.breaks:
121+
if filename not in self.breaks:
124122
return False
125123
lineno = frame.f_lineno
126-
if not lineno in self.breaks[filename]:
124+
if lineno not in self.breaks[filename]:
127125
# The line itself has no breakpoint, but maybe the line is the
128126
# first line of a function with breakpoint set by function name.
129127
lineno = frame.f_code.co_firstlineno
130-
if not lineno in self.breaks[filename]:
128+
if lineno not in self.breaks[filename]:
131129
return False
132130

133131
# flag says ok to delete temp. bp
@@ -243,12 +241,9 @@ def set_break(self, filename, lineno, temporary=0, cond = None,
243241
import linecache # Import as late as possible
244242
line = linecache.getline(filename, lineno)
245243
if not line:
246-
return 'Line %s:%d does not exist' % (filename,
247-
lineno)
248-
if not filename in self.breaks:
249-
self.breaks[filename] = []
250-
list = self.breaks[filename]
251-
if not lineno in list:
244+
return 'Line %s:%d does not exist' % (filename, lineno)
245+
list = self.breaks.setdefault(filename, [])
246+
if lineno not in list:
252247
list.append(lineno)
253248
bp = Breakpoint(filename, lineno, temporary, cond, funcname)
254249

@@ -260,11 +255,10 @@ def _prune_breaks(self, filename, lineno):
260255

261256
def clear_break(self, filename, lineno):
262257
filename = self.canonic(filename)
263-
if not filename in self.breaks:
258+
if filename not in self.breaks:
264259
return 'There are no breakpoints in %s' % filename
265260
if lineno not in self.breaks[filename]:
266-
return 'There is no breakpoint at %s:%d' % (filename,
267-
lineno)
261+
return 'There is no breakpoint at %s:%d' % (filename, lineno)
268262
# If there's only one bp in the list for that file,line
269263
# pair, then remove the breaks entry
270264
for bp in Breakpoint.bplist[filename, lineno][:]:
@@ -281,7 +275,7 @@ def clear_bpbynumber(self, arg):
281275

282276
def clear_all_file_breaks(self, filename):
283277
filename = self.canonic(filename)
284-
if not filename in self.breaks:
278+
if filename not in self.breaks:
285279
return 'There are no breakpoints in %s' % filename
286280
for line in self.breaks[filename]:
287281
blist = Breakpoint.bplist[filename, line]
@@ -354,31 +348,30 @@ def get_stack(self, f, t):
354348
i = max(0, len(stack) - 1)
355349
return stack, i
356350

357-
#
358-
359351
def format_stack_entry(self, frame_lineno, lprefix=': '):
360352
import linecache, reprlib
361353
frame, lineno = frame_lineno
362354
filename = self.canonic(frame.f_code.co_filename)
363355
s = '%s(%r)' % (filename, lineno)
364356
if frame.f_code.co_name:
365-
s = s + frame.f_code.co_name
357+
s += frame.f_code.co_name
366358
else:
367-
s = s + "<lambda>"
359+
s += "<lambda>"
368360
if '__args__' in frame.f_locals:
369361
args = frame.f_locals['__args__']
370362
else:
371363
args = None
372364
if args:
373-
s = s + reprlib.repr(args)
365+
s += reprlib.repr(args)
374366
else:
375-
s = s + '()'
367+
s += '()'
376368
if '__return__' in frame.f_locals:
377369
rv = frame.f_locals['__return__']
378-
s = s + '->'
379-
s = s + reprlib.repr(rv)
370+
s += '->'
371+
s += reprlib.repr(rv)
380372
line = linecache.getline(filename, lineno, frame.f_globals)
381-
if line: s = s + lprefix + line.strip()
373+
if line:
374+
s += lprefix + line.strip()
382375
return s
383376

384377
# The following methods can be called by clients to use
@@ -442,8 +435,7 @@ def set_trace():
442435

443436

444437
class Breakpoint:
445-
446-
"""Breakpoint class
438+
"""Breakpoint class.
447439
448440
Implements temporary breakpoints, ignore counts, disabling and
449441
(re)-enabling, and conditionals.
@@ -485,7 +477,6 @@ def __init__(self, file, line, temporary=0, cond=None, funcname=None):
485477
else:
486478
self.bplist[file, line] = [self]
487479

488-
489480
def deleteMe(self):
490481
index = (self.file, self.line)
491482
self.bpbynumber[self.number] = None # No longer in list
@@ -606,6 +597,7 @@ def effective(file, line, frame):
606597
return (b, False)
607598
return (None, None)
608599

600+
609601
# -------------------- testing --------------------
610602

611603
class Tdb(Bdb):
@@ -638,5 +630,3 @@ def bar(a):
638630
def test():
639631
t = Tdb()
640632
t.run('import bdb; bdb.foo(10)')
641-
642-
# end

0 commit comments

Comments
 (0)