Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
cython
Commits
05a561df
Commit
05a561df
authored
Sep 18, 2011
by
Vitja Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement noargs eval() support
parent
b1a9ceb7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
0 deletions
+44
-0
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+15
-0
tests/run/eval.pyx
tests/run/eval.pyx
+29
-0
No files found.
Cython/Compiler/ParseTreeTransforms.py
View file @
05a561df
...
@@ -2293,6 +2293,19 @@ class TransformBuiltinMethods(EnvTransform):
...
@@ -2293,6 +2293,19 @@ class TransformBuiltinMethods(EnvTransform):
for
var
in
local_names
]
for
var
in
local_names
]
return
ExprNodes
.
ListNode
(
pos
,
args
=
items
)
return
ExprNodes
.
ListNode
(
pos
,
args
=
items
)
def
_inject_eval
(
self
,
node
,
func_name
):
lenv
=
self
.
current_env
()
entry
=
lenv
.
lookup_here
(
func_name
)
if
entry
or
len
(
node
.
args
)
!=
1
:
return
node
# Inject globals and locals
node
.
args
.
append
(
ExprNodes
.
GlobalsExprNode
(
node
.
pos
))
if
not
lenv
.
is_module_scope
:
node
.
args
.
append
(
ExprNodes
.
LocalsExprNode
(
node
.
pos
,
self
.
current_scope_node
(),
lenv
))
return
node
def
visit_SimpleCallNode
(
self
,
node
):
def
visit_SimpleCallNode
(
self
,
node
):
# cython.foo
# cython.foo
function
=
node
.
function
.
as_cython_attribute
()
function
=
node
.
function
.
as_cython_attribute
()
...
@@ -2351,6 +2364,8 @@ class TransformBuiltinMethods(EnvTransform):
...
@@ -2351,6 +2364,8 @@ class TransformBuiltinMethods(EnvTransform):
func_name
=
node
.
function
.
name
func_name
=
node
.
function
.
name
if
func_name
in
(
'dir'
,
'locals'
,
'vars'
):
if
func_name
in
(
'dir'
,
'locals'
,
'vars'
):
return
self
.
_inject_locals
(
node
,
func_name
)
return
self
.
_inject_locals
(
node
,
func_name
)
if
func_name
==
'eval'
:
return
self
.
_inject_eval
(
node
,
func_name
)
return
node
return
node
...
...
tests/run/eval.pyx
0 → 100644
View file @
05a561df
# mode: run
# tags: eval
GLOBAL
=
123
def
eval_simple
(
local
):
"""
>>> eval_simple(321)
(123, 321)
"""
return
eval
(
'GLOBAL, local'
)
def
eval_class_scope
():
"""
>>> eval_class_scope().c
3
"""
class
TestClassScope
:
a
=
1
b
=
2
c
=
eval
(
'a + b'
)
return
TestClassScope
def
eval_locals
(
a
,
b
):
"""
>>> eval_locals(1, 2)
(1, 2)
"""
return
eval
(
'a, b'
,
{},
locals
())
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