Open lesamouraipourpre opened 3 years ago
Transferring to CircuitPython as this sounds like a change is required in CircuitPython and not on the Pi.
@tannewt might this have been fixed?
This is not fixed. I tested it at f3920c49dc7c717beb630ada61e61d75de2cf60d.
It looks like the native_group()
call is being a passed a super
object and mp_obj_cast_to_native_base()
doesn't know how to convert that to the native base. I'm not sure if that's what it should do or if it shouldn't be passed the super object in the first place.
A non-displayio example would be really helpful because then we could add a test for it and debug via the unix port.
I wrote a gist that shows what may be as many as 3 distinct problems with subclassing, properties, & super(). The test uses NativeBaseClass
, a class that @tannewt recently added to the unix coverage build for exactly this sort of testing (thanks!). This test runs on only on the "unix coverage build", not on microcontrollers.
class N(NativeBaseClass):
@property
def subtest(self):
return super().test
@subtest.setter
def subtest(self, value):
# BUG: In this context something prevents the compiler from
# transforming the super() call to the 2-arg version
# which results in
# "TypeError: function takes 2 positional arguments but 0 were given"
super().test = value
# This alternative gets further along (allows triggering AttributeError
# incorrectly instead):
super(N, self).test = value
n = N()
n.test = 7
print(n.test)
print(n.subtest) # BUG: segfaults on this line
# BUG: AttributeError: can't set attribute 'test'
n.subtest = 8
print(n.test)
print(n.subtest)
Following on from a comment by @kmatch98 on adafruit/Adafruit_CircuitPython_Display_Text#116 about the difficulty subclassing/overriding Group, I've been trying to subclass Label with the example class
GridLabel
below.This code works as expected on a Raspberry Pi, but crashes on a PyPortal Pynt with the following:
This error is raised from
circuitpython/shared-bindings/displayio/Group.c
in the method:As my example code uses the super() proxy object to call the parent set method and is failing the
mp_instance_cast_to_native_base()
method I assume this method is not able to handle a proxy object and returns MP_OBJ_NULL.As far as I can tell my example is not unreasonable and should work in CircuitPython.