|
16 | 16 | ic = lambda *a: None if not a else (a[0] if len(a) == 1 else a) # noqa |
17 | 17 | __all__ = ['arange', 'edges', 'units', 'DEBUG'] |
18 | 18 |
|
19 | | -# Important private helper func |
20 | | -def _notNone(*args, names=None): |
21 | | - """Returns the first non-``None`` value, used with keyword arg aliases and |
22 | | - for setting default values. Ugly name but clear purpose. Pass the `names` |
23 | | - keyword arg to issue warning if multiple args were passed. Must be list |
24 | | - of non-empty strings.""" |
25 | | - if names is None: |
26 | | - for arg in args: |
27 | | - if arg is not None: |
28 | | - return arg |
29 | | - return arg # last one |
30 | | - else: |
31 | | - ret = {} |
32 | | - first = None |
33 | | - if len(names) != len(args) - 1: |
34 | | - raise ValueError(f'Need {len(args)+1} names for {len(args)} args, but got {len(names)} names.') |
35 | | - names = [*names, ''] |
36 | | - for name,arg in zip(names,args): |
37 | | - if arg is not None: |
38 | | - if first is None: |
39 | | - first = arg |
40 | | - if name: |
41 | | - ret[name] = arg |
42 | | - if len(ret)>1: |
43 | | - warnings.warn(f'Got conflicting or duplicate keyword args, using the first one: {ret}') |
44 | | - return first |
45 | | - |
46 | 19 | # Debug decorators |
47 | 20 | DEBUG = False # debug mode, used for profiling and activating timer decorators |
48 | 21 | def _logger(func): |
@@ -86,6 +59,33 @@ def decorator(*args, **kwargs): |
86 | 59 | decorator.count = 0 # initialize |
87 | 60 | return decorator |
88 | 61 |
|
| 62 | +# Important private helper func |
| 63 | +def _notNone(*args, names=None): |
| 64 | + """Returns the first non-``None`` value, used with keyword arg aliases and |
| 65 | + for setting default values. Ugly name but clear purpose. Pass the `names` |
| 66 | + keyword arg to issue warning if multiple args were passed. Must be list |
| 67 | + of non-empty strings.""" |
| 68 | + if names is None: |
| 69 | + for arg in args: |
| 70 | + if arg is not None: |
| 71 | + return arg |
| 72 | + return arg # last one |
| 73 | + else: |
| 74 | + first = None |
| 75 | + kwargs = {} |
| 76 | + if len(names) != len(args) - 1: |
| 77 | + raise ValueError(f'Need {len(args)+1} names for {len(args)} args, but got {len(names)} names.') |
| 78 | + names = [*names, ''] |
| 79 | + for name,arg in zip(names,args): |
| 80 | + if arg is not None: |
| 81 | + if first is None: |
| 82 | + first = arg |
| 83 | + if name: |
| 84 | + kwargs[name] = arg |
| 85 | + if len(kwargs)>1: |
| 86 | + warnings.warn(f'Got conflicting or duplicate keyword args, using the first one: {kwargs}') |
| 87 | + return first |
| 88 | + |
89 | 89 | # Accessible for user |
90 | 90 | def arange(min_, *args): |
91 | 91 | """Identical to `numpy.arange`, but with inclusive endpoints. For |
|
0 commit comments