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
363a83bb
Commit
363a83bb
authored
Nov 14, 2012
by
Mark Dickinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #16290: __complex__ must now always return an instance of complex.
parent
feb8d2e3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
6 deletions
+11
-6
Lib/test/test_complex.py
Lib/test/test_complex.py
+2
-0
Misc/NEWS
Misc/NEWS
+3
-0
Objects/complexobject.c
Objects/complexobject.c
+6
-6
No files found.
Lib/test/test_complex.py
View file @
363a83bb
...
@@ -221,6 +221,8 @@ class ComplexTest(unittest.TestCase):
...
@@ -221,6 +221,8 @@ class ComplexTest(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
complex
,
OS
(
None
))
self
.
assertRaises
(
TypeError
,
complex
,
OS
(
None
))
self
.
assertRaises
(
TypeError
,
complex
,
NS
(
None
))
self
.
assertRaises
(
TypeError
,
complex
,
NS
(
None
))
self
.
assertRaises
(
TypeError
,
complex
,
{})
self
.
assertRaises
(
TypeError
,
complex
,
{})
self
.
assertRaises
(
TypeError
,
complex
,
NS
(
1.5
))
self
.
assertRaises
(
TypeError
,
complex
,
NS
(
1
))
self
.
assertAlmostEqual
(
complex
(
"1+10j"
),
1
+
10j
)
self
.
assertAlmostEqual
(
complex
(
"1+10j"
),
1
+
10j
)
self
.
assertAlmostEqual
(
complex
(
10
),
10
+
0j
)
self
.
assertAlmostEqual
(
complex
(
10
),
10
+
0j
)
...
...
Misc/NEWS
View file @
363a83bb
...
@@ -10,6 +10,9 @@ What's New in Python 3.4.0 Alpha 1?
...
@@ -10,6 +10,9 @@ What's New in Python 3.4.0 Alpha 1?
Core and Builtins
Core and Builtins
-----------------
-----------------
- Issue #16290: A float return value from the __complex__ special method is no
longer accepted in the complex() constructor.
- Issue #16416: On Mac OS X, operating system data are now always
- Issue #16416: On Mac OS X, operating system data are now always
encoded/decoded to/from UTF-8/surrogateescape, instead of the locale encoding
encoded/decoded to/from UTF-8/surrogateescape, instead of the locale encoding
(which may be ASCII if no locale environment variable is set), to avoid
(which may be ASCII if no locale environment variable is set), to avoid
...
...
Objects/complexobject.c
View file @
363a83bb
...
@@ -271,6 +271,12 @@ try_complex_special_method(PyObject *op) {
...
@@ -271,6 +271,12 @@ try_complex_special_method(PyObject *op) {
if
(
f
)
{
if
(
f
)
{
PyObject
*
res
=
PyObject_CallFunctionObjArgs
(
f
,
NULL
);
PyObject
*
res
=
PyObject_CallFunctionObjArgs
(
f
,
NULL
);
Py_DECREF
(
f
);
Py_DECREF
(
f
);
if
(
res
!=
NULL
&&
!
PyComplex_Check
(
res
))
{
PyErr_SetString
(
PyExc_TypeError
,
"__complex__ should return a complex object"
);
Py_DECREF
(
res
);
return
NULL
;
}
return
res
;
return
res
;
}
}
return
NULL
;
return
NULL
;
...
@@ -296,12 +302,6 @@ PyComplex_AsCComplex(PyObject *op)
...
@@ -296,12 +302,6 @@ PyComplex_AsCComplex(PyObject *op)
newop
=
try_complex_special_method
(
op
);
newop
=
try_complex_special_method
(
op
);
if
(
newop
)
{
if
(
newop
)
{
if
(
!
PyComplex_Check
(
newop
))
{
PyErr_SetString
(
PyExc_TypeError
,
"__complex__ should return a complex object"
);
Py_DECREF
(
newop
);
return
cv
;
}
cv
=
((
PyComplexObject
*
)
newop
)
->
cval
;
cv
=
((
PyComplexObject
*
)
newop
)
->
cval
;
Py_DECREF
(
newop
);
Py_DECREF
(
newop
);
return
cv
;
return
cv
;
...
...
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