← index #5669Issue #1697
Related · high · value 2.727
QUERY · ISSUE

Descriptor attribute access on a class doesn't call __get__

openby tannewtopened 2020-02-19updated 2020-02-20
py-core

CPython calls __get__ with obj as None when a descriptor is accessed on the class itself rather than an instance. MicroPython returns the descriptor instance instead of calling __get__.

CANDIDATE · ISSUE

classmethod fetches parent attribute instead of child attribute when called via child object

closedby mbueschopened 2015-12-09updated 2015-12-09

CPython 2 and 3 print 1 for the following code, however MicroPython prints 0

class A(object):
        foo = 0

        @classmethod
        def bar(cls):
                print(cls.foo)

class B(A):
        foo = 1

B().bar()

I use this to have a generic base class with generic data structures that can be extended by derived classes. The generic classmethod is supposed to use the extended data, if it was called via the derived object.

The actual code doing this is here (generic) https://github.com/mbuesch/awlsim/blob/master/awlsim/core/hardware.py and here (derived) https://github.com/mbuesch/awlsim/blob/master/awlsimhw_debug/main.py

Is there a workaround to this issue?

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied