Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
9a54a223
Commit
9a54a223
authored
Mar 30, 2014
by
Paul Sokolovsky
Browse files
objgenerator.throw(): Throwing GeneratorExit is equivalent to .close().
According to PEP380 and caught by CPython test_pep380.py .
parent
6ae237d2
Changes
1
Hide whitespace changes
Inline
Side-by-side
py/objgenerator.c
View file @
9a54a223
...
...
@@ -159,8 +159,18 @@ STATIC mp_obj_t gen_instance_send(mp_obj_t self_in, mp_obj_t send_value) {
STATIC
MP_DEFINE_CONST_FUN_OBJ_2
(
gen_instance_send_obj
,
gen_instance_send
);
STATIC
mp_obj_t
gen_instance_close
(
mp_obj_t
self_in
);
STATIC
mp_obj_t
gen_instance_throw
(
uint
n_args
,
const
mp_obj_t
*
args
)
{
mp_obj_t
ret
=
gen_resume_and_raise
(
args
[
0
],
mp_const_none
,
n_args
==
2
?
args
[
1
]
:
args
[
2
]);
mp_obj_t
exc
=
(
n_args
==
2
)
?
args
[
1
]
:
args
[
2
];
if
(
mp_obj_is_subclass_fast
(
mp_obj_get_type
(
exc
),
&
mp_type_GeneratorExit
))
{
// Throwing GeneratorExit is equivalent of calling close aka
// GeneratorExit should be handled specially
// TODO: Calling .close() will throw new exception instance, not one
// given to throw, which is not ok.
return
gen_instance_close
(
args
[
0
]);
}
mp_obj_t
ret
=
gen_resume_and_raise
(
args
[
0
],
mp_const_none
,
exc
);
if
(
ret
==
MP_OBJ_NULL
)
{
nlr_jump
(
mp_obj_new_exception
(
&
mp_type_StopIteration
));
}
else
{
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment