Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
f8b9d3c4
Commit
f8b9d3c4
authored
Jan 3, 2014
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
str: Throw TypeError for invalid index type and clean up comments.
parent
e606cb65
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
py/objstr.c
+4
-5
4 additions, 5 deletions
py/objstr.c
with
4 additions
and
5 deletions
py/objstr.c
+
4
−
5
View file @
f8b9d3c4
...
@@ -27,13 +27,11 @@ mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
...
@@ -27,13 +27,11 @@ mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
const
char
*
lhs_str
=
qstr_str
(
lhs
->
qstr
);
const
char
*
lhs_str
=
qstr_str
(
lhs
->
qstr
);
switch
(
op
)
{
switch
(
op
)
{
case
RT_BINARY_OP_SUBSCR
:
case
RT_BINARY_OP_SUBSCR
:
// string access
// XXX a massive hack!
// TODO: need predicate to check for int-like type (bools are such for example)
// TODO: need predicate to check for int-like type (bools are such for example)
// ["no", "yes"][1 == 2] is common idiom
// ["no", "yes"][1 == 2] is common idiom
if
(
MP_OBJ_IS_SMALL_INT
(
rhs_in
))
{
if
(
MP_OBJ_IS_SMALL_INT
(
rhs_in
))
{
// TODO: This implements byte string access for single index so far
// TODO: This implements byte string access for single index so far
// TODO: Handle negative indexes.
return
mp_obj_new_int
(
lhs_str
[
mp_obj_get_int
(
rhs_in
)]);
return
mp_obj_new_int
(
lhs_str
[
mp_obj_get_int
(
rhs_in
)]);
#if MICROPY_ENABLE_SLICE
#if MICROPY_ENABLE_SLICE
}
else
if
(
MP_OBJ_IS_TYPE
(
rhs_in
,
&
slice_type
))
{
}
else
if
(
MP_OBJ_IS_TYPE
(
rhs_in
,
&
slice_type
))
{
...
@@ -50,8 +48,9 @@ mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
...
@@ -50,8 +48,9 @@ mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
return
mp_obj_new_str
(
qstr_from_strn_copy
(
lhs_str
+
start
,
stop
-
start
));
return
mp_obj_new_str
(
qstr_from_strn_copy
(
lhs_str
+
start
,
stop
-
start
));
#endif
#endif
}
else
{
}
else
{
// Throw TypeError here
// Message doesn't match CPython, but we don't have so much bytes as they
assert
(
0
);
// to spend them on verbose wording
nlr_jump
(
mp_obj_new_exception_msg
(
rt_q_TypeError
,
"index must be int"
));
}
}
case
RT_BINARY_OP_ADD
:
case
RT_BINARY_OP_ADD
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment