@@ -167,8 +167,11 @@ def __exit__(self, exc_type, exc_val, exc_tb):
167167class _CachedProperty (object ):
168168 def __init__ (self , func ):
169169 self .func = func
170+ self .__doc__ = func .__doc__
170171
171172 def __get__ (self , obj , cls ):
173+ if obj is None :
174+ return self
172175 value = obj .__dict__ [self .func .__name__ ] = self .func (obj )
173176 return value
174177
@@ -192,18 +195,30 @@ def __init__(self, frame, kind, arg, tracer):
192195
193196 @_CachedProperty
194197 def locals (self ):
198+ """
199+ A dict with local variables.
200+ """
195201 return self .frame .f_locals
196202
197203 @_CachedProperty
198204 def globals (self ):
205+ """
206+ A dict with global variables.
207+ """
199208 return self .frame .f_globals
200209
201210 @_CachedProperty
202211 def function (self ):
212+ """
213+ A string with function name.
214+ """
203215 return self .code .co_name
204216
205217 @_CachedProperty
206218 def module (self ):
219+ """
220+ A string with module name (eg: ``"foo.bar"``).
221+ """
207222 module = self .frame .f_globals .get ('__name__' , '' )
208223 if module is None :
209224 module = ''
@@ -212,6 +227,9 @@ def module(self):
212227
213228 @_CachedProperty
214229 def filename (self ):
230+ """
231+ A string with absolute path to file.
232+ """
215233 filename = self .frame .f_globals .get ('__file__' , '' )
216234 if filename is None :
217235 filename = ''
@@ -225,14 +243,23 @@ def filename(self):
225243
226244 @_CachedProperty
227245 def lineno (self ):
246+ """
247+ An integer with line number in file.
248+ """
228249 return self .frame .f_lineno
229250
230251 @_CachedProperty
231252 def code (self ):
253+ """
254+ A code object (not a string).
255+ """
232256 return self .frame .f_code
233257
234258 @_CachedProperty
235259 def stdlib (self ):
260+ """
261+ A boolean flag. ``True`` if frame is in stdlib.
262+ """
236263 if self .filename .startswith (SITE_PACKAGES_PATH ):
237264 # if it's in site-packages then its definitely not stdlib
238265 return False
@@ -242,7 +269,9 @@ def stdlib(self):
242269 @_CachedProperty
243270 def fullsource (self , getlines = linecache .getlines ):
244271 """
245- Get a line from ``linecache``. Ignores failures somewhat.
272+ A string with the sourcecode for the current statement (from ``linecache`` - failures are ignored).
273+
274+ May include multiple lines if it's a class/function definition (will include decorators).
246275 """
247276 try :
248277 return self ._raw_fullsource
@@ -251,6 +280,11 @@ def fullsource(self, getlines=linecache.getlines):
251280
252281 @_CachedProperty
253282 def source (self , getline = linecache .getline ):
283+ """
284+ A string with the sourcecode for the current line (from ``linecache`` - failures are ignored).
285+
286+ Fast but sometimes incomplete.
287+ """
254288 try :
255289 return getline (self .filename , self .lineno )
256290 except Exception as exc :
@@ -325,14 +359,19 @@ def Q(*predicates, **query):
325359class Query (Fields .query ):
326360 """
327361 A query class.
362+
363+ See :class:`hunter.Event` for fields that can be filtered on.
328364 """
329365 query = ()
330366 allowed = tuple (i for i in Event .__dict__ .keys () if not i .startswith ('_' ))
331367
332368 def __init__ (self , ** query ):
333369 """
334370 Args:
335- query: criteria to match on. Currently only 'function', 'module' or 'filename' are accepted.
371+ query: criteria to match on.
372+
373+ Accepted arguments: ``arg``, ``code``, ``filename``, ``frame``, ``fullsource``, ``function``,
374+ ``globals``, ``kind``, ``lineno``, ``locals``, ``module``, ``source``, ``stdlib``, ``tracer``.
336375 """
337376 for key in query :
338377 if key not in self .allowed :
0 commit comments