Issue
Automatic pdb calling works for errors by toggling %pdb in IPython. Is there an equivalent operation (or workaround) to automatically call pdb on warnings?
Adding pdb.set_trace() to the reported line number is not ideal because the warning is inside a a library file that's called from my code.
"python -m pdb myscript.py" will do this, but I'm inside an ipython repl, not the regular python repl.
The use case here is to find type hinting errors, which are reporteed as warnings like this "RuntimeWarning: invalid value encountered in equal"
Solution
By setting a simple filter to turn warnings into 'error'
:
from warnings import warn, simplefilter
simplefilter('error')
this seems to be working just fine, e.g a sample function:
def foo():
a = '20'
warn("Horrible Things", RuntimeWarning)
which when called now triggers pdb
:
foo()
> <ipython-input-78-f33d9e580240>(4)foo()
1 from warnings import warn
2 def foo():
3 a = '20'
----> 4 warn("Horrible Things", RuntimeWarning)
ipdb>
Answered By - Dimitris Fasarakis Hilliard
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.