-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
pydoc
renders from builtins.type
note, even if it is incorrect
#97959
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
Comments
A couple of extra thoughts after reading some more source code: if _is_bound_method(object):
imclass = object.__self__.__class__
if cl:
if imclass is not cl:
note = ' from ' + classname(imclass, mod) Ok, looks like this is in sync with the following example: import pydoc
from types import MethodType
class My:
some = MethodType(some, 1)
print(pydoc.plain(pydoc.render_doc(My))) which outputs:
I think that
|
Good catch. Why this "from ..." was added in the first case? In what cases it was useful. |
I found only one: when class Some:
a = MethodType(some_func, some_instance) Plus, |
But where is it used in the real code? If make this code raising an error instead of adding "from ..." and run pydoc for all stdlib modules, what will fail? Investigate also the history of that code, commit message or issue text can explain its purpose. |
So, I got back to it. Here's what I found. test resultsRunning
Only historyThere are two commits that touch this line:
So, I can conclude that these lines have something to do with old unbound methods.
|
I do not see any value in the |
Not sure if this is related, but
It seems to me that instead of |
* 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.
This issue is much much more complex than it looked at first glance. If you look at the code, you will see other issues with notes for routines. For example an "unbound method" note is never added to unbound methods. It does not work with methods of builtin classes. It seems that this code was written to handle classic classes, and the support of new-style classes was never complete. Some changes was made later to fix runtime errors, but it was not checked that the result is correct and that all cases are supported. Other issue, is that class members that are bound methods were included in the methods section. But they behave rather like static methods, because they do not accept the self argument. #113941 fixes these and other issues. There are still unfixed issues, for example nested classes are not supported (#85799), and unbound methods of builtin classes are not visible as module members (#113942), but this PR is already large. |
* 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.
…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 commit 2939ad0) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…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 commit 2939ad0)
…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 commit 2939ad0) (cherry picked from commit cfb79ca) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
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 commit 2939ad0) (cherry picked from commit cfb79ca)
About the
First, "from enum.EnumType" is redundant, because there is "from enum.EnumType" in the section title. Usually "from" notes are not repeated for every method. Second, the section title is not completely correct. They are not normal methods. The first argument of normal arguments is BTW, for the "from" example look at the enum.StrEnum help. Now it contains:
Note that |
* 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.
While working on #97958 I've noticed that there's something strange with
help()
andclassmethod
s.Take a look at this example:
It prints:
Take a look at these two entries:
__init_subclass__(*args, **kwargs) from builtins.type
custom() from builtins.type
While
type
has__init_subclass__
, there's notype.custom
. But,help
says that there is!I think that it is incorrect and can lead to confusion.
Instead it should be:
Linked PRs
help()
does not show extra notes forclassmethod
s #98120The text was updated successfully, but these errors were encountered: