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
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
962a5d50
Commit
962a5d50
authored
10 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
py: Implement __reversed__ slot.
Addresses issue #1073.
parent
d7f19946
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
py/objreversed.c
+7
-0
7 additions, 0 deletions
py/objreversed.c
py/qstrdefs.h
+1
-0
1 addition, 0 deletions
py/qstrdefs.h
tests/basics/builtin_reversed.py
+6
-0
6 additions, 0 deletions
tests/basics/builtin_reversed.py
with
14 additions
and
0 deletions
py/objreversed.c
+
7
−
0
View file @
962a5d50
...
...
@@ -39,6 +39,13 @@ typedef struct _mp_obj_reversed_t {
STATIC
mp_obj_t
reversed_make_new
(
mp_obj_t
type_in
,
mp_uint_t
n_args
,
mp_uint_t
n_kw
,
const
mp_obj_t
*
args
)
{
mp_arg_check_num
(
n_args
,
n_kw
,
1
,
1
,
false
);
// check if __reversed__ exists, and if so delegate to it
mp_obj_t
dest
[
2
];
mp_load_method_maybe
(
args
[
0
],
MP_QSTR___reversed__
,
dest
);
if
(
dest
[
0
]
!=
MP_OBJ_NULL
)
{
return
mp_call_method_n_kw
(
0
,
0
,
dest
);
}
mp_obj_reversed_t
*
o
=
m_new_obj
(
mp_obj_reversed_t
);
o
->
base
.
type
=
type_in
;
o
->
seq
=
args
[
0
];
...
...
This diff is collapsed.
Click to expand it.
py/qstrdefs.h
+
1
−
0
View file @
962a5d50
...
...
@@ -74,6 +74,7 @@ Q(__gt__)
Q
(
__eq__
)
Q
(
__le__
)
Q
(
__ge__
)
Q
(
__reversed__
)
Q
(
micropython
)
Q
(
bytecode
)
...
...
This diff is collapsed.
Click to expand it.
tests/basics/builtin_reversed.py
+
6
−
0
View file @
962a5d50
...
...
@@ -31,3 +31,9 @@ class A:
return
pos
+
1
for
a
in
reversed
(
A
()):
print
(
a
)
# user object with __reversed__
class
B
:
def
__reversed__
(
self
):
return
[
1
,
2
,
3
]
print
(
reversed
(
B
()))
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