adafruit / adafruit/Adafruit_CircuitPython_EMC2101
Overriding property getter and setters is not supported in Circuitpython
- Dominant language
- Python
- Stars
- 6
- Forks
- 7
- PR merge metrics
- No merged PRs in 30d
Description
As reported on the forum: https://forums.adafruit.com/viewtopic.php?t=199790
Trying to use the LUT example results in:
```py
Lut: 27 deg C => 25.0% duty cycle
34 deg C => 50.0% duty cycle
42 deg C => 75.0% duty cycle
Traceback (most recent call last):
File "", line 45, in
File "adafruit_emc2101/emc2101_ext.py", line 230, in fan_speed
File "adafruit_emc2101/__init__.py", line 267, in fan_speed
File "adafruit_register/i2c_struct.py", line 80, in __get__
AttributeError: 'super' object has no attribute 'i2c_device'
```
Can anyone with the module test it on a Circuitpython board and confirm ?
I don't pretend to understand why it's that error, but when I did some tests I ended up noticing that in Circuitpython you can't override `@property` accessors from subclasses, which `emc2101_ext` and `emc2101_sub` do.
Here is where it does it for example:
https://github.com/adafruit/Adafruit_CircuitPython_EMC2101/blob/aea77f5a62ce099c99a35bfe7eae16676dc9fb8b/adafruit_emc2101/emc2101_ext.py#L223-L230
This works in C python, but not in Circuitpython.
```py
class Thing:
def __init__(self, i2c):
self.i2c_device = i2c
@property
def i2c(self):
print(self)
return self.i2c_device
class Thing_sub(Thing):
def __init__(self, i2c):
super().__init__(i2c)
@property
def i2c(self):
return super().i2c
c = Thing_sub("I2C")
print(c.i2c)
```
```
code.py output:
, >
Traceback (most recent call last):
File "code.py", line 17, in
File "code.py", line 14, in i2c
File "code.py", line 7, in i2c
AttributeError: 'super' object has no attribute 'i2c_device'
```
It's like super().i2c does call the i2c getter but with `self` being some `super` object that isn't what it should be ?
I don't know what a solution would be, maybe change the accessor methods to call a `_set_fan_speed()` method that could be overloaded in the sub classes, and called with super() as needed, since that form of overloading is known to work.
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the LUT example on a CircuitPython board, then inspect the overridden properties in adafruit_emc2101/emc2101_ext.py around lines 223-230 and the related emc2101_sub implementation. Read adafruit_register/i2c_struct.py around line 80 to understand the reported AttributeError. Done means the fan-speed accessors work on CircuitPython without the super/i2c_device failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100