Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 921d30d

Browse files
committed
Merged revisions 82654 via svnmerge from
svn+ssh://[email protected]/python/branches/py3k ........ r82654 | mark.dickinson | 2010-07-08 22:15:36 +0100 (Thu, 08 Jul 2010) | 3 lines Issue #9136: Profiling Decimal gave 'dictionary changed size during iteration'. Remove the use of locals() that caused this error. ........
1 parent 0390f50 commit 921d30d

2 files changed

Lines changed: 35 additions & 13 deletions

File tree

Lib/decimal.py

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3809,20 +3809,38 @@ def __init__(self, prec=None, rounding=None,
38093809
Emin=None, Emax=None,
38103810
capitals=None, _clamp=0,
38113811
_ignored_flags=None):
3812-
if flags is None:
3813-
flags = []
3812+
# Set defaults; for everything except flags and _ignored_flags,
3813+
# inherit from DefaultContext.
3814+
try:
3815+
dc = DefaultContext
3816+
except NameError:
3817+
pass
3818+
3819+
self.prec = prec if prec is not None else dc.prec
3820+
self.rounding = rounding if rounding is not None else dc.rounding
3821+
self.Emin = Emin if Emin is not None else dc.Emin
3822+
self.Emax = Emax if Emax is not None else dc.Emax
3823+
self.capitals = capitals if capitals is not None else dc.capitals
3824+
self._clamp = _clamp if _clamp is not None else dc._clamp
3825+
38143826
if _ignored_flags is None:
3815-
_ignored_flags = []
3816-
if not isinstance(flags, dict):
3817-
flags = dict([(s, int(s in flags)) for s in _signals])
3818-
if traps is not None and not isinstance(traps, dict):
3819-
traps = dict([(s, int(s in traps)) for s in _signals])
3820-
for name, val in locals().items():
3821-
if val is None:
3822-
setattr(self, name, _copy.copy(getattr(DefaultContext, name)))
3823-
else:
3824-
setattr(self, name, val)
3825-
del self.self
3827+
self._ignored_flags = []
3828+
else:
3829+
self._ignored_flags = _ignored_flags
3830+
3831+
if traps is None:
3832+
self.traps = dc.traps.copy()
3833+
elif not isinstance(traps, dict):
3834+
self.traps = dict((s, int(s in traps)) for s in _signals)
3835+
else:
3836+
self.traps = traps
3837+
3838+
if flags is None:
3839+
self.flags = dict.fromkeys(_signals, 0)
3840+
elif not isinstance(flags, dict):
3841+
self.flags = dict((s, int(s in flags)) for s in _signals)
3842+
else:
3843+
self.flags = flags
38263844

38273845
def __repr__(self):
38283846
"""Show the current context."""

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ C-API
7575
Library
7676
-------
7777

78+
- Issue #9136: Fix 'dictionary changed size during iteration'
79+
RuntimeError produced when profiling the decimal module. This was
80+
due to a dangerous iteration over 'locals()' in Context.__init__.
81+
7882
- Fix extreme speed issue in Decimal.pow when the base is an exact
7983
power of 10 and the exponent is tiny (for example,
8084
Decimal(10) ** Decimal('1e-999999999')).

0 commit comments

Comments
 (0)