Skip to content

Conversation

@mtsokol
Copy link
Member

@mtsokol mtsokol commented Dec 3, 2024

This is a follow-up PR after #27716. It updates np.random functions and methods' __module__ to numpy.random.

The only items left with incorrect __module__ are cdef classes, as Cython doesn't allows changing it.

List from here: pytorch/pytorch#136559 (comment)

@mattip
Copy link
Member

mattip commented Dec 3, 2024

For future reference, the cdef problem should be fixed by cython/cython#5479

Copy link
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. For Python files, I would prefer using the set_module helper, because I was in the situation before that I did not want this to happen.
(Specfically, some doctest related utils fail to find the source due to it.)

But, for cython code those things should already be failing, so...

@seberg seberg merged commit 84c3394 into numpy:main Dec 3, 2024
70 checks passed
@mtsokol mtsokol deleted the mtrand-dunder-module branch December 3, 2024 14:54
charris pushed a commit to charris/numpy that referenced this pull request Dec 5, 2024
ENH: update `__module__` in `numpy.random` module
@da-woods
Copy link

da-woods commented Dec 6, 2024

Re: module for cdef classes. A good fix looks really hard. The basic problem is that type defines its own property for __module__ which ignores whatever you set in the class dictionary for static types.

However. For heap types it works:

# distutils: extra_compile_args = -DCYTHON_USE_TYPE_SPECS=1

cdef class C:
    __module__ = "a"

print(C.__module__)  # prints "a"

Is that any use to Numpy?

(I'm also not sure that the issue that @mattip linked is a hugely great fix. It'd fix self.__module__ but not cls.__module__

@seberg
Copy link
Member

seberg commented Dec 6, 2024

Is that any use to Numpy?

Not sure I would enable it just for this sake, but I suspect heap-types are in our future anyway, so I don't mind doing it (unless someone has a clear downside).

FWIW, I don't think allowing to set __module__ and __name__/__qualname__ is very necessary/reasonable for non-heap types.
What I might allow (if it is easy) is exactly this:

cdef class myclass:
    __module__ = "something"

Which would set tp_name to f{__module__}.myclass rather than f{module.__name__}.myclass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants