Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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

Sign up
Appearance settings

DOC: fixes classes decorated with set_module not showing its source on numpy's documentation (#28629)#28645

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

aureliobarbosa
Copy link
Contributor

@aureliobarbosaaureliobarbosa commentedApr 4, 2025
edited
Loading

This PR is intended tofix#28629

Classes decorated with the_utils/set_module decorator can't be inspected for their source file, and thus the current strategy for getting the source for these classes using sphinx extension linkcode do not work. Currently 25 classes are affected. The currently problem doesn't affect functions decorated with set_module.

This task should have been done in many ways (capturing__file__,__module__, or via__code__). I choose to capture__file__ because it allowed to fix the documentation with the inclusion of a very small code snipped on the functionlinkcode_resolve, used by linkcode to obtain the external link to numpy repository. It looked to me the capturing the original__module__ would involve more code and many classes decorated with set_module were just empty, thus avoiding the possibility of capturing any__code__ via function members.

avoid calling stdlib module inspectTST: adds tests for set_module decoratorDOC: adds __file__ attribute to classes decorated with set_modulesimplify set_module and change attribute nameDOC : sets __module_file__ when overriding a __module__ in classesSpecity Exceptionsfix lint error
@aureliobarbosaaureliobarbosaforce-pushed thefix_decorated_class_link_doc branch from6f7127e to9e2f778CompareApril 8, 2025 14:26
@aureliobarbosaaureliobarbosa marked this pull request as ready for reviewApril 8, 2025 14:56
@@ -26,6 +27,12 @@ def example():
"""
def decorator(func):
if module is not None:
if isinstance(func, type):
try:
func.__module_file__ = sys.modules.get(func.__module__).__file__
Copy link
Member

Choose a reason for hiding this comment

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

Let's just call this_module_file. Giving it a dunder name is confusing because someone might think it's a name for a real dunder attribute that CPython supports. Also Python itself could add a dunder attribute with this name in the future. Another way to think about it is the language itself owns the namespace for symbols with dunder names, but leaves the single leading underscore namespace available for private use by Python libraries.

aureliobarbosa reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Done.

@melissawm
Copy link
Member

Feel free to merge if you're happy but I'd love to take a look later today

@aureliobarbosa
Copy link
ContributorAuthor

@melissawm and@ngoldbaum Sorry, but unfortunately it is not building the path in the right way! I will give another shot at fixing this later.

@aureliobarbosa
Copy link
ContributorAuthor

Now it seems to be working. When building locally it points to the right file on themain branch, as expected. I checked it only for poly1d, so far. I don't now how to make a test for linkcode_resolve (should this be the case of a test?).

Would like the commits to be squashed?

Copy link
Contributor

@mhvkmhvk left a comment

Choose a reason for hiding this comment

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

This looks good to me, nice! Unfortunately, I don't think numpy is set up to do a test docs run, so I don't know how to test it other than what you did, by building locally.

Some absolutely nitpicky comments in-line -- and might as well squash the commits when you do those. (But perhaps see first if there are other comments, and of course check that they don't break things...)

@@ -26,6 +27,12 @@ def example():
"""
def decorator(func):
if module is not None:
if isinstance(func, type):
try:
func._module_file = sys.modules.get(func.__module__).__file__
Copy link
Contributor

Choose a reason for hiding this comment

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

Total nitpick, but justfunc._module_file = sys.modules[func.__module__].__file__ would be fine since you check forKeyError.

@aureliobarbosa
Copy link
ContributorAuthor

@melissawm As soon as you take a look and review I will squash the commits (and fetch, etc).

Copy link
Member

@melissawmmelissawm left a comment
edited
Loading

Choose a reason for hiding this comment

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

Cool fix for an annoying problem! Tested locally and it works great. Thanks!

EDIT: Feel free to squash but we can do it for you when merging. Cheers!

@ngoldbaum
Copy link
Member

Thanks@aureliobarbosa!

aureliobarbosa reacted with hooray emoji

@ngoldbaumngoldbaum merged commite151f0d intonumpy:mainApr 15, 2025
72 checks passed
@github-project-automationgithub-project-automationbot moved this fromAwaiting a code review toCompleted inNumPy first-time contributor PRsApr 15, 2025
@aureliobarbosaaureliobarbosa deleted the fix_decorated_class_link_doc branchApril 16, 2025 07:15
VascoConceicao pushed a commit to VascoConceicao/numpy that referenced this pull requestMay 6, 2025
…n numpy's documentation (numpy#28629) (numpy#28645)* DOC: store file with set_module in classesavoid calling stdlib module inspectTST: adds tests for set_module decoratorDOC: adds __file__ attribute to classes decorated with set_modulesimplify set_module and change attribute nameDOC : sets __module_file__ when overriding a __module__ in classesSpecity Exceptionsfix lint error* rename variable* fix variable name* fix path
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@mhvkmhvkmhvk left review comments

@melissawmmelissawmmelissawm approved these changes

@ngoldbaumngoldbaumAwaiting requested review from ngoldbaum

Assignees
No one assigned
Projects
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

DOC: any class decorated with@set_module does not show its source on automatically generated documentation
4 participants
@aureliobarbosa@melissawm@ngoldbaum@mhvk

[8]ページ先頭

©2009-2025 Movatter.jp