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

DOC: Fixes absent line numbers on link to classes decorated with set_module #28918

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

Conversation

aureliobarbosa
Copy link
Contributor

PR #28645 was intended to fix issue #28629, which indicated that wrong links were appearing on documentation for classes decorated with set_module. A minor problem appeared on that fix, since line numbers were not assigned to the link on those decorated classes.

This PR fixes this problem by storing the original value of property __module__ of decorated classes (instead of capturing the property __file__ of the original module).

In my opinion the current approach is simpler.

@aureliobarbosa
Copy link
Contributor Author

@melissawm and @ngoldbaum

Would you mind reviewing a follow up from #28645?

numpy/_utils/__init__.py Outdated Show resolved Hide resolved
fn = relpath(fn, start=dirname(numpy.__file__))
# This can be removed when removing the decorator set_module. Fix issue #28629
if hasattr(obj, '_module_source'):
obj = copy(obj)
Copy link
Member

Choose a reason for hiding this comment

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

this is a no-op:

>>> import copy
>>> class A: ...
... 
>>> copy.copy(A) is A
True

and it's the same story with copy.deepcopy:

>>> copy.deepcopy(A) is A
True

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing that, just got to realize that copy is a little bit subtle.

The intention of the copy was to not introducing any side effect, even while running on the documentation.
Now, the whole thing about changing __module__ is about its side effect and, as discussed previously it was needed downstream.

Since this code is running while generating the docs, do you think we could just recover the original __module__ without further problems?

Copy link
Member

Choose a reason for hiding this comment

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

Since this code is running while generating the docs, do you think we could just recover the original __module__ without further problems?

I guess that depends on whether the docs currently (also) use the patched __module__ somewhere, and if so, where/when that happens. Put differently; it shouldn't be a problem if it doesn't also change the documented module paths.

But I'm not very familiar with this doc generation code, so it's probably best if another maintainer could chime in here.

Copy link
Member

Choose a reason for hiding this comment

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

As long as the docs build fine and there aren't any other regressions introduced it should be fine. You could try looking at a diff of the docs build before and after applying the change to see what changes.

It looks like there are some new warnings in the docs build - those need to be fixed too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. I will take a look at this and give the feedback here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jorenham and @ngoldbaum.

This is ready for review.

@aureliobarbosa aureliobarbosa marked this pull request as draft May 13, 2025 18:10
@aureliobarbosa aureliobarbosa force-pushed the fix_classes_with_incorrect_line_numbers branch from de6f864 to 6ed0ece Compare May 14, 2025 14:54
@aureliobarbosa aureliobarbosa marked this pull request as ready for review May 14, 2025 15:23
Copy link
Member

@jorenham jorenham left a comment

Choose a reason for hiding this comment

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

the poly1d docs now indeed include line numbers in the source code link:

https://output.circle-artifacts.com/output/job/482f8884-cb97-4a2f-8430-7fd1c14dc47b/artifacts/0/doc/build/html/reference/generated/numpy.poly1d.html#numpy.poly1d

The line numbers are offset because this branch isn't up-to-date with main. Replacing the url and branch with this one, shows that the line numbers are indeed correct: https://github.com/aureliobarbosa/numpy/blob/fix_classes_with_incorrect_line_numbers/numpy/lib/_polynomial_impl.py#L1087-L1457

@ngoldbaum
Copy link
Member

Thanks @aureliobarbosa! Sorry for taking a little while to get back to this.

@ngoldbaum ngoldbaum merged commit 2a7a0d0 into numpy:main May 20, 2025
74 checks passed
@aureliobarbosa
Copy link
Contributor Author

Thanks @ngoldbaum

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.