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
8c5b2a78
Commit
8c5b2a78
authored
Dec 16, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Basic support for issubclass() on old style classes
parent
54746476
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
8 deletions
+26
-8
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+13
-5
src/runtime/classobj.cpp
src/runtime/classobj.cpp
+3
-3
src/runtime/classobj.h
src/runtime/classobj.h
+1
-0
test/tests/oldstyle_classes.py
test/tests/oldstyle_classes.py
+9
-0
No files found.
src/runtime/builtin_modules/builtins.cpp
View file @
8c5b2a78
...
...
@@ -340,13 +340,21 @@ Box* isinstance_func(Box* obj, Box* cls) {
}
Box
*
issubclass_func
(
Box
*
child
,
Box
*
parent
)
{
if
(
parent
->
cls
==
classobj_cls
)
{
Py_FatalError
(
"don't handle issubclass for old style classes yet"
);
if
(
child
->
cls
!=
type_cls
&&
child
->
cls
!=
classobj_cls
)
raiseExcHelper
(
TypeError
,
"issubclass() arg 1 must be a class"
);
RELEASE_ASSERT
(
parent
->
cls
!=
tuple_cls
,
"unsupported"
);
if
(
child
->
cls
==
classobj_cls
)
{
if
(
parent
->
cls
!=
classobj_cls
)
return
False
;
return
boxBool
(
classobjIssubclass
(
static_cast
<
BoxedClassobj
*>
(
child
),
static_cast
<
BoxedClassobj
*>
(
parent
)));
}
RELEASE_ASSERT
(
child
->
cls
==
type_cls
,
""
);
// TODO parent can also be a tuple of classes
RELEASE_ASSERT
(
parent
->
cls
==
type_cls
,
""
)
;
assert
(
child
->
cls
==
type_cls
);
if
(
parent
->
cls
!=
type_cls
)
return
False
;
return
boxBool
(
isSubclass
(
static_cast
<
BoxedClass
*>
(
child
),
static_cast
<
BoxedClass
*>
(
parent
)));
}
...
...
src/runtime/classobj.cpp
View file @
8c5b2a78
...
...
@@ -25,19 +25,19 @@ namespace pyston {
BoxedClass
*
classobj_cls
,
*
instance_cls
;
bool
classIssubclass
(
BoxedClassobj
*
child
,
BoxedClassobj
*
parent
)
{
bool
class
obj
Issubclass
(
BoxedClassobj
*
child
,
BoxedClassobj
*
parent
)
{
if
(
child
==
parent
)
return
true
;
for
(
auto
e
:
child
->
bases
->
elts
)
{
if
(
e
->
cls
==
classobj_cls
&&
classIssubclass
(
static_cast
<
BoxedClassobj
*>
(
e
),
parent
))
if
(
e
->
cls
==
classobj_cls
&&
class
obj
Issubclass
(
static_cast
<
BoxedClassobj
*>
(
e
),
parent
))
return
true
;
}
return
false
;
}
bool
instanceIsinstance
(
BoxedInstance
*
obj
,
BoxedClassobj
*
cls
)
{
return
classIssubclass
(
obj
->
inst_cls
,
cls
);
return
class
obj
Issubclass
(
obj
->
inst_cls
,
cls
);
}
static
Box
*
classLookup
(
BoxedClassobj
*
cls
,
const
std
::
string
&
attr
)
{
...
...
src/runtime/classobj.h
View file @
8c5b2a78
...
...
@@ -27,6 +27,7 @@ class BoxedInstance;
extern
BoxedClass
*
classobj_cls
,
*
instance_cls
;
bool
instanceIsinstance
(
BoxedInstance
*
obj
,
BoxedClassobj
*
cls
);
bool
classobjIssubclass
(
BoxedClassobj
*
child
,
BoxedClassobj
*
parent
);
class
BoxedClassobj
:
public
Box
{
public:
...
...
test/tests/oldstyle_classes.py
View file @
8c5b2a78
...
...
@@ -102,3 +102,12 @@ print isinstance(D(), C)
print
str
(
f
)[:
26
]
print
repr
(
f
)[:
26
]
class
OldStyleClass
:
pass
print
issubclass
(
OldStyleClass
,
object
)
print
isinstance
(
OldStyleClass
(),
OldStyleClass
)
print
issubclass
(
OldStyleClass
,
OldStyleClass
)
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