[Python-checkins] r45945 - in python/branches/release24-maint: Lib/doctest.py Lib/test/test_doctest.py Misc/NEWS

tim.peters python-checkins at python.org
Wed May 10 04:46:50 CEST 2006


Author: tim.peters
Date: Wed May 10 04:46:48 2006
New Revision: 45945

Modified:
   python/branches/release24-maint/Lib/doctest.py
   python/branches/release24-maint/Lib/test/test_doctest.py
   python/branches/release24-maint/Misc/NEWS
Log:
Merge rev 45944 from trunk.

Variant of patch #1478292.  doctest.register_optionflag(name)
shouldn't create a new flag when `name` is already the name of
an option flag.


Modified: python/branches/release24-maint/Lib/doctest.py
==============================================================================
--- python/branches/release24-maint/Lib/doctest.py	(original)
+++ python/branches/release24-maint/Lib/doctest.py	Wed May 10 04:46:48 2006
@@ -128,9 +128,8 @@
 
 OPTIONFLAGS_BY_NAME = {}
 def register_optionflag(name):
-    flag = 1 << len(OPTIONFLAGS_BY_NAME)
-    OPTIONFLAGS_BY_NAME[name] = flag
-    return flag
+    # Create a new flag unless `name` is already known.
+    return OPTIONFLAGS_BY_NAME.setdefault(name, 1 << len(OPTIONFLAGS_BY_NAME))
 
 DONT_ACCEPT_TRUE_FOR_1 = register_optionflag('DONT_ACCEPT_TRUE_FOR_1')
 DONT_ACCEPT_BLANKLINE = register_optionflag('DONT_ACCEPT_BLANKLINE')

Modified: python/branches/release24-maint/Lib/test/test_doctest.py
==============================================================================
--- python/branches/release24-maint/Lib/test/test_doctest.py	(original)
+++ python/branches/release24-maint/Lib/test/test_doctest.py	Wed May 10 04:46:48 2006
@@ -1281,6 +1281,26 @@
         ValueError: 2
     (3, 5)
 
+New option flags can also be registered, via register_optionflag().  Here
+we reach into doctest's internals a bit.
+
+    >>> unlikely = "UNLIKELY_OPTION_NAME"
+    >>> unlikely in doctest.OPTIONFLAGS_BY_NAME
+    False
+    >>> new_flag_value = doctest.register_optionflag(unlikely)
+    >>> unlikely in doctest.OPTIONFLAGS_BY_NAME
+    True
+
+Before 2.4.4/2.5, registering a name more than once erroneously created
+more than one flag value.  Here we verify that's fixed:
+
+    >>> redundant_flag_value = doctest.register_optionflag(unlikely)
+    >>> redundant_flag_value == new_flag_value
+    True
+
+Clean up.
+    >>> del doctest.OPTIONFLAGS_BY_NAME[unlikely]
+
     """
 
     def option_directives(): r"""

Modified: python/branches/release24-maint/Misc/NEWS
==============================================================================
--- python/branches/release24-maint/Misc/NEWS	(original)
+++ python/branches/release24-maint/Misc/NEWS	Wed May 10 04:46:48 2006
@@ -32,6 +32,9 @@
 Library
 -------
 
+- Patch #1478292. ``doctest.register_optionflag(name)`` shouldn't create a
+  new flag when ``name`` is already the name of an option flag.
+
 - Bug #1473760: ``tempfile.TemporaryFile()`` could hang on Windows, when
   called from a thread spawned as a side effect of importing a module.
 


More information about the Python-checkins mailing list