Skip to content

Commit 9270357

Browse files
committed
fixes #118
1 parent 6f2cb64 commit 9270357

File tree

5 files changed

+64
-52
lines changed

5 files changed

+64
-52
lines changed

fastcore/_nbdev.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
"listable_types": "01_foundation.ipynb",
4444
"first": "01_foundation.ipynb",
4545
"nested_attr": "01_foundation.ipynb",
46+
"stop": "01_foundation.ipynb",
47+
"tst": "01_foundation.ipynb",
48+
"tst2": "01_foundation.ipynb",
4649
"CollBase": "01_foundation.ipynb",
4750
"L": "01_foundation.ipynb",
4851
"L.__signature__": "01_foundation.ipynb",
@@ -61,7 +64,6 @@
6164
"in_": "02_utils.ipynb",
6265
"operator.in_": "02_utils.ipynb",
6366
"true": "02_utils.ipynb",
64-
"stop": "02_utils.ipynb",
6567
"gen": "02_utils.ipynb",
6668
"chunked": "02_utils.ipynb",
6769
"AttrDict": "02_utils.ipynb",

fastcore/foundation.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
__all__ = ['defaults', 'copy_func', 'patch_to', 'patch', 'patch_property', 'add_docs', 'docs', 'custom_dir', 'arg0',
44
'arg1', 'arg2', 'arg3', 'arg4', 'coll_repr', 'is_bool', 'mask2idxs', 'cycle', 'zip_cycle', 'is_indexer',
5-
'negate_func', 'GetAttr', 'delegate_attr', 'bind', 'listable_types', 'first', 'nested_attr', 'CollBase', 'L',
6-
'save_config_file', 'read_config_file', 'Config']
5+
'negate_func', 'GetAttr', 'delegate_attr', 'bind', 'listable_types', 'first', 'nested_attr', 'stop', 'tst',
6+
'tst2', 'CollBase', 'L', 'save_config_file', 'read_config_file', 'Config']
77

88
# Cell
99
from .imports import *
@@ -200,6 +200,23 @@ def nested_attr(o, attr, default=None):
200200
except AttributeError: return default
201201
return o
202202

203+
# Cell
204+
def stop(e=StopIteration):
205+
"Raises exception `e` (by default `StopException`)"
206+
raise e
207+
208+
def tst():
209+
try:
210+
stop()
211+
except StopIteration:
212+
return True
213+
214+
def tst2():
215+
try:
216+
stop(e=ValueError)
217+
except ValueError:
218+
return True
219+
203220
# Cell
204221
class CollBase:
205222
"Base class for composing a list of `items`"

fastcore/utils.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
__all__ = ['ifnone', 'maybe_attr', 'basic_repr', 'get_class', 'mk_class', 'wrap_class', 'ignore_exceptions',
44
'exec_local', 'Inf', 'in_', 'lt', 'gt', 'le', 'ge', 'eq', 'ne', 'add', 'sub', 'mul', 'truediv', 'is_',
5-
'is_not', 'in_', 'true', 'stop', 'gen', 'chunked', 'AttrDict', 'dict2obj', 'with_cast', 'store_attr',
6-
'attrdict', 'properties', 'camel2snake', 'snake2camel', 'class2attr', 'hasattrs', 'setattrs', 'ShowPrint',
7-
'Int', 'Str', 'Float', 'tuplify', 'detuplify', 'replicate', 'uniqueify', 'setify', 'merge', 'is_listy',
8-
'range_of', 'groupby', 'last_index', 'shufflish', 'IterLen', 'ReindexCollection', 'num_methods',
9-
'rnum_methods', 'inum_methods', 'fastuple', 'trace', 'compose', 'maps', 'partialler', 'mapped',
10-
'instantiate', 'using_attr', 'Self', 'Self', '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']
5+
'is_not', 'in_', 'true', 'gen', 'chunked', 'AttrDict', 'dict2obj', 'with_cast', 'store_attr', 'attrdict',
6+
'properties', 'camel2snake', 'snake2camel', 'class2attr', 'hasattrs', 'setattrs', 'ShowPrint', 'Int', 'Str',
7+
'Float', 'tuplify', 'detuplify', 'replicate', 'uniqueify', 'setify', 'merge', 'is_listy', 'range_of',
8+
'groupby', 'last_index', 'shufflish', 'IterLen', 'ReindexCollection', 'num_methods', 'rnum_methods',
9+
'inum_methods', 'fastuple', 'trace', 'compose', 'maps', 'partialler', 'mapped', 'instantiate', 'using_attr',
10+
'Self', 'Self', 'remove_patches_path', 'bunzip', 'join_path_file', 'urlread', 'urljson', 'run', 'do_request',
11+
'sort_by_run', 'PrettyString', 'round_multiple', 'even_mults', 'num_cpus', 'add_props', 'ContextManagers',
12+
'set_num_threads', 'ProcessPoolExecutor', 'ThreadPoolExecutor', 'parallel', 'run_procs', 'parallel_gen']
1413

1514
# Cell
1615
from .imports import *
@@ -142,11 +141,6 @@ def true(*args, **kwargs):
142141
"Predicate: always `True`"
143142
return True
144143

145-
# Cell
146-
def stop(e=StopIteration):
147-
"Raises exception `e` (by default `StopException`)"
148-
raise e
149-
150144
# Cell
151145
def gen(func, seq, cond=true):
152146
"Like `(func(o) for o in seq if cond(func(o)))` but handles `StopIteration`"

nbs/01_foundation.ipynb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,40 @@
14531453
"test_eq(nested_attr(a, 'b.d'), None)"
14541454
]
14551455
},
1456+
{
1457+
"cell_type": "code",
1458+
"execution_count": null,
1459+
"metadata": {},
1460+
"outputs": [],
1461+
"source": [
1462+
"#export\n",
1463+
"def stop(e=StopIteration):\n",
1464+
" \"Raises exception `e` (by default `StopException`)\"\n",
1465+
" raise e\n",
1466+
"\n",
1467+
"def tst():\n",
1468+
" try: \n",
1469+
" stop() \n",
1470+
" except StopIteration: \n",
1471+
" return True\n",
1472+
" \n",
1473+
"def tst2():\n",
1474+
" try: \n",
1475+
" stop(e=ValueError) \n",
1476+
" except ValueError: \n",
1477+
" return True"
1478+
]
1479+
},
1480+
{
1481+
"cell_type": "code",
1482+
"execution_count": null,
1483+
"metadata": {},
1484+
"outputs": [],
1485+
"source": [
1486+
"assert tst()\n",
1487+
"assert tst2()"
1488+
]
1489+
},
14561490
{
14571491
"cell_type": "code",
14581492
"execution_count": null,

nbs/02_utils.ipynb

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -750,41 +750,6 @@
750750
"assert true([])"
751751
]
752752
},
753-
{
754-
"cell_type": "code",
755-
"execution_count": null,
756-
"metadata": {},
757-
"outputs": [],
758-
"source": [
759-
"#export\n",
760-
"def stop(e=StopIteration):\n",
761-
" \"Raises exception `e` (by default `StopException`)\"\n",
762-
" raise e"
763-
]
764-
},
765-
{
766-
"cell_type": "code",
767-
"execution_count": null,
768-
"metadata": {},
769-
"outputs": [],
770-
"source": [
771-
"def tst():\n",
772-
" try: \n",
773-
" stop() \n",
774-
" except StopIteration: \n",
775-
" return True\n",
776-
" \n",
777-
"def tst2():\n",
778-
" try: \n",
779-
" stop(e=ValueError) \n",
780-
" except ValueError: \n",
781-
" return True\n",
782-
"\n",
783-
"\n",
784-
"assert tst()\n",
785-
"assert tst2()"
786-
]
787-
},
788753
{
789754
"cell_type": "code",
790755
"execution_count": null,

0 commit comments

Comments
 (0)