I've tracked down a bug in which io.open()
should have been passed 'utf-8'
instead of 'utf8'
. Minimal executable code below. Why doesn't the IPython traceback indicate a line number, and why does pdb neither report that the error was with the io.open
function call nor report anything from within the the io.open
code? What could I have done with pdb
or the IPython debugger or the Canopy debugger layered on top of it to have had an easier time debugging this one?
Checking my IPython version is also confusing. The Canopy package manager reports that both ipython 4.0.0-3
and ipython4 4.0.0-9
are installed, but import IPython
followed by IPython.version_info
evaluates to (2, 4, 1, '')
.
my_module.py
in Canopy code editor:
import io
def my_function(filename):
with io.open(my_other_function(filename), u'r', u'utf8')
def my_other_function(text):
return u'modified' + text
In the IPython session:
In []: import pdb
In []: import my_module
In []: my_module.my_function(filename)
-------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-4c50d9f6cb5c> in <module>()
----> 1 my_module.my_function(filename)
C:\my_module in my_function(filename)
TypeError: an integer is required
In []: pdb.pm()
> c:\users\bbrown\documents\github\canvasapi-python\capi\my_module.py(3)my_function()
-> with io.open(my_other_function(filename), u'w', u'utf8') as filehandle:
(Pdb) up
> <ipython-input-14-f6d6cc2c1670>(1)<module>()
-> my_module.my_function('testjunk')
(Pdb) down
> c:\users\bbrown\documents\github\canvasapi-python\capi\my_module.py(3)my_function()
-> with io.open(my_other_function(filename), u'w', u'utf8') as filehandle:
(Pdb) args
filename = testjunk
(Pdb) down
*** Newest frame
Given that 'utf-8'
works fine as an argument, the TypeError
is surprising unless originating from within the code of open
, yet the call to open
was not placed on the stack, at least not as navigable from pdb
. Thank you for helping me and others learn how to debug more efficiently!