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

gh-97959: Fix rendering of routines in pydoc#113941

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

@serhiy-storchaka
Copy link
Member

@serhiy-storchakaserhiy-storchaka commentedJan 11, 2024
edited by bedevere-appbot
Loading

  • Class methods no longer have "method of builtins.type instance" note.
  • Corresponding notes are now added for class and unbound methods.
  • Method and function aliases now have references to the module or the class where the origin was defined if it differs from the current.
  • Bound methods are now listed in the static methods section.
  • Methods of builtin classes are now supported as well as methods of Python classes.

* Class methods no longer have "method of builtins.type instance" note.* Corresponding notes are now added for class and unbound methods.* Method and function aliases now have references to the module or the  class where the origin was defined if it differs from the current.* Bound methods are now listed in the static methods section.* Methods of builtin classes are now supported as well as methods of  Python classes.
@serhiy-storchaka
Copy link
MemberAuthor

Run./python -m pydoc test.pydocfolder to see how different types of methods are rendered now.

@serhiy-storchaka
Copy link
MemberAuthor

@sobolevn, please take a look at this PR. It is much larger than your#98120 and fixes deeper issues. I am not sure that I completely satisfied by its result, there will be more changes in pydoc.

Copy link
Member

@sobolevnsobolevn left a comment

Choose a reason for hiding this comment

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

Thank you! The scale of the internal pydoc change is rather big and complex. It is really hard to tell if all corner cases are covered.

But, tests look very diverse to cover them 👍

A few nitpicks.

Comment on lines +237 to +239
else:
ifobject.__module__!=modname:
returnobject.__module__
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
else:
ifobject.__module__!=modname:
returnobject.__module__
elifobject.__module__!=modname:
returnobject.__module__

This function can also returnNone, not sure if this is desired 🤔

In that case it would render asfrom None inhttps://github.com/python/cpython/pull/113941/files#diff-d2599cb4ccbf37634c5d3089a2750fc6c92c6c98d2a65861ff13d08ed3e9cff5R713-R714

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

In the current form both branches ofif '.' in object.__qualname__: are more symmetric.

And this function always returns non-None if link is not-None.

Comment on lines +710 to +712
else:
ifobject.__module__!=modname:
link='%s.html'%module.__name__
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
else:
ifobject.__module__!=modname:
link='%s.html'%module.__name__
elifobject.__module__!=modname:
link='%s.html'%module.__name__

return'<dl><dt>%s</dt>%s</dl>\n'% (decl,doc)

defdocdata(self,object,name=None,mod=None,cl=None):
defdocdata(self,object,name=None,mod=None,cl=None,*ignored):
Copy link
Member

Choose a reason for hiding this comment

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

Not sure why*ignored is needed 🤔

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Becausehomecls is now passed, but it is only used indocroutine(). Perhapsmod andcl could be included in it, as they are not used too. Some other methods already defined with*ignored parameter.

self.assertIn(' | __repr__(self, /) from builtins.object',lines)
self.assertIn(' | object_repr = __repr__(self, /)',lines)

lines=self.getsection(result,f' | Static methods{where}:',' | '+'-'*70)
Copy link
Member

Choose a reason for hiding this comment

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

'-'*70 can probably be a test helper.

ifclandinspect.getattr_static(cl,realname, [])isobject:
skipdocs=1
if (clisnotNoneand
inspect.getattr_static(cl,realname, [])isobject):
Copy link
Member

Choose a reason for hiding this comment

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

The default value here is rather strange. Why is it[]?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Because it is the simplest method to create an unique not shared value.[] is object is always false, so this condition means "the class have such attribute and it is the same as object".

Copy link
Contributor

Choose a reason for hiding this comment

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

ISTM like that piece of information should be recorded as a comment in the code.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

This is a common idiom. Well, usually it is used in more complex code:

sentinel= [...]result=getattr(obj,name,sentinel)ifresultissentinel: ...

But in this particular case no need to introduce variables for the result and the sentinel, so it all can be simplified.

erlend-aasland reacted with thumbs up emoji
@serhiy-storchakaserhiy-storchaka merged commit2939ad0 intopython:mainFeb 11, 2024
@serhiy-storchakaserhiy-storchaka deleted the pydoc-docroutine branchFebruary 11, 2024 13:19
@serhiy-storchakaserhiy-storchaka added needs backport to 3.11only security fixes needs backport to 3.12only security fixes labelsFeb 11, 2024
@miss-islington-app
Copy link

Thanks@serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks@serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry,@serhiy-storchaka, I could not cleanly backport this to3.11 due to a conflict.
Please backport usingcherry_picker on command line.

cherry_picker 2939ad02be62110ffa2ac6c4d9211c85e1d1720f 3.11

@miss-islington-app
Copy link

Sorry,@serhiy-storchaka, I could not cleanly backport this to3.12 due to a conflict.
Please backport usingcherry_picker on command line.

cherry_picker 2939ad02be62110ffa2ac6c4d9211c85e1d1720f 3.12

serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull requestFeb 11, 2024
…13941)* Class methods no longer have "method of builtins.type instance" note.* Corresponding notes are now added for class and unbound methods.* Method and function aliases now have references to the module or the  class where the origin was defined if it differs from the current.* Bound methods are now listed in the static methods section.* Methods of builtin classes are now supported as well as methods of  Python classes.(cherry picked from commit2939ad0)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-app
Copy link

GH-115296 is a backport of this pull request to the3.12 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.12only security fixes labelFeb 11, 2024
serhiy-storchaka added a commit that referenced this pull requestFeb 11, 2024
…15296)* Class methods no longer have "method of builtins.type instance" note.* Corresponding notes are now added for class and unbound methods.* Method and function aliases now have references to the module or the  class where the origin was defined if it differs from the current.* Bound methods are now listed in the static methods section.* Methods of builtin classes are now supported as well as methods of  Python classes.(cherry picked from commit2939ad0)
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull requestFeb 11, 2024
…honGH-113941) (pythonGH-115296)* Class methods no longer have "method of builtins.type instance" note.* Corresponding notes are now added for class and unbound methods.* Method and function aliases now have references to the module or the  class where the origin was defined if it differs from the current.* Bound methods are now listed in the static methods section.* Methods of builtin classes are now supported as well as methods of  Python classes.(cherry picked from commit2939ad0)(cherry picked from commitcfb79ca)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@serhiy-storchakaserhiy-storchaka removed their assignmentFeb 11, 2024
@serhiy-storchakaserhiy-storchaka removed the needs backport to 3.11only security fixes labelFeb 11, 2024
serhiy-storchaka added a commit that referenced this pull requestFeb 11, 2024
GH-115296) (GH-115302)* Class methods no longer have "method of builtins.type instance" note.* Corresponding notes are now added for class and unbound methods.* Method and function aliases now have references to the module or the  class where the origin was defined if it differs from the current.* Bound methods are now listed in the static methods section.* Methods of builtin classes are now supported as well as methods of  Python classes.(cherry picked from commit2939ad0)(cherry picked from commitcfb79ca)
fsc-eriker pushed a commit to fsc-eriker/cpython that referenced this pull requestFeb 14, 2024
* Class methods no longer have "method of builtins.type instance" note.* Corresponding notes are now added for class and unbound methods.* Method and function aliases now have references to the module or the  class where the origin was defined if it differs from the current.* Bound methods are now listed in the static methods section.* Methods of builtin classes are now supported as well as methods of  Python classes.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@sobolevnsobolevnsobolevn left review comments

@erlend-aaslanderlend-aaslanderlend-aasland left review comments

@ethanfurmanethanfurmanAwaiting requested review from ethanfurmanethanfurman is a code owner

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@serhiy-storchaka@sobolevn@erlend-aasland

[8]ページ先頭

©2009-2025 Movatter.jp