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
commit8d570705be93ee14d658edc3794c44110009c736 (patch)
treeee692198bb7ffd68e2760005717ea76ec4093ee5 /Lib/doctest.py
parentefbe7d363cfbf1d759ba93199a44623228c2a75c (diff)
downloadcpython-8d570705be93ee14d658edc3794c44110009c736.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')