Skip to content

bpo-20285: Improve help docs for object #4759

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

Merged
merged 7 commits into from
May 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ def spilldata(msg, attrs, predicate):
thisclass = attrs[0][2]
attrs, inherited = _split_list(attrs, lambda t: t[2] is thisclass)

if thisclass is builtins.object:
if object is not builtins.object and thisclass is builtins.object:
Copy link
Member

Choose a reason for hiding this comment

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

What is the purpose of this change?

Copy link
Member

Choose a reason for hiding this comment

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

The have help(object) print the methods defined on object, the same as it does for every other class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One confusing thing about this module is that the argument that the docs are being created for is named is object. So, for this PR, object both can refer to the name of the argument and the class called object.

thisclass is the third value (index 2) in the sequence returned from inspect.classify_class_attrs(object), which is defined as "The class which defined this attribute" (from the docstring). When the value of the class is object, the current if statement if thisclass is builtins.object: results in that attribute being skipped from the output.

The change is to skip the logic when the argument value is not builtins.object so that the attributes will be displayed when help(object) is used. Without this change, all of the attributes are skipped because "The class which defined this attribute" is always object.

attrs = inherited
continue
elif thisclass is object:
Expand Down Expand Up @@ -1327,7 +1327,7 @@ def spilldata(msg, attrs, predicate):
thisclass = attrs[0][2]
attrs, inherited = _split_list(attrs, lambda t: t[2] is thisclass)

if thisclass is builtins.object:
if object is not builtins.object and thisclass is builtins.object:
attrs = inherited
continue
elif thisclass is object:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Expand object.__doc__ (docstring) to make it clearer.
Modify pydoc.py so that help(object) lists object methods
(for other classes, help omits methods of the object base class.)
7 changes: 6 additions & 1 deletion Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -4750,6 +4750,11 @@ static PyMethodDef object_methods[] = {
{0}
};

PyDoc_STRVAR(object_doc,
"object()\n--\n\n"
"The base class of the class hierarchy.\n\n"
"When called, it accepts no arguments and returns a new featureless\n"
"instance that has no instance attributes and cannot be given any.\n");

PyTypeObject PyBaseObject_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
Expand All @@ -4772,7 +4777,7 @@ PyTypeObject PyBaseObject_Type = {
PyObject_GenericSetAttr, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
PyDoc_STR("object()\n--\n\nThe most base type"), /* tp_doc */
object_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
object_richcompare, /* tp_richcompare */
Expand Down