Skip to content

Commit 938c46b

Browse files
committed
fix trace
1 parent a3c90a8 commit 938c46b

File tree

4 files changed

+16
-36
lines changed

4 files changed

+16
-36
lines changed

fastcore/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.0.23"
1+
__version__ = "1.0.24"

fastcore/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import mimetypes,bz2,pickle,random,json,urllib,subprocess,shlex
2020
from contextlib import contextmanager
21+
from pdb import set_trace
2122
from urllib.request import Request,urlopen
2223
from urllib.error import HTTPError
2324
from urllib.parse import urlencode
@@ -411,9 +412,11 @@ def _f(self,*args): return self._op(op,*args)
411412
# Cell
412413
def trace(f):
413414
"Add `set_trace` to an existing function `f`"
415+
if getattr(f, '_traced', False): return f
414416
def _inner(*args,**kwargs):
415417
set_trace()
416418
return f(*args,**kwargs)
419+
_inner._traced = True
417420
return _inner
418421

419422
# Cell

nbs/02_utils.ipynb

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"\n",
2323
"import mimetypes,bz2,pickle,random,json,urllib,subprocess,shlex\n",
2424
"from contextlib import contextmanager\n",
25+
"from pdb import set_trace\n",
2526
"from urllib.request import Request,urlopen\n",
2627
"from urllib.error import HTTPError\n",
2728
"from urllib.parse import urlencode"
@@ -294,7 +295,7 @@
294295
{
295296
"data": {
296297
"text/plain": [
297-
"<__main__._t at 0x7f4a534e8730>"
298+
"<__main__._t at 0x7fe83401cca0>"
298299
]
299300
},
300301
"execution_count": null,
@@ -2169,7 +2170,7 @@
21692170
{
21702171
"data": {
21712172
"text/plain": [
2172-
"['b', 'f', 'c', 'a', 'g', 'h', 'd', 'e']"
2173+
"['h', 'c', 'e', 'a', 'g', 'b', 'f', 'd']"
21732174
]
21742175
},
21752176
"execution_count": null,
@@ -2521,50 +2522,26 @@
25212522
"#export\n",
25222523
"def trace(f):\n",
25232524
" \"Add `set_trace` to an existing function `f`\"\n",
2525+
" if getattr(f, '_traced', False): return f\n",
25242526
" def _inner(*args,**kwargs):\n",
25252527
" set_trace()\n",
25262528
" return f(*args,**kwargs)\n",
2529+
" _inner._traced = True\n",
25272530
" return _inner"
25282531
]
25292532
},
25302533
{
25312534
"cell_type": "markdown",
25322535
"metadata": {},
25332536
"source": [
2534-
"We can faciltate debugging with [the python debugger (pdb)](https://docs.python.org/3/library/pdb.html) by annotating your function with the `@trace` decorator:"
2535-
]
2536-
},
2537-
{
2538-
"cell_type": "code",
2539-
"execution_count": null,
2540-
"metadata": {},
2541-
"outputs": [],
2542-
"source": [
2543-
"@trace\n",
2544-
"def myfunc(x):return x +1"
2545-
]
2546-
},
2547-
{
2548-
"cell_type": "markdown",
2549-
"metadata": {},
2550-
"source": [
2551-
"Now, when the function is called it will drop you into the debugger. Note, you must issue the `s` command when you begin to step into the function that is being traced:\n",
2537+
"You can add a breakpoint to an existing function, e.g:\n",
25522538
"\n",
2553-
"```bash\n",
2554-
"> myfunc(3)\n",
2555-
"> <ipython-input-257-13ccd7456a8e>(6)_inner()\n",
2556-
" 3 \"Add `set_trace` to an existing function `f`\"\n",
2557-
" 4 def _inner(*args,**kwargs):\n",
2558-
" 5 set_trace()\n",
2559-
"----> 6 return f(*args,**kwargs)\n",
2560-
" 7 return _inner\n",
2539+
"```python\n",
2540+
"Path.cwd = trace(Path.cwd)\n",
2541+
"Path.cwd()\n",
2542+
"```\n",
25612543
"\n",
2562-
"ipdb> s\n",
2563-
"--Call--\n",
2564-
"> <ipython-input-260-b3d1b2a13afb>(1)myfunc()\n",
2565-
"----> 1 @trace\n",
2566-
" 2 def myfunc(x):return x +1\n",
2567-
"```"
2544+
"Now, when the function is called it will drop you into the debugger. Note, you must issue the `s` command when you begin to step into the function that is being traced."
25682545
]
25692546
},
25702547
{

settings.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ author = Jeremy Howard and Sylvain Gugger
77
author_email = [email protected]
88
copyright = fast.ai
99
branch = master
10-
version = 1.0.23
10+
version = 1.0.24
1111
min_python = 3.6
1212
audience = Developers
1313
language = English

0 commit comments

Comments
 (0)