[Python-checkins] python/dist/src/Lib doctest.py,1.103,1.104

edloper at users.sourceforge.net edloper at users.sourceforge.net
Mon Sep 13 07:47:26 CEST 2004


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32413/dist/src/Lib

Modified Files:
	doctest.py 
Log Message:
Added new parameter exclude_empty to DocTestFinder.__init__, which
controls whether tests are included for objects with empty docstrings.
Defaults to True, to match the behavior of Python 2.3.


Index: doctest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/doctest.py,v
retrieving revision 1.103
retrieving revision 1.104
diff -u -d -r1.103 -r1.104
--- doctest.py	13 Sep 2004 01:07:12 -0000	1.103
+++ doctest.py	13 Sep 2004 05:47:24 -0000	1.104
@@ -848,7 +848,8 @@
     """
 
     def __init__(self, verbose=False, parser=DocTestParser(),
-                 recurse=True, _namefilter=None):
+                 recurse=True, _namefilter=None,
+                 exclude_empty=False):
         """
         Create a new doctest finder.
 
@@ -860,10 +861,14 @@
 
         If the optional argument `recurse` is false, then `find` will
         only examine the given object, and not any contained objects.
+
+        If the optional argument `exclude_empty` is true, then `find`
+        will exclude tests for objects with empty docstrings.
         """
         self._parser = parser
         self._verbose = verbose
         self._recurse = recurse
+        self._exclude_empty = exclude_empty
         # _namefilter is undocumented, and exists only for temporary backward-
         # compatibility support of testmod's deprecated isprivate mess.
         self._namefilter = _namefilter
@@ -1055,18 +1060,19 @@
         else:
             try:
                 if obj.__doc__ is None:
-                    return None
-                docstring = str(obj.__doc__)
+                    docstring = ''
+                else:
+                    docstring = str(obj.__doc__)
             except (TypeError, AttributeError):
-                return None
-
-        # Don't bother if the docstring is empty.
-        if not docstring:
-            return None
+                docstring = ''
 
         # Find the docstring's location in the file.
         lineno = self._find_lineno(obj, source_lines)
 
+        # Don't bother if the docstring is empty.
+        if self._exclude_empty and not docstring:
+            return None
+
         # Return a DocTest for this object.
         if module is None:
             filename = None



More information about the Python-checkins mailing list