tests/cpydiff: Add test and workaround for function.__module__ attr.
MicroPython does not store any reference from a function object to the module it was defined in, but there is a way to use function.__globals__ to indirectly get the module. See issue #7259. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
605b74f390
commit
47e6c52f0c
|
@ -0,0 +1,13 @@
|
|||
"""
|
||||
categories: Core,Functions
|
||||
description: Function objects do not have the ``__module__`` attribute
|
||||
cause: MicroPython is optimized for reduced code size and RAM usage.
|
||||
workaround: Use ``sys.modules[function.__globals__['__name__']]`` for non-builtin modules.
|
||||
"""
|
||||
|
||||
|
||||
def f():
|
||||
pass
|
||||
|
||||
|
||||
print(f.__module__)
|
Loading…
Reference in New Issue