Skip to content

MAINT: set __module__ for more array_function_dispatch uses #12270

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

Merged
merged 1 commit into from
Oct 26, 2018

Conversation

shoyer
Copy link
Member

@shoyer shoyer commented Oct 26, 2018

I noticed a few more functions using array_function_dispatch where I had
not set the module in #12251.

I used this script::

import types

def check_module(module):
    for name in dir(module):
        item = getattr(module, name)
        if isinstance(item, types.FunctionType):
            print(f'{item.__module__}.{item.__name__}')

>>> import numpy
>>> check_module(numpy)
...

Note that functions without overrides like numpy.ones still display the
module in which they are defined, e.g., numpy.core.numeric.ones. We should
probably fix that, too, probably most cleanly adding a decorator that sets
__module__, e.g.,

def set_module(module):
    def decorator(func):
        func.__module__ = module
        return func
    return decorator

...

@set_module('numpy')
def ones(shape, dtype=None, order='C'):
    ...

I noticed a few more functions using ``array_function_dispatch`` where I had
not set the module, using this script::

    import types

    def check_module(module):
        for name in dir(module):
            item = getattr(module, name)
            if isinstance(item, types.FunctionType):
                print(f'{item.__module__}.{item.__name__}')

    >>> import numpy
    >>> check_module(numpy)
    ...

Note that functions without overrides like ``numpy.ones`` still display the
module in which they are defined, e.g., ``numpy.core.numeric.ones``. We should
probably fix that, too, probably most cleanly adding a decorator that sets
``__module__``, e.g.,

    def set_module(module):
        def decorator(func):
            func.__module__ = module
            return func
        return decorator

    ...

    @set_module('numpy')
    def ones(shape, dtype=None, order='C'):
        ...
@shoyer
Copy link
Member Author

shoyer commented Oct 26, 2018

cc @ahaldane

@ahaldane
Copy link
Member

LGTM, merging. Thanks Stephan.

@ahaldane ahaldane merged commit c0d4c74 into numpy:master Oct 26, 2018
@shoyer shoyer deleted the array-function-dispatch-module-fixup branch October 26, 2018 18:00
@charris charris changed the title MAINT: set __module__ for more array_function_dispatch uses MAINT: set __module__ for more array_function_dispatch uses Nov 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants