[issue12634] Random Remarks in class documentation
New submission from Ashutosh Swain <ats.engg@gmail.com>: URL: http://docs.python.org/tutorial/classes.html section: 9.4 Random Remarks The first sentense is bit confusing: "Data attributes override method attributes with the same name" Is it possible to change the sentense something like this: "Data attributes set through instance override method attributes with the same name" ---------- assignee: docs@python components: Documentation messages: 141073 nosy: ats.engg, docs@python priority: normal severity: normal status: open title: Random Remarks in class documentation type: feature request versions: Python 2.7 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue12634> _______________________________________
Raymond Hettinger <raymond.hettinger@gmail.com> added the comment: The proposed rewrite doesn't make any sense to me. Also "set through" is an reads awkwardly. ---------- assignee: docs@python -> rhettinger nosy: +rhettinger _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue12634> _______________________________________
Ezio Melotti <ezio.melotti@gmail.com> added the comment: Indeed that paragraph is not really clear. I had to read it till the end ("verbs for methods and nouns for data attributes") to figure out what it was talking about. Even then it's still not clear what it's trying to say. I *think* it means that if you have a class Foo with a method bar, and you do Foo.bar = 'data', the method will be overridden (so you won't be able to do Foo.bar for the 'data' and Foo.bar() for the method), but the opposite is also true. Moreover I find both the suggestions for avoiding conflicts (capitalizing method names and/or using an underscore) wrong (both against PEP8). Also it never happened to me to have an attribute with the same name of a method, and I think in general it's not a common case (becase, as the paragraph says, methods are verbs and attributes nouns). The whole thing could be rewritten to just say that an attribute name always refers to a single object, either to a method or to some "data". ---------- nosy: +eric.araujo, ezio.melotti, terry.reedy versions: +Python 3.2, Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue12634> _______________________________________
Éric Araujo <merwok@netwok.org> added the comment: I have the same reading as Ezio, and the same opinion that it’s unclear and unhelpful. +1 to saying that there is only one namespace for data attributes and methods. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue12634> _______________________________________
Terry J. Reedy <tjreedy@udel.edu> added the comment: That sentence is wrong to imply that there is anything special about data versus method attributes with respect to overriding -- or that attributes are special when it comes to names in a single namespace. What I think the paragraph should say, if not just deleted, is something like. "Instance attributes hide class attributes. Instance data names are often intended to override class data names. But instance data names masking methods names is likely a mistake. This can be avoided by using verbs for method names and nouns for data names." ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue12634> _______________________________________
Éric Araujo added the comment: +1 to something like Terry’s proposal. ---------- keywords: +easy stage: -> needs patch type: enhancement -> versions: +Python 3.4 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue12634> _______________________________________
Ezio Melotti added the comment: See also #16048. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue12634> _______________________________________
Changes by Chris Rebert <pybugs@rebertia.com>: ---------- nosy: +cvrebert _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue12634> _______________________________________
Changes by Yongzhi Pan <fossilet@users.sourceforge.net>: ---------- nosy: +fossilet _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue12634> _______________________________________
Yongzhi Pan added the comment: It may be worth to noting that when creating property attribute using the property decorator, we may tend to name the method using nouns, like here: http://docs.python.org/2/library/functions.html#property This is when I once overided data attribute with method. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue12634> _______________________________________
Yogesh Chaudhari added the comment: Based on Teery's comments, this patch makes the changes to the random remarks section of the class documentation ---------- keywords: +patch nosy: +Yogesh.Chaudhari Added file: http://bugs.python.org/file30134/issue12634.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue12634> _______________________________________
Yogesh Chaudhari added the comment: Similar changes for 2.7 branch ---------- hgrepos: +188 Added file: http://bugs.python.org/file30135/issue12634-27.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue12634> _______________________________________
Changes by Yogesh Chaudhari <mr.yogesh@gmail.com>: ---------- hgrepos: -188 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue12634> _______________________________________
Change by Raymond Hettinger <raymond.hettinger@gmail.com>: ---------- pull_requests: +15111 stage: needs patch -> patch review pull_request: https://github.com/python/cpython/pull/15406 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue12634> _______________________________________
Change by Raymond Hettinger <raymond.hettinger@gmail.com>: ---------- versions: +Python 3.8, Python 3.9 -Python 2.7, Python 3.2, Python 3.3, Python 3.4 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue12634> _______________________________________
Change by miss-islington <mariatta.wijaya+miss-islington@gmail.com>: ---------- pull_requests: +15114 pull_request: https://github.com/python/cpython/pull/15409 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue12634> _______________________________________
Raymond Hettinger <raymond.hettinger@gmail.com> added the comment: New changeset 483ae0cf1dcf46f8b71c4bf32419dd138e908553 by Raymond Hettinger in branch 'master': bpo-12634: Clarify an awkward section of the tutorial (GH-15406) https://github.com/python/cpython/commit/483ae0cf1dcf46f8b71c4bf32419dd138e9... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue12634> _______________________________________
Raymond Hettinger <raymond.hettinger@gmail.com> added the comment: New changeset f6a7f5bc50f4267cfb7fe0c4ea16d5359c009cbd by Raymond Hettinger (Miss Islington (bot)) in branch '3.8': bpo-12634: Clarify an awkward section of the tutorial (GH-15406) (GH-15409) https://github.com/python/cpython/commit/f6a7f5bc50f4267cfb7fe0c4ea16d5359c0... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue12634> _______________________________________
Change by Raymond Hettinger <raymond.hettinger@gmail.com>: ---------- resolution: -> fixed stage: patch review -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue12634> _______________________________________
participants (9)
-
Ashutosh Swain
-
Chris Rebert
-
Ezio Melotti
-
miss-islington
-
Raymond Hettinger
-
Terry J. Reedy
-
Yogesh Chaudhari
-
Yongzhi Pan
-
Éric Araujo