micropython-ulab/snippets/numpy/core/overrides.py
2022-01-14 10:09:34 -08:00

22 lines
No EOL
562 B
Python

# This file is part of the micropython-ulab project, https://github.com/v923z/micropython-ulab
#
# The MIT License (MIT)
#
# Copyright (c) 2022 Phil Jepsen
import sys
def set_module(module):
"""Decorator for overriding __module__ on a function or class.
Example usage::
@set_module('numpy')
def example():
pass
assert example.__module__ == 'numpy'
"""
def decorator(func):
if module is not None:
sys.modules[func.__globals__['__name__']] = module
return func
return decorator