Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
grumpy
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
grumpy
Commits
66bfd64a
Commit
66bfd64a
authored
Dec 29, 2016
by
Dylan Trotter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Generators now return nil when exhausted instead of raising StopIteration.
parent
e06bed33
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
8 deletions
+8
-8
compiler/util.py
compiler/util.py
+2
-5
runtime/generator.go
runtime/generator.go
+3
-0
runtime/generator_test.go
runtime/generator_test.go
+3
-3
No files found.
compiler/util.py
View file @
66bfd64a
...
...
@@ -77,11 +77,8 @@ class Writer(object):
# Assume that body is aligned with goto labels.
self
.
write
(
body
)
with
self
.
indent_block
():
if
block_
.
is_generator
:
self
.
write
(
'return nil, πF.Raise('
'πg.StopIterationType.ToObject(), nil, nil)'
)
else
:
self
.
write
(
'return πg.None, nil'
)
self
.
write
(
'return {}, nil'
.
format
(
'nil'
if
block_
.
is_generator
else
'πg.None'
))
self
.
write
(
'})'
)
def
write_import_block
(
self
,
imports
):
...
...
runtime/generator.go
View file @
66bfd64a
...
...
@@ -86,6 +86,9 @@ func (g *Generator) resume(f *Frame, sendValue *Object) (*Object, *BaseException
}
result
,
raised
:=
g
.
block
.
execInternal
(
g
.
frame
,
sendValue
)
g
.
mutex
.
Lock
()
if
result
==
nil
&&
raised
==
nil
{
raised
=
f
.
Raise
(
StopIterationType
.
ToObject
(),
nil
,
nil
)
}
if
raised
==
nil
{
g
.
state
=
generatorStateReady
}
else
{
...
...
runtime/generator_test.go
View file @
66bfd64a
...
...
@@ -29,7 +29,7 @@ func TestGeneratorNext(t *testing.T) {
})
recursive
=
NewGenerator
(
recursiveBlock
,
NewDict
())
.
ToObject
()
empty
:=
NewBlock
(
func
(
f
*
Frame
,
_
*
Object
)
(
*
Object
,
*
BaseException
)
{
return
nil
,
f
.
Raise
(
StopIterationType
.
ToObject
(),
nil
,
nil
)
return
nil
,
nil
})
exhausted
:=
NewGenerator
(
empty
,
NewDict
())
.
ToObject
()
mustNotRaise
(
ListType
.
Call
(
newFrame
(
nil
),
Args
{
exhausted
},
nil
))
...
...
@@ -46,7 +46,7 @@ func TestGeneratorNext(t *testing.T) {
func
TestGeneratorSend
(
t
*
testing
.
T
)
{
empty
:=
NewBlock
(
func
(
f
*
Frame
,
_
*
Object
)
(
*
Object
,
*
BaseException
)
{
return
nil
,
f
.
Raise
(
StopIterationType
.
ToObject
(),
nil
,
nil
)
return
nil
,
nil
})
cases
:=
[]
invokeTestCase
{
invokeTestCase
{
args
:
wrapArgs
(
NewGenerator
(
empty
,
NewDict
()),
123
),
wantExc
:
mustCreateException
(
TypeErrorType
,
"can't send non-None value to a just-started generator"
)},
...
...
@@ -78,7 +78,7 @@ func TestGeneratorSimple(t *testing.T) {
f
.
PushCheckpoint
(
2
)
return
NewStr
(
"bar"
)
.
ToObject
(),
nil
Yield2
:
return
nil
,
f
.
Raise
(
StopIterationType
.
ToObject
(),
nil
,
nil
)
return
nil
,
nil
})
cas
:=
&
invokeTestCase
{
args
:
wrapArgs
(
NewGenerator
(
b
,
NewDict
())),
...
...
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