This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: class syntax not fully documented in reference manual
Type: Stage:
Components: Documentation Versions: Python 3.1, Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: belopolsky, docs@python, georg.brandl, mark.dickinson
Priority: normal Keywords: patch

Created on 2010-06-29 16:52 by mark.dickinson, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue9117.patch mark.dickinson, 2010-06-29 18:03
issue9117_v2.patch mark.dickinson, 2010-06-29 19:46
Messages (9)
msg108917 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-29 16:52
Looking at:

http://docs.python.org/dev/py3k/reference/compound_stmts.html#class-definitions

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.
msg108918 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-29 17:02
Am working on a patch.
msg108920 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-06-29 17:19
> I believe that *args and **kwargs are now also syntactically
> accepted in a class definition.

Indeed:

>>> class a: pass
>>> class b: pass
>>> bases = (a, b)
>>> class c(*bases): pass
>>> kwds = {'metaclass':type}
>>> class c(*bases, **kwds): pass

works!
msg108924 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-29 18:03
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.
msg108932 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-06-29 18:47
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.
msg108936 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-29 19:11
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.
msg108938 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-29 19:44
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.
msg108939 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-29 19:46
And the same patch, but this time *without* the irrelevant audioop changes. :)
msg118927 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-10-17 10:38
This patch was mostly out-of-date since PEP 3115 metaclasses are now documented; I've merged what was missing in r85626.
History
Date User Action Args
2022-04-11 14:57:03adminsetgithub: 53363
2010-10-17 10:38:25georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg118927

resolution: fixed
2010-06-29 19:46:38mark.dickinsonsetfiles: - issue9117_v2.patch
2010-06-29 19:46:30mark.dickinsonsetfiles: + issue9117_v2.patch

messages: + msg108939
2010-06-29 19:44:54mark.dickinsonsetfiles: + issue9117_v2.patch

messages: + msg108938
2010-06-29 19:11:16mark.dickinsonsetmessages: + msg108936
2010-06-29 18:47:09belopolskysetmessages: + msg108932
2010-06-29 18:03:51mark.dickinsonsetfiles: + issue9117.patch
keywords: + patch
messages: + msg108924
2010-06-29 17:19:42belopolskysetnosy: + belopolsky
messages: + msg108920
2010-06-29 17:02:03mark.dickinsonsetmessages: + msg108918
2010-06-29 16:52:39mark.dickinsoncreate