Skip to content

Commit e74acc3

Browse files
committed
Minor utils changes
1 parent 64015f7 commit e74acc3

File tree

2 files changed

+29
-28
lines changed

2 files changed

+29
-28
lines changed

proplot/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def _warning_proplot(message, category, filename, lineno, line=None):
3535
# WARNING: Import order is meaningful! Loads modules that are dependencies
3636
# of other modules last, and loads styletools early so we can try to update
3737
# TTFPATH before the fontManager is loaded by other matplotlib modules
38-
from .utils import * # misc stuff, debug mode
38+
from .utils import DEBUG
39+
from .utils import *
3940
if DEBUG:
4041
import time
4142
t = time.clock()

proplot/utils.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,6 @@
1616
ic = lambda *a: None if not a else (a[0] if len(a) == 1 else a) # noqa
1717
__all__ = ['arange', 'edges', 'units', 'DEBUG']
1818

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-
4619
# Debug decorators
4720
DEBUG = False # debug mode, used for profiling and activating timer decorators
4821
def _logger(func):
@@ -86,6 +59,33 @@ def decorator(*args, **kwargs):
8659
decorator.count = 0 # initialize
8760
return decorator
8861

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+
8989
# Accessible for user
9090
def arange(min_, *args):
9191
"""Identical to `numpy.arange`, but with inclusive endpoints. For

0 commit comments

Comments
 (0)