microbit-foundation / micropython-microbit-v2

Temporary home for MicroPython for micro:bit v2 as we stablise it before pushing upstream
MIT License
42 stars 23 forks source link

Module in the filesystem has the __class__ dunder #104

Closed microbit-carlos closed 2 years ago

microbit-carlos commented 2 years ago

With a my_module.py file that only contains FOO = 0:

MicroPython 569e361 on 2022-06-20; micro:bit v2.0.0 with nRF52833
Type "help()" for more information.
>>> import my_module
>>> dir(my_module)
['__class__', '__name__', 'FOO']
>>> my_module.__class__
<class 'module'>

I don't think the __class__ attribute here is correct? Trying the same in CPython doesn't have that dunder attribute.

dpgeorge commented 2 years ago

Trying the same in CPython doesn't have that dunder attribute.

CPython does have it, it's just not listed by dir(...). Try my_module.__class__ under CPython and you get the same as MicroPython.

jaustin commented 2 years ago

We're curious to know why CPython doesn't show this, but happy to close this as an issue :)

dpgeorge commented 2 years ago

We're curious to know why CPython doesn't show this

Honestly, I don't know! Maybe it filters out __class__ from dir on modules.