[Python-Dev] [Python-ideas] Proposed addtion to urllib.parse in 3.1 (and urlparse in 2.7) (original) (raw)

Steven Bethard steven.bethard at gmail.com
Tue Apr 14 03:19:27 CEST 2009


On Mon, Apr 13, 2009 at 1:14 PM, Mart Sõmermaa <mrts.pydev at gmail.com> wrote:

On Mon, Apr 13, 2009 at 8:23 PM, Steven Bethard <steven.bethard at gmail.com> wrote:

On Mon, Apr 13, 2009 at 2:29 AM, Mart Sõmermaa <mrts.pydev at gmail.com> wrote: > As for the duplicate handling, I've implemented a threefold strategy that > should address all use cases raised before: > >  def addqueryparams(*args, **kwargs): >     """ >     addqueryparms(url, [allowdups, [argsdict, [separator]]], **kwargs) > >     Appends query parameters to an URL and returns the result. > >     :param url: the URL to update, a string. >     :param allowdups: if >         * True: plainly append new parameters, allowing all duplicates >           (default), >         * False: disallow duplicates in values and regroup keys so that >           different values for the same key are adjacent, >         * None: disallow duplicates in keys -- each key can have a single >           value and later values override the value (like dict.update()).

Unnamed flag parameters are unfriendly to the reader. If I see something like:  addqueryparams(url, True, dict(a=b, c=d)) I can pretty much guess what the first and third arguments are, but I have no clue for the second. Even if I have read the documentation before, I may not remember whether the middle argument is "allowdups" or "keepdups". Keyword arguments are already used for specifying the arguments to the query, so naming can't be used. Someone may need an 'allowdups' key in their query and forget to pass it in paramsdict. A default behaviour should be found that works according to most user's expectations so that they don't need to use the positional arguments generally.

I believe the usual Python approach here is to have two variants of the function, add_query_params and add_query_params_no_dups (or whatever you want to name them). That way the flag parameter is "named" right in the function name.

Steve

I'm not in-sane. Indeed, I am so far out of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy



More information about the Python-Dev mailing list