#|hide from nbdev.showdoc import * from fastcore.all import * import numpy as np,numbers colab_link('index') coll_repr test_eq(coll_repr(range(1000), 5), '(#1000) [0,1,2,3,4...]') coll_repr(range(1000), 5) test_eq([0,1,2,3], np.arange(4)) test(2, 3, operator.lt) def divide_zero(): return 1/0 test_fail(divide_zero) test_stdout(lambda: print('hi'), 'hi') p = Path('images') p.ls() @patch def num_items(self:Path): return len(self.ls()) p.num_items() class Author: def __init__(self, name): self.name = name class ProductPage(GetAttr): _default = 'author' def __init__(self,author,price,cost): self.author,self.price,self.cost = author,price,cost p = ProductPage(Author("Jeremy"), 1.50, 0.50) [o for o in dir(p) if not o.startswith('_')] class ProductPage: def __init__(self,author,price,cost): store_attr() __repr__ = basic_repr('author,price,cost') ProductPage("Jeremy", 1.50, 0.50) @funcs_kwargs class T: _methods=['some_method'] def __init__(self, **kwargs): assert not kwargs, f'Passed unknown args: {kwargs}' p = T(some_method = print) p.some_method("hello") L(1,2,3) p = L.range(20).shuffle() p p[2,4,6] p.argwhere(ge(15)) 1 + L(2,3,4) class A(Transform): def encodes(self, x): return x+1 A()(1) @Transform def f(x): return x+1 f(1) @Transform def g(x): return x/2 pipe = Pipeline([f,g]) pipe(3)