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
3e4896eb
Commit
3e4896eb
authored
Jan 21, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix a regression -- __dict__ should be checked before calling __getattr__
parent
8628cdc9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
7 deletions
+19
-7
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+11
-7
test/tests/getattr_dict.py
test/tests/getattr_dict.py
+8
-0
No files found.
src/runtime/objmodel.cpp
View file @
3e4896eb
...
...
@@ -1455,6 +1455,16 @@ extern "C" Box* getattr(Box* obj, const char* attr) {
static
StatCounter
slowpath_getattr
(
"slowpath_getattr"
);
slowpath_getattr
.
log
();
bool
is_dunder
=
(
attr
[
0
]
==
'_'
&&
attr
[
1
]
==
'_'
);
if
(
is_dunder
)
{
if
(
strcmp
(
attr
,
"__dict__"
)
==
0
)
{
// TODO this is wrong, should be added at the class level as a getset
if
(
obj
->
cls
->
instancesHaveHCAttrs
())
return
makeAttrWrapper
(
obj
);
}
}
if
(
VERBOSITY
()
>=
2
)
{
#if !DISABLE_STATS
std
::
string
per_name_stat_name
=
"getattr__"
+
std
::
string
(
attr
);
...
...
@@ -1500,13 +1510,7 @@ extern "C" Box* getattr(Box* obj, const char* attr) {
return
val
;
}
if
(
attr
[
0
]
==
'_'
&&
attr
[
1
]
==
'_'
)
{
if
(
strcmp
(
attr
,
"__dict__"
)
==
0
)
{
// TODO this is wrong, should be added at the class level as a getset
if
(
obj
->
cls
->
instancesHaveHCAttrs
())
return
makeAttrWrapper
(
obj
);
}
if
(
is_dunder
)
{
// There's more to it than this:
if
(
strcmp
(
attr
,
"__class__"
)
==
0
)
{
assert
(
obj
->
cls
!=
instance_cls
);
// I think in this case __class__ is supposed to be the classobj?
...
...
test/tests/getattr_dict.py
0 → 100644
View file @
3e4896eb
# Regression test: __dict__ should be accessible from __getattr__
class
C
(
object
):
def
__getattr__
(
self
,
attr
):
print
len
(
self
.
__dict__
)
return
5
print
C
().
a
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