Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
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
Boxiang Sun
Pyston
Commits
27df1a77
Commit
27df1a77
authored
Aug 14, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #832 from vinzenz/bytearray-string-concat
Allow string + bytearray => bytearray. Fixes #780
parents
60850a52
a8e6299a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
4 deletions
+23
-4
src/runtime/str.cpp
src/runtime/str.cpp
+10
-4
test/tests/bytearray_str_concat.py
test/tests/bytearray_str_concat.py
+13
-0
No files found.
src/runtime/str.cpp
View file @
27df1a77
...
@@ -342,10 +342,16 @@ extern "C" Box* strAdd(BoxedString* lhs, Box* _rhs) {
...
@@ -342,10 +342,16 @@ extern "C" Box* strAdd(BoxedString* lhs, Box* _rhs) {
}
}
if
(
!
PyString_Check
(
_rhs
))
{
if
(
!
PyString_Check
(
_rhs
))
{
// Note: this is deliberately not returning NotImplemented, even though
if
(
PyByteArray_Check
(
_rhs
))
{
// that would be more usual. I assume this behavior of CPython's is
Box
*
rtn
=
PyByteArray_Concat
(
lhs
,
_rhs
);
// for backwards compatibility.
checkAndThrowCAPIException
();
raiseExcHelper
(
TypeError
,
"cannot concatenate 'str' and '%s' objects"
,
getTypeName
(
_rhs
));
return
rtn
;
}
else
{
// Note: this is deliberately not returning NotImplemented, even though
// that would be more usual. I assume this behavior of CPython's is
// for backwards compatibility.
raiseExcHelper
(
TypeError
,
"cannot concatenate 'str' and '%s' objects"
,
getTypeName
(
_rhs
));
}
}
}
BoxedString
*
rhs
=
static_cast
<
BoxedString
*>
(
_rhs
);
BoxedString
*
rhs
=
static_cast
<
BoxedString
*>
(
_rhs
);
...
...
test/tests/bytearray_str_concat.py
0 → 100644
View file @
27df1a77
assert
((
'abc'
+
bytearray
(
'def'
))
==
bytearray
(
'abcdef'
))
assert
((
bytearray
(
'abc'
)
+
'def'
)
==
bytearray
(
'abcdef'
))
try
:
u'abc'
+
bytearray
(
'def'
)
assert
(
False
)
except
TypeError
:
pass
try
:
bytearray
(
'abc'
)
+
u'def'
assert
(
False
)
except
TypeError
:
pass
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