microbit-foundation / micropython-microbit-stubs

Type stubs for MicroPython for micro:bit to support the micro:bit Python Editor V3
https://python.microbit.org/
Other
3 stars 2 forks source link

Add mem{8,16,32} to machine. #35

Closed microbit-matt-hillsdon closed 2 years ago

microbit-matt-hillsdon commented 2 years ago

https://github.com/microbit-foundation/python-editor-next/issues/723

microbit-matt-hillsdon commented 2 years ago

@microbit-carlos, would be great if you could review. Is there some better option for the original code on the linked issue?

microbit-matt-hillsdon commented 2 years ago

Preview build of the editor with these stubs building now. Will be at: https://review-python-editor-next.microbit.org/mem/ https://github.com/microbit-foundation/python-editor-next/pull/724

microbit-carlos commented 2 years ago

Is there some better option for the original code on the linked issue?

Not sure I understand the question, better than what code? Accessing random memory using machine.mem32?

microbit-matt-hillsdon commented 2 years ago

Not sure I understand the question, better than what code? Accessing random memory using machine.mem32?

@microbit-carlos, from what I can read from the source in the screenshot it seems like it's not randomly chosen, but instead to set pin0 into high drive mode. Image is on https://github.com/microbit-foundation/python-editor-next/issues/723#issue-1225065824

microbit-carlos commented 2 years ago

Right, sorry, I didn't mean "random" in the literal sense. But I guess that does answer the question about what you were referring to when you said "original code".

That is the only way right now to configure peripherals in MicroPython to something different than what CODAL does (using Python code). So that's why they accessory library has done that.

Nevertheless, even if there was a better way to do that, this PR is still required to correctly parse the machine.mem8/16/32 instances.

microbit-carlos commented 2 years ago

Looking at this image: image

There is no way to hide the mem class definition in the API viewer?

microbit-carlos commented 2 years ago

I guess is similar to MicroBitDigitalPin, which as classes that will appear in the API sidebar, but cannot be used in the code. Is it worth adding a note that the class cannot be instantiated?

microbit-matt-hillsdon commented 2 years ago

I guess is similar to MicroBitDigitalPin, which as classes that will appear in the API sidebar, but cannot be used in the code. Is it worth adding a note that the class cannot be instantiated?

I nearly did that, I expected to find text I could reuse on Button or MicroBitDigitalPin but we haven't done it there. I also felt that "instantiated" is a bit jargon-y. I'll raise a separate issue.

microbit-matt-hillsdon commented 2 years ago

I nearly did that, I expected to find text I could reuse on Button or MicroBitDigitalPin but we haven't done it there. I also felt that "instantiated" is a bit jargon-y. I'll raise a separate issue.

Raised https://github.com/microbit-foundation/micropython-microbit-stubs/issues/37