Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

ENH: Make __module__ attribute coherent across API #27716

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 4 commits into from
Nov 20, 2024

Conversation

mtsokol
Copy link
Member

@mtsokol mtsokol commented Nov 7, 2024

Hi!
As described in pytorch/pytorch#136559 __module__ is incoherent across Python API. I think by definition, function's __module__ attribute should return the name of the module that this function originates from.

@mtsokol mtsokol self-assigned this Nov 7, 2024
@rgommers
Copy link
Member

Looks good to me overall so far, thanks for pushing this forward @mtsokol.

I think by definiton, function's __module__ attribute should return the name of the module that this function originates from.

To clarify since "originates" could be misunderstood: each function is available in the public API from a single namespace (on rare occasions, some object may be exposed in 2 places still), and we want to ensure that __module__ points to that public namespace, and not to the private namespace/object where the implementation lives.

@mtsokol mtsokol added this to the 2.2.0 release milestone Nov 12, 2024
@mtsokol mtsokol changed the title [WIP] ENH: Make __module__ attribute coherent across API ENH: Make __module__ attribute coherent across API Nov 14, 2024
@mtsokol mtsokol marked this pull request as ready for review November 14, 2024 15:22
@mtsokol
Copy link
Member Author

mtsokol commented Nov 14, 2024

Ok, I think it's ready for reviews. Some comments:

  • I skip all numpy.random module (all functions have __module__ as numpy.random.mtrand there instead of numpy.random) as, it looks like, cython disallows overriding __module__ (need to ask about it in the mailing list).
  • I also cleaned up ma a bit to adhere to "each function is exported from one place" rule, as it was required by my test.

@charris charris changed the title ENH: Make __module__ attribute coherent across API ENH: Make __module__ attribute coherent across API Nov 14, 2024
@mtsokol mtsokol force-pushed the module-attribute branch 2 times, most recently from 377730a to c13ca1b Compare November 15, 2024 13:26
@rgommers
Copy link
Member

I skip all numpy.random module (all functions have __module__ as numpy.random.mtrand there instead of numpy.random) as, it looks like, cython disallows overriding __module__ (need to ask about it in the mailing list).

Ouch, that is bad. In NumPy 1.26 the attribute did contain numpy.random, which is more correct. Worth raising upstream indeed.

@mattip
Copy link
Member

mattip commented Nov 15, 2024

When we discussed this at the triage meeting, we recommended an approach to consider the cython-generated code in a separate PR

@mattip mattip merged commit 91aed7b into numpy:main Nov 20, 2024
69 checks passed
@mtsokol mtsokol deleted the module-attribute branch November 20, 2024 18:24
@mattip
Copy link
Member

mattip commented Nov 20, 2024

Thanks @mtsokol. We can adjust this as needed going forward. Hopefully we will find a way to se the cython-generated code in random's __module__.

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.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.