Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
9fce44bc
Commit
9fce44bc
authored
Aug 08, 2004
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
* Context.copy() now makes a deepcopy.
* Facilitate reloads of local thread.
parent
161c9632
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
12 deletions
+21
-12
Lib/decimal.py
Lib/decimal.py
+21
-12
No files found.
Lib/decimal.py
View file @
9fce44bc
...
...
@@ -392,7 +392,7 @@ except AttributeError:
def
setcontext
(
context
):
"""Set this thread's context to context."""
if
context
in
(
DefaultContext
,
BasicContext
,
ExtendedContext
):
context
=
co
py
.
deepcopy
(
context
)
context
=
co
ntext
.
copy
(
)
context
.
clear_flags
()
threading
.
currentThread
().
__decimal_context__
=
context
...
...
@@ -413,6 +413,8 @@ except AttributeError:
else
:
local
=
threading
.
local
()
if
hasattr
(
local
,
'__decimal_context__'
):
del
local
.
__decimal_context__
def
getcontext
(
_local
=
local
):
"""Returns this thread's context.
...
...
@@ -431,7 +433,7 @@ else:
def
setcontext
(
context
,
_local
=
local
):
"""Set this thread's context to context."""
if
context
in
(
DefaultContext
,
BasicContext
,
ExtendedContext
):
context
=
co
py
.
deepcopy
(
context
)
context
=
co
ntext
.
copy
(
)
context
.
clear_flags
()
_local
.
__decimal_context__
=
context
...
...
@@ -642,7 +644,7 @@ class Decimal(object):
elif
self
.
adjusted
<
other
.
adjusted
()
and
other
.
_int
[
0
]
!=
0
:
return
-
((
-
1
)
**
self
.
_sign
)
context
=
context
.
copy
()
context
=
context
.
_shallow_
copy
()
rounding
=
context
.
_set_rounding
(
ROUND_UP
)
#round away from 0
flags
=
context
.
_ignore_all_flags
()
...
...
@@ -861,7 +863,7 @@ class Decimal(object):
return
ans
if
not
round
:
context
=
context
.
copy
()
context
=
context
.
_shallow_
copy
()
context
.
_set_rounding_decision
(
NEVER_ROUND
)
if
self
.
_sign
:
...
...
@@ -1358,7 +1360,7 @@ class Decimal(object):
# If DivisionImpossible causes an error, do not leave Rounded/Inexact
# ignored in the calling function.
context
=
context
.
copy
()
context
=
context
.
_shallow_
copy
()
flags
=
context
.
_ignore_flags
(
Rounded
,
Inexact
)
#keep DivisionImpossible flags
(
side
,
r
)
=
self
.
__divmod__
(
other
,
context
=
context
)
...
...
@@ -1367,7 +1369,7 @@ class Decimal(object):
context
.
_regard_flags
(
*
flags
)
return
r
context
=
context
.
copy
()
context
=
context
.
_shallow_
copy
()
rounding
=
context
.
_set_rounding_decision
(
NEVER_ROUND
)
if
other
.
_sign
:
...
...
@@ -1600,7 +1602,7 @@ class Decimal(object):
#Now we've got the rounding function
if
prec
!=
context
.
prec
:
context
=
context
.
copy
()
context
=
context
.
_shallow_
copy
()
context
.
prec
=
prec
ans
=
this_function
(
prec
,
expdiff
,
context
)
context
.
_raise_error
(
Rounded
)
...
...
@@ -1738,7 +1740,7 @@ class Decimal(object):
mul
=
Decimal
(
self
)
val
=
Decimal
(
1
)
context
=
context
.
copy
()
context
=
context
.
_shallow_
copy
()
context
.
prec
=
firstprec
+
elength
+
1
rounding
=
context
.
rounding
if
n
<
0
:
...
...
@@ -1938,7 +1940,7 @@ class Decimal(object):
else
:
tmp
.
_exp
=
0
context
=
context
.
copy
()
context
=
context
.
_shallow_
copy
()
flags
=
context
.
_ignore_all_flags
()
firstprec
=
context
.
prec
context
.
prec
=
3
...
...
@@ -2166,12 +2168,19 @@ class Context(object):
for
flag
in
self
.
flags
:
self
.
flags
[
flag
]
=
0
def
copy
(
self
):
"""Returns a copy from self."""
def
_shallow_
copy
(
self
):
"""Returns a
shallow
copy from self."""
nc
=
Context
(
self
.
prec
,
self
.
rounding
,
self
.
traps
,
self
.
flags
,
self
.
_rounding_decision
,
self
.
Emin
,
self
.
Emax
,
self
.
capitals
,
self
.
_clamp
,
self
.
_ignored_flags
)
return
nc
def
copy
(
self
):
"""Returns a deep copy from self."""
nc
=
Context
(
self
.
prec
,
self
.
rounding
,
self
.
traps
.
copy
(),
self
.
flags
.
copy
(),
self
.
_rounding_decision
,
self
.
Emin
,
self
.
Emax
,
self
.
capitals
,
self
.
_clamp
,
self
.
_ignored_flags
)
return
nc
__copy__
=
copy
def
_raise_error
(
self
,
condition
,
explanation
=
None
,
*
args
):
...
...
@@ -2233,7 +2242,7 @@ class Context(object):
Sets the rounding decision, and returns the current (previous)
rounding decision. Often used like:
context = context.copy()
context = context.
_shallow_
copy()
# That so you don't change the calling context
# if an error occurs in the middle (say DivisionImpossible is raised).
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment