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
802ad225
Commit
802ad225
authored
Aug 08, 2016
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
don't handle functions containing lambdas with yields as generators
I'm suprised we did not run into this earlier...
parent
daa0ffd5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
17 deletions
+22
-17
src/analysis/scoping_analysis.cpp
src/analysis/scoping_analysis.cpp
+14
-17
test/tests/generators.py
test/tests/generators.py
+8
-0
No files found.
src/analysis/scoping_analysis.cpp
View file @
802ad225
...
...
@@ -26,31 +26,28 @@ namespace pyston {
class
YieldVisitor
:
public
NoopASTVisitor
{
public:
YieldVisitor
()
:
containsYield
(
false
)
{}
AST
*
starting_node
;
bool
contains_yield
;
bool
visit_functiondef
(
AST_FunctionDef
*
)
override
{
return
true
;
}
YieldVisitor
(
AST
*
initial_node
)
:
starting_node
(
initial_node
),
contains_yield
(
false
)
{}
// we are only interested if the statements of the initial node contain a yield not if any child function contains a
// yield
bool
shouldSkip
(
AST
*
node
)
const
{
return
starting_node
!=
node
;
}
bool
visit_classdef
(
AST_ClassDef
*
node
)
override
{
return
shouldSkip
(
node
);
}
bool
visit_functiondef
(
AST_FunctionDef
*
node
)
override
{
return
shouldSkip
(
node
);
}
bool
visit_lambda
(
AST_Lambda
*
node
)
override
{
return
shouldSkip
(
node
);
}
bool
visit_yield
(
AST_Yield
*
)
override
{
contains
Y
ield
=
true
;
contains
_y
ield
=
true
;
return
true
;
}
bool
containsYield
;
};
bool
containsYield
(
AST
*
ast
)
{
YieldVisitor
visitor
;
if
(
ast
->
type
==
AST_TYPE
::
FunctionDef
)
{
AST_FunctionDef
*
funcDef
=
static_cast
<
AST_FunctionDef
*>
(
ast
);
for
(
auto
&
e
:
funcDef
->
body
)
{
e
->
accept
(
&
visitor
);
if
(
visitor
.
containsYield
)
return
true
;
}
}
else
{
ast
->
accept
(
&
visitor
);
}
return
visitor
.
containsYield
;
YieldVisitor
visitor
(
ast
);
ast
->
accept
(
&
visitor
);
return
visitor
.
contains_yield
;
}
// TODO
...
...
test/tests/generators.py
View file @
802ad225
...
...
@@ -134,3 +134,11 @@ x = lambda: (yield 1)
print
list
(
x
())
x
=
lambda
:
((
yield
1
),
(
yield
2
))
print
list
(
x
())
# we used to think that this function is a generator
def
this_is_not_generator
():
type
((
lambda
:
(
yield
)))
type
((
lambda
:
(
yield
))())
def
f
():
yield
print
type
(
this_is_not_generator
())
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