Skip to content

Commit e4672d7

Browse files
committed
lazy
1 parent 0962367 commit e4672d7

5 files changed

Lines changed: 36 additions & 8 deletions

File tree

fastcore/basics.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
# %% ../nbs/01_basics.ipynb #0e91ed82
2727
from .imports import *
28-
import ast,builtins,pprint,types,typing
28+
import builtins,types,typing
2929
from functools import cmp_to_key,wraps
3030
from copy import copy
3131
from datetime import date
@@ -279,7 +279,10 @@ def __dir__(self): return super().__dir__() + list(self.keys())
279279
# %% ../nbs/01_basics.ipynb #28bf9743
280280
class AttrDict(adict):
281281
"`dict` subclass that also provides access to keys as attrs, and has a pretty markdown repr"
282-
def _repr_markdown_(self): return f'```python\n{pprint.pformat(self, indent=2)}\n```'
282+
def _repr_markdown_(self):
283+
import pprint
284+
return f'```python\n{pprint.pformat(self, indent=2)}\n```'
285+
283286
def copy(self): return AttrDict(**self)
284287

285288
# %% ../nbs/01_basics.ipynb #cb8a0ff4
@@ -1276,6 +1279,7 @@ def str2float(s:str):
12761279
# %% ../nbs/01_basics.ipynb #5d49a6d4
12771280
def str2list(s:str):
12781281
"Convert `s` to a list"
1282+
import ast
12791283
s = s.strip()
12801284
if not s: return []
12811285
if s[0] != '[': s = '['+s + ']'

fastcore/parallel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from .xtras import *
1515
from functools import wraps
1616

17-
import concurrent.futures,time,asyncio
17+
import concurrent.futures,time
1818
from multiprocessing import Process,Queue,Manager,set_start_method,get_all_start_methods,get_context
1919
from threading import Thread
2020
try:
@@ -156,6 +156,7 @@ def _add_one(x, a=1):
156156
async def parallel_async(f, items, *args, n_workers=16, pause=0,
157157
timeout=None, chunksize=1, on_exc=print, cancel_on_error=False, **kwargs):
158158
"Applies `f` to `items` in parallel using asyncio and a semaphore to limit concurrency."
159+
import asyncio
159160
semaphore = asyncio.Semaphore(n_workers)
160161
async def limited_task(i, item):
161162
coro = f(item, *args, **kwargs) if asyncio.iscoroutinefunction(f) else asyncio.to_thread(f, item, *args, **kwargs)

nbs/01_basics.ipynb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"source": [
2020
"#| export\n",
2121
"from fastcore.imports import *\n",
22-
"import ast,builtins,pprint,types,typing\n",
22+
"import builtins,types,typing\n",
2323
"from functools import cmp_to_key,wraps\n",
2424
"from copy import copy\n",
2525
"from datetime import date\n",
@@ -1700,7 +1700,10 @@
17001700
"#| export\n",
17011701
"class AttrDict(adict):\n",
17021702
" \"`dict` subclass that also provides access to keys as attrs, and has a pretty markdown repr\"\n",
1703-
" def _repr_markdown_(self): return f'```python\\n{pprint.pformat(self, indent=2)}\\n```'\n",
1703+
" def _repr_markdown_(self):\n",
1704+
" import pprint\n",
1705+
" return f'```python\\n{pprint.pformat(self, indent=2)}\\n```'\n",
1706+
"\n",
17041707
" def copy(self): return AttrDict(**self)"
17051708
]
17061709
},
@@ -7724,6 +7727,7 @@
77247727
"#| export\n",
77257728
"def str2list(s:str):\n",
77267729
" \"Convert `s` to a list\"\n",
7730+
" import ast\n",
77277731
" s = s.strip()\n",
77287732
" if not s: return []\n",
77297733
" if s[0] != '[': s = '['+s + ']'\n",
@@ -8385,7 +8389,16 @@
83858389
]
83868390
}
83878391
],
8388-
"metadata": {},
8392+
"metadata": {
8393+
"solveit": {
8394+
"default_code": false,
8395+
"mode": "learning",
8396+
"use_fence": false,
8397+
"use_thinking": true,
8398+
"use_tools": true,
8399+
"ver": 2
8400+
}
8401+
},
83898402
"nbformat": 4,
83908403
"nbformat_minor": 5
83918404
}

nbs/02_foundation.ipynb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4569,7 +4569,16 @@
45694569
]
45704570
}
45714571
],
4572-
"metadata": {},
4572+
"metadata": {
4573+
"solveit": {
4574+
"default_code": false,
4575+
"mode": "learning",
4576+
"use_fence": false,
4577+
"use_thinking": true,
4578+
"use_tools": true,
4579+
"ver": 2
4580+
}
4581+
},
45734582
"nbformat": 4,
45744583
"nbformat_minor": 5
45754584
}

nbs/03a_parallel.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"from fastcore.xtras import *\n",
2626
"from functools import wraps\n",
2727
"\n",
28-
"import concurrent.futures,time,asyncio\n",
28+
"import concurrent.futures,time\n",
2929
"from multiprocessing import Process,Queue,Manager,set_start_method,get_all_start_methods,get_context\n",
3030
"from threading import Thread\n",
3131
"try:\n",
@@ -766,6 +766,7 @@
766766
"async def parallel_async(f, items, *args, n_workers=16, pause=0,\n",
767767
" timeout=None, chunksize=1, on_exc=print, cancel_on_error=False, **kwargs):\n",
768768
" \"Applies `f` to `items` in parallel using asyncio and a semaphore to limit concurrency.\"\n",
769+
" import asyncio\n",
769770
" semaphore = asyncio.Semaphore(n_workers)\n",
770771
" async def limited_task(i, item):\n",
771772
" coro = f(item, *args, **kwargs) if asyncio.iscoroutinefunction(f) else asyncio.to_thread(f, item, *args, **kwargs)\n",

0 commit comments

Comments
 (0)