From 655cbfd1d61d4e5fb2cdc5d0c95c85a8f73bf689 2010-01-01 05:13:01 From: Fernando Perez Date: 2010-01-01 05:13:01 Subject: [PATCH] Fix debugging with breakpoints. URL: https://bugs.launchpad.net/ipython/+bug/381069 --- diff --git a/IPython/Debugger.py b/IPython/Debugger.py index 117b7d1..34b92e3 100644 --- a/IPython/Debugger.py +++ b/IPython/Debugger.py @@ -520,3 +520,36 @@ class Pdb(OldPdb): namespaces = [('Locals', self.curframe.f_locals), ('Globals', self.curframe.f_globals)] __IPYTHON__.magic_pinfo("pinfo %s" % arg, namespaces=namespaces) + + def checkline(self, filename, lineno): + """Check whether specified line seems to be executable. + + Return `lineno` if it is, 0 if not (e.g. a docstring, comment, blank + line or EOF). Warning: testing is not comprehensive. + """ + ####################################################################### + # XXX Hack! Use python-2.5 compatible code for this call, because with + # all of our changes, we've drifted from the pdb api in 2.6. For now, + # changing: + # + #line = linecache.getline(filename, lineno, self.curframe.f_globals) + # to: + # + line = linecache.getline(filename, lineno) + # + # does the trick. But in reality, we need to fix this by reconciling + # our updates with the new Pdb APIs in Python 2.6. + # + # End hack. The rest of this method is copied verbatim from 2.6 pdb.py + ####################################################################### + + if not line: + print >>self.stdout, 'End of file' + return 0 + line = line.strip() + # Don't allow setting breakpoint at a blank line + if (not line or (line[0] == '#') or + (line[:3] == '"""') or line[:3] == "'''"): + print >>self.stdout, '*** Blank or comment' + return 0 + return lineno