Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
While working on#97958 I've noticed that there's something strange withhelp() andclassmethods.
Take a look at this example:
importpydocclassMy:@classmethoddef__init_subclass__(cls,*args,**kwargs):pass@classmethoddefcustom(cls):passprint(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.typecustom() from builtins.type
Whiletype has__init_subclass__, there's notype.custom. But,help says that there is!
>>>type.__init_subclass__<built-inmethod__init_subclass__oftypeobjectat0x10a50c360>>>>type.customTraceback (mostrecentcalllast):File"<stdin>",line1,in<module>AttributeError:typeobject'type'hasnoattribute'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()