mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	#10777: fix iteration over dict keys while mutating the dict.
This commit is contained in:
		
							parent
							
								
									ff52f76019
								
							
						
					
					
						commit
						90b20675bd
					
				
					 3 changed files with 13 additions and 1 deletions
				
			
		| 
						 | 
					@ -1841,6 +1841,15 @@ def check_issue6565():
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def check_issue10777():
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    Registering a namespace twice caused a "dictionary changed size during
 | 
				
			||||||
 | 
					    iteration" bug.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    >>> ET.register_namespace('test10777', 'http://myuri/')
 | 
				
			||||||
 | 
					    >>> ET.register_namespace('test10777', 'http://myuri/')
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# --------------------------------------------------------------------
 | 
					# --------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1068,7 +1068,7 @@ def _serialize_text(write, elem):
 | 
				
			||||||
def register_namespace(prefix, uri):
 | 
					def register_namespace(prefix, uri):
 | 
				
			||||||
    if re.match("ns\d+$", prefix):
 | 
					    if re.match("ns\d+$", prefix):
 | 
				
			||||||
        raise ValueError("Prefix format reserved for internal use")
 | 
					        raise ValueError("Prefix format reserved for internal use")
 | 
				
			||||||
    for k, v in _namespace_map.items():
 | 
					    for k, v in list(_namespace_map.items()):
 | 
				
			||||||
        if k == uri or v == prefix:
 | 
					        if k == uri or v == prefix:
 | 
				
			||||||
            del _namespace_map[k]
 | 
					            del _namespace_map[k]
 | 
				
			||||||
    _namespace_map[uri] = prefix
 | 
					    _namespace_map[uri] = prefix
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,6 +18,9 @@ Core and Builtins
 | 
				
			||||||
Library
 | 
					Library
 | 
				
			||||||
-------
 | 
					-------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- Issue #10777: Fix "dictionary changed size during iteration" bug in
 | 
				
			||||||
 | 
					  ElementTree register_namespace().
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Issue #10626: test_logging now preserves logger disabled states.
 | 
					- Issue #10626: test_logging now preserves logger disabled states.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Issue #10774: test_logging now removes temp files created during tests.
 | 
					- Issue #10774: test_logging now removes temp files created during tests.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue