summaryrefslogtreecommitdiffstats
path: root/Lib/decimal.py
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-07-08 21:18:21 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2010-07-08 21:18:21 (GMT)
commit921d30d2611c3efb5dd7081d93d02415da5b49ea (patch)
tree82ca7af26d9acc0109ee0902b18ba7690026e2b1 /Lib/decimal.py
parent0390f504ac81c9eb2b71eea81204284f01b200a2 (diff)
downloadcpython-921d30d2611c3efb5dd7081d93d02415da5b49ea.zip
cpython-921d30d2611c3efb5dd7081d93d02415da5b49ea.tar.gz
cpython-921d30d2611c3efb5dd7081d93d02415da5b49ea.tar.bz2
Merged revisions 82654 via svnmerge from
svn+ssh://pythondev@svn.python.org/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. ........
Diffstat (limited to 'Lib/decimal.py')
-rw-r--r--Lib/decimal.py44
1 files changed, 31 insertions, 13 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py
index 958b2f9..c61b549 100644
--- a/Lib/decimal.py
+++ b/Lib/decimal.py
@@ -3809,20 +3809,38 @@ class Context(object):
Emin=None, Emax=None,
capitals=None, _clamp=0,
_ignored_flags=None):
- if flags is None:
- flags = []
+ # Set defaults; for everything except flags and _ignored_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:
- _ignored_flags = []
- if not isinstance(flags, dict):
- flags = dict([(s, int(s in flags)) for s in _signals])
- if traps is not None and not isinstance(traps, dict):
- traps = dict([(s, int(s in traps)) for s in _signals])
- for name, val in locals().items():
- if val is None:
- setattr(self, name, _copy.copy(getattr(DefaultContext, name)))
- else:
- setattr(self, name, val)
- del self.self
+ self._ignored_flags = []
+ else:
+ self._ignored_flags = _ignored_flags
+
+ if traps is None:
+ self.traps = dc.traps.copy()
+ elif not isinstance(traps, dict):
+ self.traps = dict((s, int(s in traps)) for s in _signals)
+ else:
+ self.traps = traps
+
+ 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):
"""Show the current context."""