FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

ENH: update `__module__` in `numpy.random` module by mtsokol · Pull Request #27891 · numpy/numpy · GitHub

/ numpy Public

ENH: update __module__ in numpy.random module - #27891

Merged
seberg merged 1 commit into
numpy:mainfrom
mtsokol:mtrand-dunder-module
Dec 3, 2024
Merged

ENH: update __module__ in numpy.random module#27891
seberg merged 1 commit into
numpy:mainfrom
mtsokol:mtrand-dunder-module

Conversation

mtsokol commented Dec 3, 2024
edited
Loading

Copy link
Copy Markdown
Member

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 commented Dec 3, 2024

Copy link
Copy Markdown
Member

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

seberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 merged commit 84c3394 into numpy:main Dec 3, 2024
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 commented Dec 6, 2024
edited
Loading

Copy link
Copy Markdown
Contributor

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 commented Dec 6, 2024
edited
Loading

Copy link
Copy Markdown
Member

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.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL