[issue9117] class syntax not fully documented in reference manual

New submission from Mark Dickinson <dickinsm@gmail.com>: Looking at: http://docs.python.org/dev/py3k/reference/compound_stmts.html#class-definiti... I see: classdef ::= [decorators] "class" classname [inheritance] ":" suite inheritance ::= "(" [expression_list] ")" classname ::= identifier this seems to be missing the keyword arguments that are now possible in a classdef (e.g. for specifying a metaclass). I believe that *args and **kwargs are now also syntactically accepted in a class definition. ---------- assignee: docs@python components: Documentation messages: 108917 nosy: docs@python, mark.dickinson priority: normal severity: normal status: open title: class syntax not fully documented in reference manual versions: Python 3.1, Python 3.2 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9117> _______________________________________

Mark Dickinson <dickinsm@gmail.com> added the comment: Am working on a patch. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9117> _______________________________________

Alexander Belopolsky <belopolsky@users.sourceforge.net> added the comment:
I believe that *args and **kwargs are now also syntactically accepted in a class definition.
Indeed:
works! ---------- nosy: +belopolsky _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9117> _______________________________________

Mark Dickinson <dickinsm@gmail.com> added the comment: It looks like fixing the production list is the easy part (see attached patch): as far as I can tell, the *syntax* for class definitions is pretty much identical to that for function calls. (The semantics are different, of course.) It would be good if someone could check this patch for sanity, though. The description in that section still needs updating. ---------- keywords: +patch Added file: http://bugs.python.org/file17802/issue9117.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9117> _______________________________________

Alexander Belopolsky <belopolsky@users.sourceforge.net> added the comment: The production looks right to me, but I think it should be broken in two or more lines. Since it is rendered pre-formatted, long line results in a horizontal scroll bar unless the browser window is extremely wide. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9117> _______________________________________

Mark Dickinson <dickinsm@gmail.com> added the comment: Yes, good plan. I'll do that. I'm also not sure about the 'comprehension' bit; it's true that a comprehension is syntactically valid here (e.g., "class A(x for x in range(3))"), but it's also entirely useless: it has to be the sole argument, so there can't be a metaclass argument, so the metaclass would have to be type. But type (quite sensibly) won't accept a generator as a base class. Oh well; I suppose it doesn't *have* to make sense to be valid syntax... This still leaves the hard part, which is distilling the essence of PEP 3115 and adding it to the reference manual. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9117> _______________________________________

Mark Dickinson <dickinsm@gmail.com> added the comment: Updated patch. I've reorganized that documentation section a bit, and added a link to PEP 3115. This isn't ideal, but it's better than nothing. ---------- Added file: http://bugs.python.org/file17805/issue9117_v2.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9117> _______________________________________

Mark Dickinson <dickinsm@gmail.com> added the comment: And the same patch, but this time *without* the irrelevant audioop changes. :) ---------- Added file: http://bugs.python.org/file17806/issue9117_v2.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9117> _______________________________________

Changes by Mark Dickinson <dickinsm@gmail.com>: Removed file: http://bugs.python.org/file17805/issue9117_v2.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9117> _______________________________________

Georg Brandl <georg@python.org> added the comment: This patch was mostly out-of-date since PEP 3115 metaclasses are now documented; I've merged what was missing in r85626. ---------- nosy: +georg.brandl resolution: -> fixed status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9117> _______________________________________

Mark Dickinson <dickinsm@gmail.com> added the comment: Am working on a patch. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9117> _______________________________________

Alexander Belopolsky <belopolsky@users.sourceforge.net> added the comment:
I believe that *args and **kwargs are now also syntactically accepted in a class definition.
Indeed:
works! ---------- nosy: +belopolsky _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9117> _______________________________________

Mark Dickinson <dickinsm@gmail.com> added the comment: It looks like fixing the production list is the easy part (see attached patch): as far as I can tell, the *syntax* for class definitions is pretty much identical to that for function calls. (The semantics are different, of course.) It would be good if someone could check this patch for sanity, though. The description in that section still needs updating. ---------- keywords: +patch Added file: http://bugs.python.org/file17802/issue9117.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9117> _______________________________________

Alexander Belopolsky <belopolsky@users.sourceforge.net> added the comment: The production looks right to me, but I think it should be broken in two or more lines. Since it is rendered pre-formatted, long line results in a horizontal scroll bar unless the browser window is extremely wide. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9117> _______________________________________

Mark Dickinson <dickinsm@gmail.com> added the comment: Yes, good plan. I'll do that. I'm also not sure about the 'comprehension' bit; it's true that a comprehension is syntactically valid here (e.g., "class A(x for x in range(3))"), but it's also entirely useless: it has to be the sole argument, so there can't be a metaclass argument, so the metaclass would have to be type. But type (quite sensibly) won't accept a generator as a base class. Oh well; I suppose it doesn't *have* to make sense to be valid syntax... This still leaves the hard part, which is distilling the essence of PEP 3115 and adding it to the reference manual. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9117> _______________________________________

Mark Dickinson <dickinsm@gmail.com> added the comment: Updated patch. I've reorganized that documentation section a bit, and added a link to PEP 3115. This isn't ideal, but it's better than nothing. ---------- Added file: http://bugs.python.org/file17805/issue9117_v2.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9117> _______________________________________

Mark Dickinson <dickinsm@gmail.com> added the comment: And the same patch, but this time *without* the irrelevant audioop changes. :) ---------- Added file: http://bugs.python.org/file17806/issue9117_v2.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9117> _______________________________________

Changes by Mark Dickinson <dickinsm@gmail.com>: Removed file: http://bugs.python.org/file17805/issue9117_v2.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9117> _______________________________________

Georg Brandl <georg@python.org> added the comment: This patch was mostly out-of-date since PEP 3115 metaclasses are now documented; I've merged what was missing in r85626. ---------- nosy: +georg.brandl resolution: -> fixed status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9117> _______________________________________
participants (3)
-
Alexander Belopolsky
-
Georg Brandl
-
Mark Dickinson