Skip to content

Commit 9e6e7c7

Browse files
rename nbs to keep sequential numbering after removing 4 and 5
1 parent b643a7f commit 9e6e7c7

15 files changed

+115
-115
lines changed

fastcore/docments.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Document parameters using comments."""
22

3-
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/06_docments.ipynb.
3+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/04_docments.ipynb.
44

5-
# %% ../nbs/06_docments.ipynb 2
5+
# %% ../nbs/04_docments.ipynb 2
66
from __future__ import annotations
77

88
import re,ast
@@ -22,35 +22,35 @@
2222
__all__ = ['empty', 'docstring', 'parse_docstring', 'isdataclass', 'get_dataclass_source', 'get_source', 'get_name', 'qual_name',
2323
'docments', 'extract_docstrings']
2424

25-
# %% ../nbs/06_docments.ipynb
25+
# %% ../nbs/04_docments.ipynb
2626
def docstring(sym):
2727
"Get docstring for `sym` for functions ad classes"
2828
if isinstance(sym, str): return sym
2929
res = getdoc(sym)
3030
if not res and isclass(sym): res = getdoc(sym.__init__)
3131
return res or ""
3232

33-
# %% ../nbs/06_docments.ipynb
33+
# %% ../nbs/04_docments.ipynb
3434
def parse_docstring(sym):
3535
"Parse a numpy-style docstring in `sym`"
3636
return AttrDict(**docscrape.NumpyDocString(docstring(sym)))
3737

38-
# %% ../nbs/06_docments.ipynb
38+
# %% ../nbs/04_docments.ipynb
3939
def isdataclass(s):
4040
"Check if `s` is a dataclass but not a dataclass' instance"
4141
return is_dataclass(s) and isclass(s)
4242

43-
# %% ../nbs/06_docments.ipynb
43+
# %% ../nbs/04_docments.ipynb
4444
def get_dataclass_source(s):
4545
"Get source code for dataclass `s`"
4646
return getsource(s) if not getattr(s, "__module__") == '__main__' else ""
4747

48-
# %% ../nbs/06_docments.ipynb
48+
# %% ../nbs/04_docments.ipynb
4949
def get_source(s):
5050
"Get source code for string, function object or dataclass `s`"
5151
return getsource(s) if isfunction(s) or ismethod(s) else get_dataclass_source(s) if isdataclass(s) else s
5252

53-
# %% ../nbs/06_docments.ipynb
53+
# %% ../nbs/04_docments.ipynb
5454
def _parses(s):
5555
"Parse Python code in string, function object or dataclass `s`"
5656
return parse(dedent(get_source(s)))
@@ -85,10 +85,10 @@ def _param_locs(s, returns=True, args_kwargs=False):
8585
return res
8686
return None
8787

88-
# %% ../nbs/06_docments.ipynb
88+
# %% ../nbs/04_docments.ipynb
8989
empty = Parameter.empty
9090

91-
# %% ../nbs/06_docments.ipynb
91+
# %% ../nbs/04_docments.ipynb
9292
def _get_comment(line, arg, comments, parms):
9393
if line in comments: return comments[line].strip()
9494
line -= 1
@@ -105,7 +105,7 @@ def _get_full(p, docs):
105105
elif p.kind in (Parameter.VAR_POSITIONAL, Parameter.VAR_KEYWORD): anno = p.kind
106106
return AttrDict(docment=docs.get(p.name), anno=anno, default=p.default)
107107

108-
# %% ../nbs/06_docments.ipynb
108+
# %% ../nbs/04_docments.ipynb
109109
def _merge_doc(dm, npdoc):
110110
if not npdoc: return dm
111111
if not dm.anno or dm.anno==empty: dm.anno = npdoc.type
@@ -118,14 +118,14 @@ def _merge_docs(dms, npdocs):
118118
if 'return' in dms: params['return'] = _merge_doc(dms['return'], npdocs['Returns'])
119119
return params
120120

121-
# %% ../nbs/06_docments.ipynb
121+
# %% ../nbs/04_docments.ipynb
122122
def _get_property_name(p):
123123
"Get the name of property `p`"
124124
if hasattr(p, 'fget'):
125125
return p.fget.func.__qualname__ if hasattr(p.fget, 'func') else p.fget.__qualname__
126126
else: return next(iter(re.findall(r'\'(.*)\'', str(p)))).split('.')[-1]
127127

128-
# %% ../nbs/06_docments.ipynb
128+
# %% ../nbs/04_docments.ipynb
129129
def get_name(obj):
130130
"Get the name of `obj`"
131131
if hasattr(obj, '__name__'): return obj.__name__
@@ -134,14 +134,14 @@ def get_name(obj):
134134
elif type(obj)==property: return _get_property_name(obj)
135135
else: return str(obj).split('.')[-1]
136136

137-
# %% ../nbs/06_docments.ipynb
137+
# %% ../nbs/04_docments.ipynb
138138
def qual_name(obj):
139139
"Get the qualified name of `obj`"
140140
if hasattr(obj,'__qualname__'): return obj.__qualname__
141141
if ismethod(obj): return f"{get_name(obj.__self__)}.{get_name(fn)}"
142142
return get_name(obj)
143143

144-
# %% ../nbs/06_docments.ipynb
144+
# %% ../nbs/04_docments.ipynb
145145
def _docments(s, returns=True, eval_str=False, args_kwargs=False):
146146
"`dict` of parameter names to 'docment-style' comments in function or string `s`"
147147
nps = parse_docstring(s)
@@ -160,7 +160,7 @@ def _docments(s, returns=True, eval_str=False, args_kwargs=False):
160160
if k in hints: v['anno'] = hints.get(k)
161161
return res
162162

163-
# %% ../nbs/06_docments.ipynb
163+
# %% ../nbs/04_docments.ipynb
164164
@delegates(_docments)
165165
def docments(elt, full=False, args_kwargs=False, **kwargs):
166166
"Generates a `docment`"
@@ -178,7 +178,7 @@ def _update_docments(f, r):
178178
if not full: r = {k:v['docment'] for k,v in r.items()}
179179
return AttrDict(r)
180180

181-
# %% ../nbs/06_docments.ipynb
181+
# %% ../nbs/04_docments.ipynb
182182
def _get_params(node):
183183
params = [a.arg for a in node.args.args]
184184
if node.args.vararg: params.append(f"*{node.args.vararg.arg}")
@@ -215,7 +215,7 @@ def visit_Module(self, node):
215215
if module_doc: self.docstrings['_module'] = (module_doc, "")
216216
self.generic_visit(node)
217217

218-
# %% ../nbs/06_docments.ipynb
218+
# %% ../nbs/04_docments.ipynb
219219
def extract_docstrings(code):
220220
"Create a dict from function/class/method names to tuples of docstrings and param lists"
221221
extractor = _DocstringExtractor()

fastcore/meta.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
"""Metaclasses"""
22

3-
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/07_meta.ipynb.
3+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/05_meta.ipynb.
44

55
# %% auto 0
66
__all__ = ['test_sig', 'FixSigMeta', 'PrePostInitMeta', 'AutoInit', 'NewChkMeta', 'BypassNewMeta', 'empty2none', 'anno_dict',
77
'use_kwargs_dict', 'use_kwargs', 'delegates', 'method', 'funcs_kwargs']
88

9-
# %% ../nbs/07_meta.ipynb
9+
# %% ../nbs/05_meta.ipynb
1010
from .imports import *
1111
from .test import *
1212
from contextlib import contextmanager
1313
from copy import copy
1414
import inspect
1515

16-
# %% ../nbs/07_meta.ipynb
16+
# %% ../nbs/05_meta.ipynb
1717
def test_sig(f, b):
1818
"Test the signature of an object"
1919
test_eq(str(inspect.signature(f)), b)
2020

21-
# %% ../nbs/07_meta.ipynb
21+
# %% ../nbs/05_meta.ipynb
2222
def _rm_self(sig):
2323
sigd = dict(sig.parameters)
2424
sigd.pop('self')
2525
return sig.replace(parameters=sigd.values())
2626

27-
# %% ../nbs/07_meta.ipynb
27+
# %% ../nbs/05_meta.ipynb
2828
class FixSigMeta(type):
2929
"A metaclass that fixes the signature on classes that override `__new__`"
3030
def __new__(cls, name, bases, dict):
3131
res = super().__new__(cls, name, bases, dict)
3232
if res.__init__ is not object.__init__: res.__signature__ = _rm_self(inspect.signature(res.__init__))
3333
return res
3434

35-
# %% ../nbs/07_meta.ipynb
35+
# %% ../nbs/05_meta.ipynb
3636
class PrePostInitMeta(FixSigMeta):
3737
"A metaclass that calls optional `__pre_init__` and `__post_init__` methods"
3838
def __call__(cls, *args, **kwargs):
@@ -43,20 +43,20 @@ def __call__(cls, *args, **kwargs):
4343
if hasattr(res,'__post_init__'): res.__post_init__(*args,**kwargs)
4444
return res
4545

46-
# %% ../nbs/07_meta.ipynb
46+
# %% ../nbs/05_meta.ipynb
4747
class AutoInit(metaclass=PrePostInitMeta):
4848
"Same as `object`, but no need for subclasses to call `super().__init__`"
4949
def __pre_init__(self, *args, **kwargs): super().__init__(*args, **kwargs)
5050

51-
# %% ../nbs/07_meta.ipynb
51+
# %% ../nbs/05_meta.ipynb
5252
class NewChkMeta(FixSigMeta):
5353
"Metaclass to avoid recreating object passed to constructor"
5454
def __call__(cls, x=None, *args, **kwargs):
5555
if not args and not kwargs and x is not None and isinstance(x,cls): return x
5656
res = super().__call__(*((x,) + args), **kwargs)
5757
return res
5858

59-
# %% ../nbs/07_meta.ipynb
59+
# %% ../nbs/05_meta.ipynb
6060
class BypassNewMeta(FixSigMeta):
6161
"Metaclass: casts `x` to this class if it's of type `cls._bypass_type`"
6262
def __call__(cls, x=None, *args, **kwargs):
@@ -66,20 +66,20 @@ def __call__(cls, x=None, *args, **kwargs):
6666
if cls!=x.__class__: x.__class__ = cls
6767
return x
6868

69-
# %% ../nbs/07_meta.ipynb
69+
# %% ../nbs/05_meta.ipynb
7070
def empty2none(p):
7171
"Replace `Parameter.empty` with `None`"
7272
return None if p==inspect.Parameter.empty else p
7373

74-
# %% ../nbs/07_meta.ipynb
74+
# %% ../nbs/05_meta.ipynb
7575
def anno_dict(f):
7676
"`__annotation__ dictionary with `empty` cast to `None`, returning empty if doesn't exist"
7777
return {k:empty2none(v) for k,v in getattr(f, '__annotations__', {}).items()}
7878

79-
# %% ../nbs/07_meta.ipynb
79+
# %% ../nbs/05_meta.ipynb
8080
def _mk_param(n,d=None): return inspect.Parameter(n, inspect.Parameter.KEYWORD_ONLY, default=d)
8181

82-
# %% ../nbs/07_meta.ipynb
82+
# %% ../nbs/05_meta.ipynb
8383
def use_kwargs_dict(keep=False, **kwargs):
8484
"Decorator: replace `**kwargs` in signature with `names` params"
8585
def _f(f):
@@ -93,7 +93,7 @@ def _f(f):
9393
return f
9494
return _f
9595

96-
# %% ../nbs/07_meta.ipynb
96+
# %% ../nbs/05_meta.ipynb
9797
def use_kwargs(names, keep=False):
9898
"Decorator: replace `**kwargs` in signature with `names` params"
9999
def _f(f):
@@ -107,7 +107,7 @@ def _f(f):
107107
return f
108108
return _f
109109

110-
# %% ../nbs/07_meta.ipynb
110+
# %% ../nbs/05_meta.ipynb
111111
def delegates(to:FunctionType=None, # Delegatee
112112
keep=False, # Keep `kwargs` in decorated function?
113113
but:list=None, # Exclude these parameters from signature
@@ -135,13 +135,13 @@ def _f(f):
135135
return f
136136
return _f
137137

138-
# %% ../nbs/07_meta.ipynb
138+
# %% ../nbs/05_meta.ipynb
139139
def method(f):
140140
"Mark `f` as a method"
141141
# `1` is a dummy instance since Py3 doesn't allow `None` any more
142142
return MethodType(f, 1)
143143

144-
# %% ../nbs/07_meta.ipynb
144+
# %% ../nbs/05_meta.ipynb
145145
def _funcs_kwargs(cls, as_method):
146146
old_init = cls.__init__
147147
def _init(self, *args, **kwargs):
@@ -157,7 +157,7 @@ def _init(self, *args, **kwargs):
157157
if hasattr(cls, '__signature__'): cls.__signature__ = _rm_self(inspect.signature(cls.__init__))
158158
return cls
159159

160-
# %% ../nbs/07_meta.ipynb
160+
# %% ../nbs/05_meta.ipynb
161161
def funcs_kwargs(as_method=False):
162162
"Replace methods in `cls._methods` with those from `kwargs`"
163163
if callable(as_method): return _funcs_kwargs(as_method, False)

0 commit comments

Comments
 (0)