Closed
Description
While working on #97958 I've noticed that there's something strange with help()
and classmethod
s.
Take a look at this example:
import pydoc
class My:
@classmethod
def __init_subclass__(cls, *args, **kwargs):
pass
@classmethod
def custom(cls):
pass
print(pydoc.plain(pydoc.render_doc(My)))
It prints:
Python Library Documentation: class My in module __main__
class My(builtins.object)
| Class methods defined here:
|
| __init_subclass__(*args, **kwargs) from builtins.type
| This method is called when a class is subclassed.
|
| The default implementation does nothing. It may be
| overridden to extend subclasses.
|
| custom() from builtins.type
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
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 no type.custom
. But, help
says that there is!
>>> type.__init_subclass__
<built-in method __init_subclass__ of type object at 0x10a50c360>
>>> type.custom
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: type object 'type' has no attribute 'custom'
I think that it is incorrect and can lead to confusion.
Instead it should be:
| __init_subclass__(*args, **kwargs) from builtins.type
| This method is called when a class is subclassed.
|
| The default implementation does nothing. It may be
| overridden to extend subclasses.
|
| custom()