2020import math
2121import random
2222import re
23+
2324try :
2425 from collections import OrderedDict
2526except ImportError :
@@ -54,12 +55,6 @@ def __len__(self):
5455from histogrammar .pycparser import c_ast
5556import histogrammar .version
5657
57- try :
58- import histogrammar .specialized
59- spec = True
60- except (ImportError , AttributeError ):
61- spec = False
62-
6358
6459class ContainerException (Exception ):
6560 """Exception type for improperly configured containers."""
@@ -122,10 +117,13 @@ def specialize(self):
122117 since they are created before the histogrammar.specialized module can be defined.
123118 These objects wouldn't satisfy any of ``addImplicitMethod``'s checks anyway.
124119 """
125- if spec :
120+ try :
126121 # MB 20220517: warning, this is a slow function.
127122 # Adding functions to each object, ideally avoid this.
123+ import histogrammar .specialized
128124 histogrammar .specialized .addImplicitMethods (self )
125+ except (ImportError , AttributeError ):
126+ pass
129127
130128 self .fill = FillMethod (self , self .fill )
131129 self .plot = PlotMethod (self , self .plot )
@@ -237,6 +235,7 @@ def plot(self, httpServer=None, **parameters):
237235 raise NotImplementedError
238236
239237 def __getstate__ (self ):
238+ # used by pickling
240239 state = dict (self .__dict__ )
241240 for s in ['fill' , 'plot' ]:
242241 # these states are set dynamically by FillMethod and PlotMethod, in factory.specialize().
@@ -247,6 +246,7 @@ def __getstate__(self):
247246 return state
248247
249248 def __setstate__ (self , dict ):
249+ # used by unpickling
250250 self .__dict__ = dict
251251 self .fill = FillMethod (self , self .fill )
252252 self .plot = PlotMethod (self , self .plot )
0 commit comments