diff --git a/fastship/maker.py b/fastship/maker.py index 5903f23..3203acb 100644 --- a/fastship/maker.py +++ b/fastship/maker.py @@ -15,7 +15,7 @@ from fastcore.basics import * from fastcore.imports import * from fastcore.nbio import * -from fastcore.pyparse import parse_py +from fastcore.pyparse import parse_py, patch_targets import ast @@ -46,7 +46,7 @@ def make_all(self:ModuleMaker, cells): # NB: "_all_" can include strings (names), or symbols, so we look for "id" or "value" all_vals = [v for o in trees if isinstance(o, (ast.Assign, ast.AnnAssign, ast.AugAssign)) and getattr(o.targets[0] if isinstance(o, ast.Assign) else o.target, 'id', None)=='_all_' for v in _val_or_id(o)] - syms = [d.name for d in m.defs if d.is_public and not any(dec.startswith('patch') for dec in d.decos)] + syms = [d.name for d in m.defs if d.is_public and not patch_targets(d)] assigns = [nm for nm in m.assigns if not nm.startswith('_')] return L(assigns + syms + all_vals).unique() diff --git a/pyproject.toml b/pyproject.toml index 16592fb..77ad5ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ dependencies = [ "aihist>=0.1.2", "execnb>=0.4.1", "fast5ever>=0.1.7", - "fastcore>=2.3.18", + "fastcore>=2.3.19", "fastgit>=0.1.0", "ghapi>=2.1.4", "mdhtml[fill,hl]>=0.1.59", diff --git a/ship/api/01_maker.ipynb b/ship/api/01_maker.ipynb index 3daff80..a79c094 100644 --- a/ship/api/01_maker.ipynb +++ b/ship/api/01_maker.ipynb @@ -39,7 +39,7 @@ "from fastcore.basics import *\n", "from fastcore.imports import *\n", "from fastcore.nbio import *\n", - "from fastcore.pyparse import parse_py\n", + "from fastcore.pyparse import parse_py, patch_targets\n", "\n", "import ast\n", "\n", @@ -147,7 +147,7 @@ " # NB: \"_all_\" can include strings (names), or symbols, so we look for \"id\" or \"value\"\n", " all_vals = [v for o in trees if isinstance(o, (ast.Assign, ast.AnnAssign, ast.AugAssign))\n", " and getattr(o.targets[0] if isinstance(o, ast.Assign) else o.target, 'id', None)=='_all_' for v in _val_or_id(o)]\n", - " syms = [d.name for d in m.defs if d.is_public and not any(dec.startswith('patch') for dec in d.decos)]\n", + " syms = [d.name for d in m.defs if d.is_public and not patch_targets(d)]\n", " assigns = [nm for nm in m.assigns if not nm.startswith('_')]\n", " return L(assigns + syms + all_vals).unique()" ] @@ -182,8 +182,9 @@ "outputs": [], "source": [ "nb = make_code_cells(\"from __future__ import print_function\", \"def a():...\", \"def b():...\",\n", - " \"c=d=1\", \"_f=1\", \"_g=1\", \"_h=1\", \"_all_=['_g', _h]\", \"@patch\\ndef h(self:ca):...\")\n", - "test_eq(set(mm.make_all(nb)), set(['a','b','c','d', '_g', '_h']))" + " \"c=d=1\", \"_f=1\", \"_g=1\", \"_h=1\", \"_all_=['_g', _h]\", \"@patch\\ndef h(self:ca):...\",\n", + " \"@patch_to(ca)\\ndef r(self):...\", \"@app.patch('/x')\\ndef p(req:Req):...\", \"@app.patch\\ndef q(req:Req):...\")\n", + "test_eq(set(mm.make_all(nb)), set(['a','b','c','d', '_g', '_h', 'p', 'q']))" ] }, {