diff options
author | Damien George <damien@micropython.org> | 2024-10-01 10:26:27 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2024-10-16 15:03:30 +1100 |
commit | 1b89c503db690967d50699abe0bfa942f6f6b15e (patch) | |
tree | 5dbde19959d3f56328bf95dceff981e21ae28106 /py | |
parent | 3fecab58a0bab6db736d24c0be7e78e04c651cb0 (diff) | |
download | micropython-1b89c503db690967d50699abe0bfa942f6f6b15e.tar.gz micropython-1b89c503db690967d50699abe0bfa942f6f6b15e.zip |
py/objtype: Don't delegate lookup of descriptor methods to __getattr__.
When descriptors are enabled, lookup of the `__get__`, `__set__` and
`__delete__` descriptor methods should not be delegated to `__getattr__`.
That follows CPython behaviour.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'py')
-rw-r--r-- | py/objtype.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/py/objtype.c b/py/objtype.c index 847216982a..b9af100899 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -660,6 +660,13 @@ static void mp_obj_instance_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *des // try __getattr__ if (attr != MP_QSTR___getattr__) { + #if MICROPY_PY_DESCRIPTORS + // With descriptors enabled, don't delegate lookups of __get__/__set__/__delete__. + if (attr == MP_QSTR___get__ || attr == MP_QSTR___set__ || attr == MP_QSTR___delete__) { + return; + } + #endif + #if MICROPY_PY_DELATTR_SETATTR // If the requested attr is __setattr__/__delattr__ then don't delegate the lookup // to __getattr__. If we followed CPython's behaviour then __setattr__/__delattr__ |