Skip to content

Commit 46fa345

Browse files
committed
CHANGELOG
1 parent a3d4bbb commit 46fa345

File tree

11 files changed

+89
-18
lines changed

11 files changed

+89
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
token
12
docs/
23
conda/
34
.last_checked

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ test:
1818
nbdev_test_nbs
1919

2020
release: pypi
21+
git tag "$(python setup.py version)"
22+
git push --tags
2123
nbdev_conda_package --upload_user fastai --build_args '-c pytorch -c fastai'
2224
nbdev_bump_version
2325

fastcore/__init__.py

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

fastcore/_nbdev.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@
114114
"remove_patches_path": "02_utils.ipynb",
115115
"bunzip": "02_utils.ipynb",
116116
"join_path_file": "02_utils.ipynb",
117+
"urlread": "02_utils.ipynb",
118+
"urljson": "02_utils.ipynb",
117119
"sort_by_run": "02_utils.ipynb",
118120
"PrettyString": "02_utils.ipynb",
119121
"round_multiple": "02_utils.ipynb",

fastcore/dispatch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def __init__(self, funcs=(), bases=()):
7272

7373
def add(self, f):
7474
"Add type `t` and function `f`"
75+
if f and getattr(f,'__defaults__',None): warn(f"{f.__name__} has default params. These will be ignored.")
7576
a0,a1 = _p2_anno(f)
7677
t = self.funcs.d.get(a0)
7778
if t is None:

fastcore/imports.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import numpy as np
22
import io,operator,sys,os,re,mimetypes,itertools,shutil,pickle,tempfile,subprocess
33
import itertools,random,inspect,functools,math,bz2,typing,numbers,warnings,threading
4+
import json,urllib.request
45

6+
from warnings import warn
57
from dataclasses import dataclass
68
from functools import partial,reduce
79
from threading import Thread
@@ -14,6 +16,7 @@
1416
from collections import defaultdict,Counter
1517
from operator import itemgetter,attrgetter
1618
from uuid import uuid4
19+
from urllib.request import HTTPError
1720

1821
# External modules
1922
from numpy import array,ndarray
@@ -70,3 +73,4 @@ def equals(a,b):
7073
all_equal if is_iter(a) or is_iter(b) else
7174
operator.eq)
7275
return cmp(a,b)
76+

fastcore/utils.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
'rnum_methods', 'inum_methods', 'fastuple', 'Inf', 'in_', 'lt', 'gt', 'le', 'ge', 'eq', 'ne', 'add', 'sub',
88
'mul', 'truediv', 'is_', 'is_not', 'in_', 'true', 'stop', 'gen', 'chunked', 'trace', 'compose', 'maps',
99
'partialler', 'mapped', 'instantiate', 'using_attr', 'log_args', 'Self', 'Self', 'remove_patches_path',
10-
'bunzip', 'join_path_file', 'sort_by_run', 'PrettyString', 'round_multiple', 'even_mults', 'num_cpus',
11-
'add_props', 'ContextManagers', 'set_num_threads', 'ProcessPoolExecutor', 'parallel', 'parallel_chunks',
12-
'run_procs', 'parallel_gen', 'ipython_shell', 'in_ipython', 'in_colab', 'in_jupyter', 'in_notebook',
13-
'IN_NOTEBOOK', 'IN_JUPYTER', 'IN_COLAB', 'IN_IPYTHON']
10+
'bunzip', 'join_path_file', 'urlread', 'urljson', 'sort_by_run', 'PrettyString', 'round_multiple',
11+
'even_mults', 'num_cpus', 'add_props', 'ContextManagers', 'set_num_threads', 'ProcessPoolExecutor',
12+
'parallel', 'parallel_chunks', 'run_procs', 'parallel_gen', 'ipython_shell', 'in_ipython', 'in_colab',
13+
'in_jupyter', 'in_notebook', 'IN_NOTEBOOK', 'IN_JUPYTER', 'IN_COLAB', 'IN_IPYTHON']
1414

1515
# Cell
1616
from .imports import *
@@ -594,6 +594,16 @@ def join_path_file(file, path, ext=''):
594594
path.mkdir(parents=True, exist_ok=True)
595595
return path/f'{file}{ext}'
596596

597+
# Cell
598+
def urlread(url):
599+
"Retrieve `url`"
600+
return urllib.request.urlopen(url).read()
601+
602+
# Cell
603+
def urljson(url):
604+
"Retrieve `url` and decode json"
605+
return json.loads(urlread(url))
606+
597607
# Cell
598608
def _is_instance(f, gs):
599609
tst = [g if type(g) in [type, 'function'] else g.__class__ for g in gs]

nbs/02_utils.ipynb

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3100,7 +3100,7 @@
31003100
"source": [
31013101
"## File Functions\n",
31023102
"\n",
3103-
"Utilities (other than extensions to Pathlib.Path) for dealing with files."
3103+
"Utilities (other than extensions to Pathlib.Path) for dealing with IO."
31043104
]
31053105
},
31063106
{
@@ -3163,6 +3163,30 @@
31633163
"shutil.rmtree(Path.cwd()/'_tmp')"
31643164
]
31653165
},
3166+
{
3167+
"cell_type": "code",
3168+
"execution_count": null,
3169+
"metadata": {},
3170+
"outputs": [],
3171+
"source": [
3172+
"#export\n",
3173+
"def urlread(url):\n",
3174+
" \"Retrieve `url`\"\n",
3175+
" return urllib.request.urlopen(url).read()"
3176+
]
3177+
},
3178+
{
3179+
"cell_type": "code",
3180+
"execution_count": null,
3181+
"metadata": {},
3182+
"outputs": [],
3183+
"source": [
3184+
"#export\n",
3185+
"def urljson(url):\n",
3186+
" \"Retrieve `url` and decode json\"\n",
3187+
" return json.loads(urlread(url))"
3188+
]
3189+
},
31663190
{
31673191
"cell_type": "markdown",
31683192
"metadata": {},

nbs/03_dispatch.ipynb

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@
336336
"\n",
337337
" def add(self, f):\n",
338338
" \"Add type `t` and function `f`\"\n",
339+
" if f and getattr(f,'__defaults__',None): warn(f\"{f.__name__} has default params. These will be ignored.\")\n",
339340
" a0,a1 = _p2_anno(f)\n",
340341
" t = self.funcs.d.get(a0)\n",
341342
" if t is None:\n",
@@ -828,7 +829,7 @@
828829
{
829830
"data": {
830831
"text/markdown": [
831-
"<h4 id=\"TypeDispatch.__call__\" class=\"doc_header\"><code>TypeDispatch.__call__</code><a href=\"__main__.py#L32\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
832+
"<h4 id=\"TypeDispatch.__call__\" class=\"doc_header\"><code>TypeDispatch.__call__</code><a href=\"__main__.py#L33\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
832833
"\n",
833834
"> <code>TypeDispatch.__call__</code>(**\\*`args`**, **\\*\\*`kwargs`**)\n",
834835
"\n",
@@ -916,7 +917,7 @@
916917
{
917918
"data": {
918919
"text/markdown": [
919-
"<h4 id=\"TypeDispatch.returns\" class=\"doc_header\"><code>TypeDispatch.returns</code><a href=\"__main__.py#L20\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
920+
"<h4 id=\"TypeDispatch.returns\" class=\"doc_header\"><code>TypeDispatch.returns</code><a href=\"__main__.py#L21\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
920921
"\n",
921922
"> <code>TypeDispatch.returns</code>(**`x`**)\n",
922923
"\n",
@@ -979,14 +980,14 @@
979980
"source": [
980981
"def m_nin(self, x:(str,numbers.Integral)): return str(x)+'1'\n",
981982
"def m_bll(self, x:bool): self.foo='a'\n",
982-
"def m_num(self, x:numbers.Number): return x\n",
983+
"def m_num(self, x:numbers.Number): return x*2\n",
983984
"\n",
984985
"t = TypeDispatch([m_nin,m_num,m_bll])\n",
985986
"class A: f = t # set class attribute `f` equal to a TypeDispatch instance\n",
986987
" \n",
987988
"a = A()\n",
988989
"test_eq(a.f(1), '11') #dispatch to m_nin\n",
989-
"test_eq(a.f(1.), 1.) #dispatch to m_num\n",
990+
"test_eq(a.f(1.), 2.) #dispatch to m_num\n",
990991
"test_is(a.f.inst, a)\n",
991992
"\n",
992993
"a.f(False) # this triggers t.m_bll to run, which sets self.foo to 'a'\n",
@@ -1028,7 +1029,7 @@
10281029
"class A2: f = t2\n",
10291030
"a2 = A2()\n",
10301031
"test_eq(a2.f(1), '11')\n",
1031-
"test_eq(a2.f(1.), 1.)\n",
1032+
"test_eq(a2.f(1.), 2.)\n",
10321033
"test_is(a2.f.inst, a2)\n",
10331034
"a2.f(False)\n",
10341035
"test_eq(a2.foo, 'a')\n",
@@ -1072,15 +1073,36 @@
10721073
"def f_td_test(x:numbers.Integral, y): return x+1\n",
10731074
"@typedispatch\n",
10741075
"def f_td_test(x:int, y:float): return x+y\n",
1076+
"@typedispatch\n",
1077+
"def f_td_test(x:int, y:int): return x*y\n",
10751078
"\n",
10761079
"test_eq(f_td_test(3,2.0), 5)\n",
1077-
"\n",
10781080
"assert issubclass(int, numbers.Integral)\n",
1079-
"test_eq(f_td_test(3,2), 4)\n",
1081+
"test_eq(f_td_test(3,2), 6)\n",
10801082
"\n",
10811083
"test_eq(f_td_test('a','b'), 'ab')"
10821084
]
10831085
},
1086+
{
1087+
"cell_type": "code",
1088+
"execution_count": null,
1089+
"metadata": {},
1090+
"outputs": [
1091+
{
1092+
"name": "stdout",
1093+
"output_type": "stream",
1094+
"text": [
1095+
"<class 'UserWarning'>: f_td_test has default params. These will be ignored.\n"
1096+
]
1097+
}
1098+
],
1099+
"source": [
1100+
"def outer():\n",
1101+
" @typedispatch\n",
1102+
" def f_td_test(x:int,y:int=10): return x*y\n",
1103+
"test_warns(outer,True)"
1104+
]
1105+
},
10841106
{
10851107
"cell_type": "markdown",
10861108
"metadata": {},

settings.ini

Lines changed: 2 additions & 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.1
10+
version = 1.0.2
1111
min_python = 3.6
1212
audience = Developers
1313
language = English
@@ -24,4 +24,5 @@ title = fastcore
2424
doc_host = https://fastcore.fast.ai
2525
doc_baseurl = /
2626
host = github
27+
doc_src_path = docs_src
2728

0 commit comments

Comments
 (0)