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
06e56e58
Commit
06e56e58
authored
Feb 15, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix dir() implementation to always return a sorted list
parent
ec1b4ad3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
5 deletions
+33
-5
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+32
-0
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+1
-5
No files found.
Cython/Compiler/ExprNodes.py
View file @
06e56e58
...
@@ -6224,6 +6224,38 @@ class DictItemNode(ExprNode):
...
@@ -6224,6 +6224,38 @@ class DictItemNode(ExprNode):
return
iter
([
self
.
key
,
self
.
value
])
return
iter
([
self
.
key
,
self
.
value
])
class
SortedDictKeysNode
(
ExprNode
):
# build sorted list of dict keys, e.g. for dir()
subexprs
=
[
'base_dict'
]
is_temp
=
True
def
__init__
(
self
,
base_dict
):
ExprNode
.
__init__
(
self
,
base_dict
.
pos
,
base_dict
=
base_dict
)
self
.
type
=
Builtin
.
list_type
def
analyse_types
(
self
,
env
):
base_dict
=
self
.
base_dict
.
analyse_types
(
env
)
if
base_dict
.
type
is
Builtin
.
dict_type
:
base_dict
=
base_dict
.
as_none_safe_node
(
"'NoneType' object is not iterable"
)
self
.
base_dict
=
base_dict
return
self
def
generate_result_code
(
self
,
code
):
dict_result
=
self
.
base_dict
.
py_result
()
if
self
.
base_dict
.
type
is
Builtin
.
dict_type
:
function
=
'PyDict_Keys'
else
:
function
=
'PyMapping_Keys'
code
.
putln
(
'%s = %s(%s); %s'
%
(
self
.
result
(),
function
,
dict_result
,
code
.
error_goto_if_null
(
self
.
result
(),
self
.
pos
)))
code
.
put_gotref
(
self
.
py_result
())
code
.
putln
(
code
.
error_goto_if_neg
(
'PyList_Sort(%s)'
%
self
.
py_result
(),
self
.
pos
))
class
ModuleNameMixin
(
object
):
class
ModuleNameMixin
(
object
):
def
set_qualified_name
(
self
,
env
,
self_name
):
def
set_qualified_name
(
self
,
env
,
self_name
):
self
.
module_name
=
env
.
global_scope
().
qualified_name
self
.
module_name
=
env
.
global_scope
().
qualified_name
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
06e56e58
...
@@ -2489,11 +2489,7 @@ class TransformBuiltinMethods(EnvTransform):
...
@@ -2489,11 +2489,7 @@ class TransformBuiltinMethods(EnvTransform):
locals_dict
=
ExprNodes
.
CloneNode
(
pyclass
.
dict
)
locals_dict
=
ExprNodes
.
CloneNode
(
pyclass
.
dict
)
else
:
else
:
locals_dict
=
ExprNodes
.
GlobalsExprNode
(
pos
)
locals_dict
=
ExprNodes
.
GlobalsExprNode
(
pos
)
return
ExprNodes
.
SimpleCallNode
(
return
ExprNodes
.
SortedDictKeysNode
(
locals_dict
)
pos
,
function
=
ExprNodes
.
AttributeNode
(
pos
,
obj
=
locals_dict
,
attribute
=
"keys"
),
args
=
[])
local_names
=
[
var
.
name
for
var
in
lenv
.
entries
.
values
()
if
var
.
name
]
local_names
=
[
var
.
name
for
var
in
lenv
.
entries
.
values
()
if
var
.
name
]
items
=
[
ExprNodes
.
IdentifierStringNode
(
pos
,
value
=
var
)
items
=
[
ExprNodes
.
IdentifierStringNode
(
pos
,
value
=
var
)
for
var
in
local_names
]
for
var
in
local_names
]
...
...
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