Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 55fa047

Browse files
committed
some more trickery in the Namespace class to aboid duplication of mod names
svn path=/trunk/matplotlib/; revision=3525
1 parent abcd40d commit 55fa047

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

lib/matplotlib/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,12 @@ class Namespace:
878878
A class which takes a list of modules and creates an object with
879879
the module naems at attrs
880880
"""
881-
def __init__(self, *modules):
882-
def make_key(x): return x.__name__.replace('matplotlib.', '')
883-
self.__dict__ = dict([(make_key(m), m) for m in modules])
881+
def __init__(self, namespace):
882+
for k,v in namespace.items():
883+
modname = getattr(v, '__name__', None)
884+
if modname is None: continue
885+
if modname.startswith('matplotlib.'):
886+
self.__dict__[modname.replace('matplotlib.', '')] = v
887+
888+
884889

lib/matplotlib/axes.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
contour, dates, font_manager, image, legend, lines, mlab, cm, \
1313
patches, quiver, table, text, ticker, transforms
1414

15-
mpl = matplotlib.Namespace(artist, agg, axis, cbook, collections, colors,
16-
contour, dates, font_manager, image, legend, lines, mlab, cm,
17-
patches, quiver, table, text, ticker, transforms )
15+
# put all the matplotlib modules in the local namespace into a single
16+
# namespace object to avoid ambiguity in references below, eg artist
17+
# becomes mpl.artist
18+
mpl = matplotlib.Namespace(locals())
1819

1920

2021
def delete_masked_points(*args):

0 commit comments

Comments
 (0)