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
Boxiang Sun
cython
Commits
9a9ee007
Commit
9a9ee007
authored
Feb 15, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avoid list building when in-testing against dir() result
parent
85f97592
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
0 deletions
+48
-0
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+14
-0
tests/run/locals_T732.pyx
tests/run/locals_T732.pyx
+34
-0
No files found.
Cython/Compiler/ParseTreeTransforms.py
View file @
9a9ee007
...
...
@@ -2495,6 +2495,20 @@ class TransformBuiltinMethods(EnvTransform):
for
var
in
local_names
]
return
ExprNodes
.
ListNode
(
pos
,
args
=
items
)
def
visit_PrimaryCmpNode
(
self
,
node
):
# special case: for in/not-in test, we do not need to sort locals()
self
.
visitchildren
(
node
)
if
node
.
operator
in
'not_in'
:
# in/not_in
if
isinstance
(
node
.
operand2
,
ExprNodes
.
SortedDictKeysNode
):
arg
=
node
.
operand2
.
arg
if
isinstance
(
arg
,
ExprNodes
.
NoneCheckNode
):
arg
=
arg
.
arg
node
.
operand2
=
arg
return
node
def
visit_CascadedCmpNode
(
self
,
node
):
return
self
.
visit_PrimaryCmpNode
(
node
)
def
_inject_eval
(
self
,
node
,
func_name
):
lenv
=
self
.
current_env
()
entry
=
lenv
.
lookup_here
(
func_name
)
...
...
tests/run/locals_T732.pyx
View file @
9a9ee007
...
...
@@ -2,10 +2,13 @@
# ticket: 731
# tags: locals, vars, dir
cimport
cython
LOCALS
=
locals
()
GLOBALS
=
globals
()
DIR_SAME
=
sorted
(
dir
())
==
sorted
(
globals
().
keys
())
def
test_module_locals_and_dir
():
"""
>>> LOCALS is GLOBALS
...
...
@@ -14,6 +17,7 @@ def test_module_locals_and_dir():
True
"""
def
test_class_locals_and_dir
():
"""
>>> klass = test_class_locals_and_dir()
...
...
@@ -28,3 +32,33 @@ def test_class_locals_and_dir():
names
=
dir
()
locs
=
locals
()
return
Foo
@
cython
.
test_fail_if_path_exists
(
'//SortedDictKeysNode'
)
def
test_class_dir_contains
():
"""
>>> klass = test_class_dir_contains()
True
False
True
False
True
False
True
True
True
"""
not_visible
=
1234
class
Foo
:
visible
=
4321
print
(
'visible'
in
dir
())
print
(
'not_visible'
in
dir
())
print
(
'not_visible'
not
in
dir
())
print
(
'locs'
in
dir
())
print
(
'visible'
in
locals
())
print
(
'locs'
in
locals
())
locs
=
locals
()
print
(
'visible'
in
dir
())
print
(
'locs'
in
dir
())
print
(
'locs'
in
locals
())
return
Foo
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