Skip to content

Commit 8b02927

Browse files
committed
fixes #121
1 parent b1d27bf commit 8b02927

File tree

3 files changed

+11
-63
lines changed

3 files changed

+11
-63
lines changed

fastcore/_nbdev.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@
111111
"load_pickle": "02_utils.ipynb",
112112
"Path.ls": "02_utils.ipynb",
113113
"Path.__repr__": "02_utils.ipynb",
114-
"remove_patches_path": "02_utils.ipynb",
115114
"bunzip": "02_utils.ipynb",
116115
"join_path_file": "02_utils.ipynb",
117116
"urlread": "02_utils.ipynb",

fastcore/utils.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
'Float', 'tuplify', 'detuplify', 'replicate', 'uniqueify', 'setify', 'merge', 'is_listy', 'range_of',
88
'groupby', 'last_index', 'shufflish', 'IterLen', 'ReindexCollection', 'num_methods', 'rnum_methods',
99
'inum_methods', 'fastuple', 'trace', 'compose', 'maps', 'partialler', 'mapped', 'instantiate', 'using_attr',
10-
'Self', 'Self', 'save_pickle', 'load_pickle', 'remove_patches_path', 'bunzip', 'join_path_file', 'urlread',
11-
'urljson', 'run', 'do_request', 'sort_by_run', 'PrettyString', 'round_multiple', 'even_mults', 'num_cpus',
12-
'add_props', 'ContextManagers', 'set_num_threads', 'ProcessPoolExecutor', 'ThreadPoolExecutor', 'parallel',
13-
'run_procs', 'parallel_gen']
10+
'Self', 'Self', 'save_pickle', 'load_pickle', 'bunzip', 'join_path_file', 'urlread', 'urljson', 'run',
11+
'do_request', 'sort_by_run', 'PrettyString', 'round_multiple', 'even_mults', 'num_cpus', 'add_props',
12+
'ContextManagers', 'set_num_threads', 'ProcessPoolExecutor', 'ThreadPoolExecutor', 'parallel', 'run_procs',
13+
'parallel_gen']
1414

1515
# Cell
1616
from .imports import *
@@ -545,19 +545,6 @@ def __repr__(self:Path):
545545
except: pass
546546
return f"Path({self.as_posix()!r})"
547547

548-
# Cell
549-
_patched = ['read', 'readlines', 'write', 'save', 'load', 'ls']
550-
551-
@contextmanager
552-
def remove_patches_path():
553-
"A context manager for disabling Path extensions."
554-
patches = L(getattr(Path, n) for n in _patched)
555-
try:
556-
for n in _patched: delattr(Path, n)
557-
yield
558-
finally:
559-
for (n, f) in zip(_patched, patches): setattr(Path, n, f)
560-
561548
# Cell
562549
def bunzip(fn):
563550
"bunzip `fn`, raising exception if output already exists"

nbs/02_utils.ipynb

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@
295295
{
296296
"data": {
297297
"text/plain": [
298-
"<__main__._t at 0x7fcf69d97d10>"
298+
"<__main__._t at 0x7f85ba48cfd0>"
299299
]
300300
},
301301
"execution_count": null,
@@ -2170,7 +2170,7 @@
21702170
{
21712171
"data": {
21722172
"text/plain": [
2173-
"['b', 'f', 'h', 'a', 'c', 'g', 'e', 'd']"
2173+
"['e', 'g', 'f', 'b', 'c', 'a', 'd', 'h']"
21742174
]
21752175
},
21762176
"execution_count": null,
@@ -3057,44 +3057,6 @@
30573057
"finally: Path.BASE_PATH = None"
30583058
]
30593059
},
3060-
{
3061-
"cell_type": "code",
3062-
"execution_count": null,
3063-
"metadata": {},
3064-
"outputs": [],
3065-
"source": [
3066-
"#export\n",
3067-
"_patched = ['read', 'readlines', 'write', 'save', 'load', 'ls']\n",
3068-
"\n",
3069-
"@contextmanager\n",
3070-
"def remove_patches_path():\n",
3071-
" \"A context manager for disabling Path extensions.\"\n",
3072-
" patches = L(getattr(Path, n) for n in _patched)\n",
3073-
" try:\n",
3074-
" for n in _patched: delattr(Path, n)\n",
3075-
" yield\n",
3076-
" finally:\n",
3077-
" for (n, f) in zip(_patched, patches): setattr(Path, n, f)"
3078-
]
3079-
},
3080-
{
3081-
"cell_type": "markdown",
3082-
"metadata": {},
3083-
"source": [
3084-
"You can temporarily disable the various `Path` extensions by using `remove_patches_path` as a context manager as illustrated below:"
3085-
]
3086-
},
3087-
{
3088-
"cell_type": "code",
3089-
"execution_count": null,
3090-
"metadata": {},
3091-
"outputs": [],
3092-
"source": [
3093-
"with remove_patches_path():\n",
3094-
" assert not hasattr(Path, 'write')\n",
3095-
"assert hasattr(Path, 'write')"
3096-
]
3097-
},
30983060
{
30993061
"cell_type": "markdown",
31003062
"metadata": {},
@@ -3897,11 +3859,11 @@
38973859
"name": "stdout",
38983860
"output_type": "stream",
38993861
"text": [
3900-
"0 2020-10-08 18:02:47.582440\n",
3901-
"1 2020-10-08 18:02:47.833442\n",
3902-
"2 2020-10-08 18:02:48.083059\n",
3903-
"3 2020-10-08 18:02:48.334451\n",
3904-
"4 2020-10-08 18:02:48.584491\n"
3862+
"0 2020-10-08 18:38:18.973557\n",
3863+
"1 2020-10-08 18:38:19.223553\n",
3864+
"2 2020-10-08 18:38:19.475253\n",
3865+
"3 2020-10-08 18:38:19.725614\n",
3866+
"4 2020-10-08 18:38:19.976216\n"
39053867
]
39063868
}
39073869
],

0 commit comments

Comments
 (0)