summaryrefslogtreecommitdiff
path: root/Lib/doctest.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2006-05-10 02:43:01 +0000
committerTim Peters <tim.peters@gmail.com>2006-05-10 02:43:01 +0000
commitad2ef33245bdd90bf0e80824dbba732b17fdf6b6 (patch)
tree7ba86f8d781849d7d8c2b536dd848368bda2f71f /Lib/doctest.py
parent40f55b2f08c89cedb03b9af7fc3e5e2ffe68e219 (diff)
downloadcpython-git-ad2ef33245bdd90bf0e80824dbba732b17fdf6b6.tar.gz
Variant of patch #1478292. doctest.register_optionflag(name)
shouldn't create a new flag when `name` is already the name of an option flag.
Diffstat (limited to 'Lib/doctest.py')
-rw-r--r--Lib/doctest.py5
1 files changed, 2 insertions, 3 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py
index 900d8718f9..318b21df54 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')