mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	Variant of patch #1478292. doctest.register_optionflag(name)
shouldn't create a new flag when `name` is already the name of an option flag.
This commit is contained in:
		
							parent
							
								
									40f55b2f08
								
							
						
					
					
						commit
						ad2ef33245
					
				
					 3 changed files with 26 additions and 4 deletions
				
			
		| 
						 | 
					@ -129,9 +129,8 @@ def _test():
 | 
				
			||||||
 | 
					
 | 
				
			||||||
OPTIONFLAGS_BY_NAME = {}
 | 
					OPTIONFLAGS_BY_NAME = {}
 | 
				
			||||||
def register_optionflag(name):
 | 
					def register_optionflag(name):
 | 
				
			||||||
    flag = 1 << len(OPTIONFLAGS_BY_NAME)
 | 
					    # Create a new flag unless `name` is already known.
 | 
				
			||||||
    OPTIONFLAGS_BY_NAME[name] = flag
 | 
					    return OPTIONFLAGS_BY_NAME.setdefault(name, 1 << len(OPTIONFLAGS_BY_NAME))
 | 
				
			||||||
    return flag
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
DONT_ACCEPT_TRUE_FOR_1 = register_optionflag('DONT_ACCEPT_TRUE_FOR_1')
 | 
					DONT_ACCEPT_TRUE_FOR_1 = register_optionflag('DONT_ACCEPT_TRUE_FOR_1')
 | 
				
			||||||
DONT_ACCEPT_BLANKLINE = register_optionflag('DONT_ACCEPT_BLANKLINE')
 | 
					DONT_ACCEPT_BLANKLINE = register_optionflag('DONT_ACCEPT_BLANKLINE')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1300,6 +1300,26 @@ def optionflags(): r"""
 | 
				
			||||||
        ValueError: 2
 | 
					        ValueError: 2
 | 
				
			||||||
    (3, 5)
 | 
					    (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"""
 | 
					    def option_directives(): r"""
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -96,6 +96,9 @@ Extension Modules
 | 
				
			||||||
Library
 | 
					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
 | 
					- Bug #1385040: don't allow "def foo(a=1, b): pass" in the compiler
 | 
				
			||||||
  package.
 | 
					  package.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue