-
-
Notifications
You must be signed in to change notification settings - Fork 29.2k
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
gh-119016: Remove outdated sentences from the "classes" tutorial #119130
Conversation
I am still wondering why the text "not referring to..." is needed here. There are some differences between class instance methods and builtin class instance methods (e.g. |
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
https://docs.python.org/3/tutorial/classes.html#odds-and-ends:
|
Doc/tutorial/classes.rst
Outdated
The other kind of instance attribute reference is a *method*. In the following | ||
discussion, we’ll use the term method exclusively to mean methods of class | ||
instance objects, unless explicitly stated otherwise. (In other words, we are | ||
not referring to built-in methods such as ``alist.append`` where ``alist`` is | ||
a :class:`list` object.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This paragraph is very old. It appears to have remained in this tutorial largely unchanged since it was originally added in 1992, in 5e0759d.
I don't think that the original purpose of this paragraph was to point out that alist.append
has, strictly speaking, a slightly different type to a user-defined method on a user-defined class. That feels like a subtle point that leads to few visible differences in behaviour for users.
In very early versions of Python, many builtin types such as list
were not classes at all -- they were more primitive types that operated according to a different object model. (See https://stackoverflow.com/a/54873/13990016 for more details. This changed in Python 2.2, originally released in 2001.) I think this paragraph was originally intended to clarify that even objects that were not instances of classes, such as lists, could also have methods.
Nowadays, all objects are instances of classes, and it is not possible to create types that do not inherit from object
. It's been this way for a long time now. As such, I think this paragraph is now largely redundant. Rather than making the edit you propose here, I would simply delete most of this paragraph altogether.
The other kind of instance attribute reference is a *method*. In the following | |
discussion, we’ll use the term method exclusively to mean methods of class | |
instance objects, unless explicitly stated otherwise. (In other words, we are | |
not referring to built-in methods such as ``alist.append`` where ``alist`` is | |
a :class:`list` object.) | |
The other kind of instance attribute reference is a *method*. A method is a | |
function that "belongs to" an object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about suggesting this originally, but https://docs.python.org/3/reference/datamodel.html#built-in-methods makes it sound like there's still some difference between built-in methods and methods on user defined classes (besides built-ins being defined in C that is). As mentioned in #119016 (comment), the types are different at least.
Does the last paragraphs in particular of both 9.3.4 (https://docs.python.org/3/tutorial/classes.html#method-objects) and 9.7 (https://docs.python.org/3/tutorial/classes.html#odds-and-ends) apply equally to built-in methods? If not, there might still be some confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, builtin methods are a different type to pure-Python methods, but they're meant to be entirely duck-type compatible. Any glaring differences between them are arguably bugs. Off the top of my head, I don't think any of the paragraphs you link to there are different when it comes to builtin methods.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
This comment was marked as outdated.
This comment was marked as outdated.
pythonGH-119130) (cherry picked from commit c618f7d) Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
GH-119925 is a backport of this pull request to the 3.13 branch. |
pythonGH-119130) (cherry picked from commit c618f7d) Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
GH-119926 is a backport of this pull request to the 3.12 branch. |
python#119130) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
📚 Documentation preview 📚: https://cpython-previews--119130.org.readthedocs.build/