Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
3ff259a2
Commit
3ff259a2
authored
Dec 09, 2015
by
Damien George
Browse files
py: Fix calling of parent classmethod from instance of subclass.
Addresses issue #1697.
parent
1be0fde4
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/runtime.c
View file @
3ff259a2
...
...
@@ -934,6 +934,11 @@ void mp_convert_member_lookup(mp_obj_t self, const mp_obj_type_t *type, mp_obj_t
dest
[
0
]
=
((
mp_obj_static_class_method_t
*
)
MP_OBJ_TO_PTR
(
member
))
->
fun
;
}
else
if
(
MP_OBJ_IS_TYPE
(
member
,
&
mp_type_classmethod
))
{
// return a bound method, with self being the type of this object
// this type should be the type of the original instance, not the base
// type (which is what is passed in the 'type' argument to this function)
if
(
self
!=
MP_OBJ_NULL
)
{
type
=
mp_obj_get_type
(
self
);
}
dest
[
0
]
=
((
mp_obj_static_class_method_t
*
)
MP_OBJ_TO_PTR
(
member
))
->
fun
;
dest
[
1
]
=
MP_OBJ_FROM_PTR
(
type
);
}
else
if
(
MP_OBJ_IS_TYPE
(
member
,
&
mp_type_type
))
{
...
...
tests/basics/subclass_classmethod.py
View file @
3ff259a2
...
...
@@ -10,3 +10,22 @@ class Sub(Base):
Sub
.
foo
()
# overriding a member and accessing it via a classmethod
class
A
(
object
):
foo
=
0
@
classmethod
def
bar
(
cls
):
print
(
cls
.
foo
)
def
baz
(
self
):
print
(
self
.
foo
)
class
B
(
A
):
foo
=
1
B
.
bar
()
# class calling classmethod
B
().
bar
()
# instance calling classmethod
B
().
baz
()
# instance calling normal method
Write
Preview
Supports
Markdown
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