]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merge rev 45944 from trunk.
authorTim Peters <tim.peters@gmail.com>
Wed, 10 May 2006 02:46:48 +0000 (02:46 +0000)
committerTim Peters <tim.peters@gmail.com>
Wed, 10 May 2006 02:46:48 +0000 (02:46 +0000)
Variant of patch #1478292.  doctest.register_optionflag(name)
shouldn't create a new flag when `name` is already the name of
an option flag.

Lib/doctest.py
Lib/test/test_doctest.py
Misc/NEWS

index 642b5223b906d6e8e7a34f5f6db0396981eed167..d146a83459d54d52727bd85e54aa0cb31ee627a3 100644 (file)
@@ -128,9 +128,8 @@ warnings.filterwarnings("ignore", "is_private", DeprecationWarning,
 
 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')
index 1665c05414e2160684e10e96cfbcbcb1cc840a04..36ffec906f9987b019a193e26fddd9dff89056ba 100644 (file)
@@ -1281,6 +1281,26 @@ count as failures:
         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"""
index 593a881df60457d2e2ad4ce9ace2ee1c61e08cee..5adfc11787415a5041b80e5a970edcc6d0685a85 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -32,6 +32,9 @@ Extension Modules
 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.