diff options
author | Tim Peters <tim.peters@gmail.com> | 2006-05-10 02:43:01 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2006-05-10 02:43:01 (GMT) |
commit | ad2ef33245bdd90bf0e80824dbba732b17fdf6b6 (patch) | |
tree | 7ba86f8d781849d7d8c2b536dd848368bda2f71f | |
parent | 40f55b2f08c89cedb03b9af7fc3e5e2ffe68e219 (diff) | |
download | cpython-ad2ef33245bdd90bf0e80824dbba732b17fdf6b6.zip cpython-ad2ef33245bdd90bf0e80824dbba732b17fdf6b6.tar.gz cpython-ad2ef33245bdd90bf0e80824dbba732b17fdf6b6.tar.bz2 |
Variant of patch #1478292. doctest.register_optionflag(name)
shouldn't create a new flag when `name` is already the name of
an option flag.
-rw-r--r-- | Lib/doctest.py | 5 | ||||
-rw-r--r-- | Lib/test/test_doctest.py | 20 | ||||
-rw-r--r-- | Misc/NEWS | 5 |
3 files changed, 26 insertions, 4 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py index 900d871..318b21d 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -129,9 +129,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') diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py index d39aa42..443c962 100644 --- a/Lib/test/test_doctest.py +++ b/Lib/test/test_doctest.py @@ -1300,6 +1300,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""" @@ -67,7 +67,7 @@ Core and builtins Extension Modules ----------------- -- Use Win32 API to implement os.{access,chdir,chmod,mkdir,remove,rename,rmdir,utime}. +- Use Win32 API to implement os.{access,chdir,chmod,mkdir,remove,rename,rmdir,utime}. As a result, these functions now raise WindowsError instead of OSError. - Calling Tk_Init twice is refused if the first call failed as that @@ -96,6 +96,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 #1385040: don't allow "def foo(a=1, b): pass" in the compiler package. |