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
bdd8eeaa
Commit
bdd8eeaa
authored
Sep 24, 2016
by
Mark Dickinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #28203: Fix incorrect type in error message from complex(1.0, {2:3}). Patch by Soumya Sharma.
parent
536d10e9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
6 deletions
+29
-6
Lib/test/test_complex.py
Lib/test/test_complex.py
+8
-0
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
Objects/complexobject.c
Objects/complexobject.c
+17
-6
No files found.
Lib/test/test_complex.py
View file @
bdd8eeaa
...
...
@@ -326,6 +326,14 @@ class ComplexTest(unittest.TestCase):
self
.
assertRaises
(
ValueError
,
complex
,
"1e1ej"
)
self
.
assertRaises
(
ValueError
,
complex
,
"1e++1ej"
)
self
.
assertRaises
(
ValueError
,
complex
,
")1+2j("
)
self
.
assertRaisesRegex
(
TypeError
,
"first argument must be a string or a number, not 'dict'"
,
complex
,
{
1
:
2
},
1
)
self
.
assertRaisesRegex
(
TypeError
,
"second argument must be a number, not 'dict'"
,
complex
,
1
,
{
1
:
2
})
# the following three are accepted by Python 2.6
self
.
assertRaises
(
ValueError
,
complex
,
"1..1j"
)
self
.
assertRaises
(
ValueError
,
complex
,
"1.11.1j"
)
...
...
Misc/ACKS
View file @
bdd8eeaa
...
...
@@ -1349,6 +1349,7 @@ Daniel Shahaf
Mark Shannon
Ha Shao
Richard Shapiro
Soumya Sharma
Varun Sharma
Daniel Shaulov
Vlad Shcherbina
...
...
Misc/NEWS
View file @
bdd8eeaa
...
...
@@ -10,6 +10,9 @@ Release date: TBA
Core and Builtins
-----------------
- Issue #28203: Fix incorrect type in error message from
``complex(1.0, {2:3})``. Patch by Soumya Sharma.
- Issue #27955: Fallback on reading /dev/urandom device when the getrandom()
syscall fails with EPERM, for example when blocked by SECCOMP.
...
...
Objects/complexobject.c
View file @
bdd8eeaa
...
...
@@ -954,18 +954,29 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
nbr
=
r
->
ob_type
->
tp_as_number
;
if
(
i
!=
NULL
)
nbi
=
i
->
ob_type
->
tp_as_number
;
if
(
nbr
==
NULL
||
nbr
->
nb_float
==
NULL
||
((
i
!=
NULL
)
&&
(
nbi
==
NULL
||
nbi
->
nb_float
==
NULL
)))
{
if
(
nbr
==
NULL
||
nbr
->
nb_float
==
NULL
)
{
PyErr_Format
(
PyExc_TypeError
,
"complex() argument must be a string or a number, not '%.200s'"
,
Py_TYPE
(
r
)
->
tp_name
);
"complex() first argument must be a string or a number, "
"not '%.200s'"
,
Py_TYPE
(
r
)
->
tp_name
);
if
(
own_r
)
{
Py_DECREF
(
r
);
}
return
NULL
;
}
if
(
i
!=
NULL
)
{
nbi
=
i
->
ob_type
->
tp_as_number
;
if
(
nbi
==
NULL
||
nbi
->
nb_float
==
NULL
)
{
PyErr_Format
(
PyExc_TypeError
,
"complex() second argument must be a number, "
"not '%.200s'"
,
Py_TYPE
(
i
)
->
tp_name
);
if
(
own_r
)
{
Py_DECREF
(
r
);
}
return
NULL
;
}
}
/* If we get this far, then the "real" and "imag" parts should
both be treated as numbers, and the constructor should return a
...
...
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