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
2c2044e7
Commit
2c2044e7
authored
Oct 21, 2018
by
Serhiy Storchaka
Committed by
GitHub
Oct 21, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-34984: Improve error messages for bytes and bytearray constructors. (GH-9874)
parent
914f9a07
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
6 deletions
+25
-6
Lib/test/test_bytes.py
Lib/test/test_bytes.py
+2
-0
Objects/bytearrayobject.c
Objects/bytearrayobject.c
+20
-4
Objects/bytesobject.c
Objects/bytesobject.c
+3
-2
No files found.
Lib/test/test_bytes.py
View file @
2c2044e7
...
...
@@ -169,6 +169,8 @@ class BaseBytesTest:
self
.
assertRaises
(
TypeError
,
self
.
type2test
,
[
0.0
])
self
.
assertRaises
(
TypeError
,
self
.
type2test
,
[
None
])
self
.
assertRaises
(
TypeError
,
self
.
type2test
,
[
C
()])
self
.
assertRaises
(
TypeError
,
self
.
type2test
,
encoding
=
'ascii'
)
self
.
assertRaises
(
TypeError
,
self
.
type2test
,
errors
=
'ignore'
)
self
.
assertRaises
(
TypeError
,
self
.
type2test
,
0
,
'ascii'
)
self
.
assertRaises
(
TypeError
,
self
.
type2test
,
b''
,
'ascii'
)
self
.
assertRaises
(
TypeError
,
self
.
type2test
,
0
,
errors
=
'ignore'
)
...
...
Objects/bytearrayobject.c
View file @
2c2044e7
...
...
@@ -783,7 +783,9 @@ bytearray_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
if
(
arg
==
NULL
)
{
if
(
encoding
!=
NULL
||
errors
!=
NULL
)
{
PyErr_SetString
(
PyExc_TypeError
,
"encoding or errors without sequence argument"
);
encoding
!=
NULL
?
"encoding without a string argument"
:
"errors without a string argument"
);
return
-
1
;
}
return
0
;
...
...
@@ -812,7 +814,9 @@ bytearray_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
/* If it's not unicode, there can't be encoding or errors */
if
(
encoding
!=
NULL
||
errors
!=
NULL
)
{
PyErr_SetString
(
PyExc_TypeError
,
"encoding or errors without a string argument"
);
encoding
!=
NULL
?
"encoding without a string argument"
:
"errors without a string argument"
);
return
-
1
;
}
...
...
@@ -860,8 +864,14 @@ bytearray_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
/* Get the iterator */
it
=
PyObject_GetIter
(
arg
);
if
(
it
==
NULL
)
if
(
it
==
NULL
)
{
if
(
PyErr_ExceptionMatches
(
PyExc_TypeError
))
{
PyErr_Format
(
PyExc_TypeError
,
"cannot convert '%.200s' object to bytearray"
,
arg
->
ob_type
->
tp_name
);
}
return
-
1
;
}
iternext
=
*
Py_TYPE
(
it
)
->
tp_iternext
;
/* Run the iterator to exhaustion */
...
...
@@ -1626,8 +1636,14 @@ bytearray_extend(PyByteArrayObject *self, PyObject *iterable_of_ints)
}
it
=
PyObject_GetIter
(
iterable_of_ints
);
if
(
it
==
NULL
)
if
(
it
==
NULL
)
{
if
(
PyErr_ExceptionMatches
(
PyExc_TypeError
))
{
PyErr_Format
(
PyExc_TypeError
,
"can't extend bytearray with %.100s"
,
iterable_of_ints
->
ob_type
->
tp_name
);
}
return
NULL
;
}
/* Try to determine the length of the argument. 32 is arbitrary. */
buf_size
=
PyObject_LengthHint
(
iterable_of_ints
,
32
);
...
...
Objects/bytesobject.c
View file @
2c2044e7
...
...
@@ -2537,8 +2537,9 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if
(
x
==
NULL
)
{
if
(
encoding
!=
NULL
||
errors
!=
NULL
)
{
PyErr_SetString
(
PyExc_TypeError
,
"encoding or errors without sequence "
"argument"
);
encoding
!=
NULL
?
"encoding without a string argument"
:
"errors without a string argument"
);
return
NULL
;
}
return
PyBytes_FromStringAndSize
(
NULL
,
0
);
...
...
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