kopia lustrzana https://github.com/micropython/micropython
tests: Add test for when instance member overrides class member.
rodzic
5b7aa294e0
commit
c33ecb83ba
|
@ -457,7 +457,7 @@ STATIC mp_obj_t instance_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_i
|
||||||
}
|
}
|
||||||
|
|
||||||
void mp_obj_instance_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
void mp_obj_instance_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||||
// logic: look in obj members then class locals (TODO check this against CPython)
|
// logic: look in instance members then class locals
|
||||||
assert(is_instance_type(mp_obj_get_type(self_in)));
|
assert(is_instance_type(mp_obj_get_type(self_in)));
|
||||||
mp_obj_instance_t *self = self_in;
|
mp_obj_instance_t *self = self_in;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
# test that we can override a class method with an instance method
|
||||||
|
|
||||||
|
class A:
|
||||||
|
def foo(self):
|
||||||
|
return 1
|
||||||
|
|
||||||
|
a = A()
|
||||||
|
print(a.foo())
|
||||||
|
a.foo = lambda:2
|
||||||
|
print(a.foo())
|
Ładowanie…
Reference in New Issue