-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Calling inherited sensor methods crashes MicroPython #777
Comments
I don't think there are any config switches for this. I think we just have to call If we really want to avoid this crash, we could possibly define a Or maybe we need to add checks that fields are initialized (not zero) before using them? |
Yep, planning to look at this soonish, there’s some things I was thinking to rework in this area anyway. |
On closer inspection, it isn't due to inheritance per se. It also crashes with simply It's perhaps just because we don't assert the type of self in each of our methods. We could do that, but we'd need to consider the trade off with build size. On that note, I've been thinking we could do some fun tricks to reduce the code size of sensor types...
They don't have a We could probably encourage composition over inheritance instead. |
👍 |
This works: from pybricks.parameters import Port
from pybricks.iodevices import PUPDevice
class NewSensor(PUPDevice):
def __init__(self, port):
super().__init__(port)
print(self.info())
print(self.read(0))
sensor = NewSensor(Port.C) |
We should probably open a separate issue for this one, but there is |
It costs 156 bytes on Move Hub. Considering that it prevents a crash, that seems like it would be worth it. |
I see your WIP commmit now. That's nice for a more descriptive error, but we shouldn't need it to just fix the crash. Just enabling |
Except it doesn't fix the crash in the It only fixes crashing in cases like to Calling methods in |
Just enabling the check self config (without the WIP commit) fixed this for me as well. |
I split it to separate issue.
Agreed that this might be too expensive. Alternatively, it could be handled by the I was hoping we could avoid writing any user code that could crash the hub, but maybe this is just one of those limitations we just have to document. |
After a closer look, it does look like this is pretty much the same as #805. Better yet, it can be fixed. It could be done with a variant of the WIP branch (and defining the check self macro correctly, and also doing it manually for non-kwarg funcs), but I'll have a look whether we can do it with a smaller code size impact. |
Found it. One line of code :) |
Describe the bug
Classes that inherit a sensor will crash when calling inherited methods.
It's possible we don't have the right flags enabled to support this.
Now that we support multi-file projects, making classes is kind of expected/encouraged, so we should probably re-enable them if we can.
To reproduce
The text was updated successfully, but these errors were encountered: