mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	Issue #9136: Profiling Decimal gave 'dictionary changed size during iteration'.
Remove the use of locals() that caused this error.
This commit is contained in:
		
							parent
							
								
									e42f1bb354
								
							
						
					
					
						commit
						0dd8f7890a
					
				
					 2 changed files with 35 additions and 13 deletions
				
			
		| 
						 | 
					@ -3813,20 +3813,38 @@ def __init__(self, prec=None, rounding=None,
 | 
				
			||||||
                 Emin=None, Emax=None,
 | 
					                 Emin=None, Emax=None,
 | 
				
			||||||
                 capitals=None, clamp=None,
 | 
					                 capitals=None, clamp=None,
 | 
				
			||||||
                 _ignored_flags=None):
 | 
					                 _ignored_flags=None):
 | 
				
			||||||
        if flags is None:
 | 
					        # Set defaults; for everything except flags and _ignored_flags,
 | 
				
			||||||
            flags = []
 | 
					        # inherit from DefaultContext.
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            dc = DefaultContext
 | 
				
			||||||
 | 
					        except NameError:
 | 
				
			||||||
 | 
					            pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.prec = prec if prec is not None else dc.prec
 | 
				
			||||||
 | 
					        self.rounding = rounding if rounding is not None else dc.rounding
 | 
				
			||||||
 | 
					        self.Emin = Emin if Emin is not None else dc.Emin
 | 
				
			||||||
 | 
					        self.Emax = Emax if Emax is not None else dc.Emax
 | 
				
			||||||
 | 
					        self.capitals = capitals if capitals is not None else dc.capitals
 | 
				
			||||||
 | 
					        self.clamp = clamp if clamp is not None else dc.clamp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if _ignored_flags is None:
 | 
					        if _ignored_flags is None:
 | 
				
			||||||
            _ignored_flags = []
 | 
					            self._ignored_flags = []
 | 
				
			||||||
        if not isinstance(flags, dict):
 | 
					        else:
 | 
				
			||||||
            flags = dict([(s, int(s in flags)) for s in _signals])
 | 
					            self._ignored_flags = _ignored_flags
 | 
				
			||||||
        if traps is not None and not isinstance(traps, dict):
 | 
					
 | 
				
			||||||
            traps = dict([(s, int(s in traps)) for s in _signals])
 | 
					        if traps is None:
 | 
				
			||||||
        for name, val in locals().items():
 | 
					            self.traps = dc.traps.copy()
 | 
				
			||||||
            if val is None:
 | 
					        elif not isinstance(traps, dict):
 | 
				
			||||||
                setattr(self, name, _copy.copy(getattr(DefaultContext, name)))
 | 
					            self.traps = dict((s, int(s in traps)) for s in _signals)
 | 
				
			||||||
            else:
 | 
					        else:
 | 
				
			||||||
                setattr(self, name, val)
 | 
					            self.traps = traps
 | 
				
			||||||
        del self.self
 | 
					
 | 
				
			||||||
 | 
					        if flags is None:
 | 
				
			||||||
 | 
					            self.flags = dict.fromkeys(_signals, 0)
 | 
				
			||||||
 | 
					        elif not isinstance(flags, dict):
 | 
				
			||||||
 | 
					            self.flags = dict((s, int(s in flags)) for s in _signals)
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            self.flags = flags
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __repr__(self):
 | 
					    def __repr__(self):
 | 
				
			||||||
        """Show the current context."""
 | 
					        """Show the current context."""
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -470,6 +470,10 @@ C-API
 | 
				
			||||||
Library
 | 
					Library
 | 
				
			||||||
-------
 | 
					-------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- Issue #9136: Fix 'dictionary changed size during iteration'
 | 
				
			||||||
 | 
					  RuntimeError produced when profiling the decimal module.  This was
 | 
				
			||||||
 | 
					  due to a dangerous iteration over 'locals()' in Context.__init__.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fix extreme speed issue in Decimal.pow when the base is an exact
 | 
					- Fix extreme speed issue in Decimal.pow when the base is an exact
 | 
				
			||||||
  power of 10 and the exponent is tiny (for example,
 | 
					  power of 10 and the exponent is tiny (for example,
 | 
				
			||||||
  Decimal(10) ** Decimal('1e-999999999')).
 | 
					  Decimal(10) ** Decimal('1e-999999999')).
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue