Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #6255
| From | Jess Austin <jess.austin@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | super() in class defs? |
| Date | 2011-05-25 10:54 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <aed43cea-eae7-40d5-a3c9-13b841d3fd7c@c41g2000yqm.googlegroups.com> (permalink) |
I may be attempting something improper here, but maybe I'm just going
about it the wrong way. I'm subclassing
http.server.CGIHTTPRequestHandler, and I'm using a decorator to add
functionality to several overridden methods.
def do_decorate(func):
. def wrapper(self):
. if appropriate():
. return func()
. complain_about_error()
. return wrapper
class myHandler(CGIHTTPRequestHandler):
. @do_decorate
. def do_GET(self):
. return super().do_GET()
. # also override do_HEAD and do_POST
My first thought was that I could just replace that whole method
definition with one line:
class myHandler(CGIHTTPRequestHandler):
. do_GET = do_decorate(super().do_GET)
That generates the following error:
SystemError: super(): __class__ cell not found
So I guess that when super() is called in the context of a class def
rather than that of a method def, it doesn't have the information it
needs. Now I'll probably just say:
do_GET = do_decorate(CGIHTTPRequestHandler.do_GET)
but I wonder if there is a "correct" way to do this instead? Thanks!
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
super() in class defs? Jess Austin <jess.austin@gmail.com> - 2011-05-25 10:54 -0700
Re: super() in class defs? Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-25 12:31 -0600
Re: super() in class defs? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-25 21:40 +0000
Re: super() in class defs? Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-25 17:31 -0600
Re: super() in class defs? Raymond Hettinger <python@rcn.com> - 2011-05-25 16:45 -0700
csiph-web