@@ -111,15 +111,6 @@ def _determine_default_dataset_id(dataset_id=None):
111111 return dataset_id
112112
113113
114- def _lazy_dataset_id ():
115- """Alias wrapper for _determine_default_dataset_id.
116-
117- Unit test need to be able to replace _determine_default_dataset_id()
118- so we can't wrap the actual ``function`` object in a ``_LazyProperty``.
119- """
120- return _determine_default_dataset_id ()
121-
122-
123114def set_default_dataset_id (dataset_id = None ):
124115 """Set default dataset ID either explicitly or implicitly as fall-back.
125116
@@ -170,22 +161,40 @@ class _LazyProperty(object):
170161 :type name: string
171162 :param name: The name of the attribute / property being evaluated.
172163
173- :type method: callable that takes no arguments
174- :param method: The method used to evaluate the property.
164+ :type deferred_callable: callable that takes no arguments
165+ :param deferred_callable: The function / method used to evaluate the
166+ property.
175167 """
176168
177- def __init__ (self , name , method ):
169+ def __init__ (self , name , deferred_callable ):
178170 self ._name = name
179- self ._method = method
171+ self ._deferred_callable = deferred_callable
180172
181173 def __get__ (self , obj , objtype ):
182174 if obj is None or objtype is not _DefaultsContainer :
183175 return self
184176
185- setattr (obj , self ._name , self ._method ())
177+ setattr (obj , self ._name , self ._deferred_callable ())
186178 return getattr (obj , self ._name )
187179
188180
181+ def _lazy_property_deco (deferred_callable ):
182+ """Decorator a method to create a :class:`_LazyProperty`.
183+
184+ :type deferred_callable: callable that takes no arguments
185+ :param deferred_callable: The function / method used to evaluate the
186+ property.
187+
188+ :rtype: :class:`_LazyProperty`.
189+ :returns: A lazy property which defers the deferred_callable.
190+ """
191+ if isinstance (deferred_callable , staticmethod ):
192+ # H/T: http://stackoverflow.com/a/9527450/1068170
193+ # For Python2.7+ deferred_callable.__func__ would suffice.
194+ deferred_callable = deferred_callable .__get__ (True )
195+ return _LazyProperty (deferred_callable .__name__ , deferred_callable )
196+
197+
189198class _DefaultsContainer (object ):
190199 """Container for defaults.
191200
@@ -196,7 +205,11 @@ class _DefaultsContainer(object):
196205 :param dataset_id: Persistent implied dataset ID from environment.
197206 """
198207
199- dataset_id = _LazyProperty ('dataset_id' , _lazy_dataset_id )
208+ @_lazy_property_deco
209+ @staticmethod
210+ def dataset_id ():
211+ """Return the implicit default dataset ID."""
212+ return _determine_default_dataset_id ()
200213
201214 def __init__ (self , connection = None , dataset_id = None , implicit = False ):
202215 self .connection = connection
0 commit comments