3 ms·
> If you look at something like numpy functions, so many of them share the exact same parameter definitions. What if you could write def log(standard-exp-params
by masklinn 4y ago
> If you look at something like numpy functions, so many of them share the exact same parameter definitions. What if you could write def log(standard-exp-params) instead of having to write them out every single time?
They're not actually written out every time, the issue is mostly documentary (and it would be nice if Python or Sphinx ever had a good solution). And numpy actually has a bunch of generators for that e.g. https://github.com/numpy/numpy/blob/45bc13e6d922690eea43b9d807d476e0f243f836/numpy/core/code_generators/ufunc_docstrings.py https://github.com/numpy/numpy/blob/45bc13e6d922690eea43b9d8... handles filling in the common bits of documentation for the ufuncs.
- PyWoody 4y agoI don't use Numpy but it sounds like they're describing *, ** operators. default_args = ('x', 'y', 'z') default_kwargs = {'p': 'p', 'q': 'q', 'r': 'r'} def printer(x, y, z, /, *, p, q, r): print(f'x={x} | y={y} | z={z} | p={p} | q={q} | r={r}') printer(*default_args, **default_kwargs) # x=x | y=y | z=z | p=p | q=q | r=r EDIT: Formatting.
- masklinn 4y agoYes but also that lacks most of the documentation so it's not great. If you have multiple callables taking these parameters documenting them is awkward, by default help/pydoc and sphinx will tell you that the parameters are `default_args` and `default_kwargs`, but that's not actually true, those are just intended as shortcuts / helpers .