reingart / rad2py_googlecode

Automatically exported from code.google.com/p/rad2py
GNU General Public License v3.0
0 stars 1 forks source link

BDB (exec) reports incorrect line on exceptions raised on main module #7

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a file (hola.py)
2. Edit (see code sample bellow)
3. Run with the debugger (F5), it reports incorrectly line 1
4. Run with shell (SHIFT+F5), it reports correctly line 9

Sample code:

def main(h="CHAU!"):
    a = h
    n = raw_input("nombre?")
    n = n+"ldasf"
    if n:
        print a, n

if __name__=="__main__":
    main(j=1)

What is the expected output? 

Traceback (most recent call last):
  File "/home/reingart/tesis/rad2py/hola.py", line 9, in <module>
    main(j=1)
TypeError: main() got an unexpected keyword argument 'j'

What do you see instead?

Traceback (most recent call last):
  File "main.py", line 577, in OnDebugCommand
    self.OnRun(event, debug=True)
  File "main.py", line 459, in OnRun
    self.shell.RunScript(code, syspath, debug and self.debugger, self.console)
  File "/home/reingart/tesis/rad2py/ide2py/shell.py", line 73, in RunScript
    debugger.Run(code, interp=self.interp)
  File "/home/reingart/tesis/rad2py/ide2py/debugger.py", line 51, in Run
    return self.run(code, *args, **kwargs)
  File "/usr/lib/python2.7/bdb.py", line 387, in run
    exec cmd in globals, locals
  File "/home/reingart/tesis/rad2py/hola.py", line 1, in <module>
    def main(h="CHAU!"):
TypeError: main() got an unexpected keyword argument 'j'

Original issue reported on code.google.com by reingart@gmail.com on 7 Oct 2011 at 6:36

GoogleCodeExporter commented 9 years ago
Resolved using the imp module:

imp.load_source("__main__", filename)

instead of:

execfile(filename)

Now the exceptions in the main module are reported with the correct line number

Original comment by reingart@gmail.com on 14 Jan 2012 at 7:34