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
c5ee90e5
Commit
c5ee90e5
authored
Jun 03, 2014
by
Vinzenz Feenstra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extended test, usage of callattrInternal and getattr_internal
Signed-off-by:
Vinzenz Feenstra
<
evilissimo@gmail.com
>
parent
f9992af3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
20 deletions
+33
-20
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+12
-15
test/tests/dir.py
test/tests/dir.py
+21
-5
No files found.
src/runtime/builtin_modules/builtins.cpp
View file @
c5ee90e5
...
...
@@ -38,22 +38,19 @@ extern "C" Box* dir1(Box* obj) {
// TODO: Recursive class traversal for lookup of types and eliminating
// duplicates afterwards
BoxedList
*
result
=
nullptr
;
if
(
obj
->
cls
->
hasattrs
)
{
// If __dir__ is present just call it and return what it returns
HCBox
*
hcb
=
static_cast
<
HCBox
*>
(
obj
);
Box
*
obj_dir
=
hcb
->
cls
->
getattr
(
"__dir__"
,
nullptr
,
nullptr
);
if
(
obj_dir
)
{
return
runtimeCall
(
obj_dir
,
1
,
obj
,
nullptr
,
nullptr
,
nullptr
);
}
// If __dir__ is present just call it and return what it returns
static
std
::
string
attr_dir
=
"__dir__"
;
Box
*
dir_result
=
callattrInternal
(
obj
,
&
attr_dir
,
CLASS_ONLY
,
nullptr
,
0
,
nullptr
,
nullptr
,
nullptr
,
nullptr
);
if
(
dir_result
&&
dir_result
->
cls
==
list_cls
)
{
return
dir_result
;
}
// If __dict__ is present use its keys and add the reset below
Box
*
obj_dict
=
hcb
->
cls
->
getattr
(
"__dict__"
,
nullptr
,
nullptr
);
if
(
obj_dict
)
{
result
=
new
BoxedList
();
assert
(
obj_dict
->
cls
==
dict_cls
);
for
(
auto
&
kv
:
static_cast
<
BoxedDict
*>
(
obj_dict
)
->
d
)
{
listAppend
(
result
,
kv
.
first
);
}
// If __dict__ is present use its keys and add the reset below
Box
*
obj_dict
=
getattr_internal
(
obj
,
"__dict__"
,
false
,
true
,
nullptr
,
nullptr
);
if
(
obj_dict
&&
obj_dict
->
cls
==
dict_cls
)
{
result
=
new
BoxedList
();
for
(
auto
&
kv
:
static_cast
<
BoxedDict
*>
(
obj_dict
)
->
d
)
{
listAppend
(
result
,
kv
.
first
);
}
}
if
(
!
result
)
{
...
...
test/tests/dir.py
View file @
c5ee90e5
...
...
@@ -21,8 +21,8 @@ class TestClass(object):
class
TestClass2
(
object
):
def
__init__
(
self
):
self
.
attribute1
=
None
self
.
__dict__
=
{
'dictAttr'
:
True
}
self
.
__dict__
=
{
'dictAttr'
:
False
,
'attribute1'
:
None
}
self
.
other_attribute
=
False
def
method1
(
self
):
pass
...
...
@@ -50,6 +50,22 @@ dir(int)
dir
(
str
)
dir
(
set
)
tc
=
TestClass
()
for
f
in
dir
(
tc
):
print
tc
.
__dict__
[
f
]
def
test_in_dir
(
names
,
obj
):
r
=
dir
(
obj
)
print
[
n
in
r
for
n
in
names
]
test_in_dir
(
fake
(),
TestClass
())
test_in_dir
([
'attribute1'
,
'method1'
],
TestClass2
)
test_in_dir
([
'attribute1'
,
'method1'
,
'dictAttr'
],
TestClass2
())
test_in_dir
([
'__str__'
,
'__new__'
,
'__repr__'
,
'__dir__'
,
'__init__'
,
'__module__'
]
+
fake
(),
TestClass
)
test_in_dir
([
'__str__'
,
'__new__'
,
'__repr__'
,
'__dir__'
,
'__init__'
,
'__module__'
,
'method1'
,
'dictAttr'
,
'attribute1'
],
TestClass2
)
test_in_dir
([
'attribute1'
,
'dictAttr'
,
'__init__'
,
'__module__'
,
'method1'
,
'other_attribute'
,
'__dict__'
],
TestClass2
())
test_in_dir
(
fake
(),
TestClass
())
print
len
(
fake
())
==
len
(
dir
(
TestClass
()))
for
t
in
[
str
,
int
,
list
,
set
,
dict
]:
test_in_dir
([
'__str__'
,
'__new__'
,
'__repr__'
,
'__dir__'
,
'__module__'
],
t
)
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