Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Preserve wsgify default args #203
wsgify objects can be created with args/kwargs at construction time:
def hello(req, name): return "Hello, %s!" % name app = wsgify(hello, args=("Fred",))
Previously, these arguments would only be passed to the underlying
That is, continuing the above example:
req = Request.blank('/') resp = req.get_response(app) # => "Hello, Fred"
app(req) # => raises TypeError
This is perhaps most confusing when it interacts with
@wsgify.middleware def add_magic_header(req, app, value='seated ducks'): resp = req.get_response(app) resp.headers['Magic-Header'] = value return resp app = add_magic_header(app, value='flying elephants') resp1 = req.get_response(app) resp2 = app(req) resp1.headers['Magic-Header'] # => 'flying elephants' resp2.headers['Magic-Header'] # => 'seated ducks'
(An executable example of the above can be found here.)
This pull request ensures that if variadic arguments or keyword arguments are
then the defaults are used.
I wrote up this patch last night, and I've been thinking about it some more.
I'm not sure this is the right thing to do.
Specifically, while the difference between
In addition, the whole story of default arguments seems a bit confusing:
So I'm submitting this for discussion, because it may be that the correct fix is actually some clearer documentation about when default arguments are used and when they are not. (i.e. "If you use the resulting callable as
I'd be interested to hear what others think.