On Friday 16 October 2009 13:39:10 Russell Keith-Magee wrote: > Interesting idea. I think the advantages you list are all on the > money. My only question is on the pathological case: > > render_to_response("template_name.html", {'foo','bar'}, > context_instance=Context(), request=request) > > What is the interpretation here? An error? ignore the request? > ignore the context? > > Introducing an API where there is a usage that is legal syntax but > ambiguous argument usage makes me slightly nervous - although, I > will admit the potential for accidental misuse here is small.
I implemented this the other day, and it seemed like the only sensible thing to do was raise a ValueError if they try to supply both, rather than silently overwrite a value in **kwargs. The patch is essentially the following lines inserted into render_to_response: ... request = kwargs.pop('request', None) if request is not None: if 'context_instance' in kwargs: raise ValueError("blah blah blah") else: kwargs['context_instance'] = RequestContext(request) ... > 4) Add a completely new shortcut: > > bikeshed(request, *args, **kwargs) > > which does exactly what render_to_response does, but instantiates a > RequestContext. I've deliberately chosen a nonsense name - at the > moment, deciding if this is the solution we want is more important > than the actual name. I am inclined towards 4) as well. I would just *slightly* quibble that the name is not important - a name that makes sense and is memorable is very important for a shortcut. If I have to look it up, it's not a shortcut any more. That's why I think that modifying render_to_response rather than adding a new shortcut has a slight edge here - because people already know it. Also, it means that I can just use "M-x grep" in emacs to find all instances that can be updated, and I don't have to worry about import lines :-) Not that I don't have a complete test suite on all my projects that would catch any missing imports, of course... ;-) Hmm, for me this boils down to whether I'm feeling lazy or feeling like a perfectionist, option 4) is definitely cleaner... Luke -- The probability of someone watching you is proportional to the stupidity of your action. Luke Plant || http://lukeplant.me.uk/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---