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
9cb329c8
Commit
9cb329c8
authored
Nov 07, 2012
by
Stefan Krah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #16431: Use the type information when constructing a Decimal subtype
from a Decimal argument.
parent
cb0141a8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
2 deletions
+35
-2
Lib/test/test_decimal.py
Lib/test/test_decimal.py
+5
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/_decimal/_decimal.c
Modules/_decimal/_decimal.c
+27
-2
No files found.
Lib/test/test_decimal.py
View file @
9cb329c8
...
...
@@ -2047,6 +2047,11 @@ class UsabilityTest(unittest.TestCase):
self
.
assertIs
(
type
(
d
),
MyDecimal
)
self
.
assertEqual
(
d
,
d1
)
a
=
Decimal
(
'1.0'
)
b
=
MyDecimal
(
a
)
self
.
assertIs
(
type
(
b
),
MyDecimal
)
self
.
assertEqual
(
a
,
b
)
def
test_implicit_context
(
self
):
Decimal
=
self
.
decimal
.
Decimal
getcontext
=
self
.
decimal
.
getcontext
...
...
Misc/NEWS
View file @
9cb329c8
...
...
@@ -80,6 +80,9 @@ Core and Builtins
Library
-------
-
Issue
#
16431
:
Use
the
type
information
when
constructing
a
Decimal
subtype
from
a
Decimal
argument
.
-
Issue
#
16350
:
zlib
.
Decompress
.
decompress
()
now
accumulates
data
from
successive
calls
after
EOF
in
unused_data
,
instead
of
only
saving
the
argument
to
the
last
call
.
Patch
by
Serhiy
Storchaka
.
...
...
Modules/_decimal/_decimal.c
View file @
9cb329c8
...
...
@@ -2338,6 +2338,32 @@ PyDecType_FromFloat(PyTypeObject *type, PyObject *v,
return
dec
;
}
/* Return a new PyDecObject (subtype) from a Decimal. */
static
PyObject
*
PyDecType_FromDecimalExact
(
PyTypeObject
*
type
,
PyObject
*
v
,
PyObject
*
context
)
{
PyObject
*
dec
;
uint32_t
status
=
0
;
if
(
type
==
&
PyDec_Type
)
{
Py_INCREF
(
v
);
return
v
;
}
dec
=
PyDecType_New
(
type
);
if
(
dec
==
NULL
)
{
return
NULL
;
}
mpd_qcopy
(
MPD
(
dec
),
MPD
(
v
),
&
status
);
if
(
dec_addstatus
(
context
,
status
))
{
Py_DECREF
(
dec
);
return
NULL
;
}
return
dec
;
}
static
PyObject
*
sequence_as_tuple
(
PyObject
*
v
,
PyObject
*
ex
,
const
char
*
mesg
)
{
...
...
@@ -2642,8 +2668,7 @@ PyDecType_FromObjectExact(PyTypeObject *type, PyObject *v, PyObject *context)
return
PyDecType_FromSsizeExact
(
type
,
0
,
context
);
}
else
if
(
PyDec_Check
(
v
))
{
Py_INCREF
(
v
);
return
v
;
return
PyDecType_FromDecimalExact
(
type
,
v
,
context
);
}
else
if
(
PyUnicode_Check
(
v
))
{
return
PyDecType_FromUnicodeExactWS
(
type
,
v
,
context
);
...
...
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