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.

Author mastahyeti
Recipients mastahyeti
Date 2012-08-30.18:17:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1346350665.33.0.731435453404.issue15824@psf.upfronthosting.co.za>
In-reply-to
Content
This patch removes the inheritance from namedtuple and attempts to add the necessary methods to make it backwards compatible.

When parsing a url with urlparse.urlparse, the return type is non-mutable (named tuple). This is really inconvenient, because one of the most common (imop) use cases for urlparse is to parse a url, make an adjustment or change and then unparse it. Currently, something like this is required:

    import urlparse

    url = list(urlparse.urlparse('http://www.example.com/foo/bar?hehe=haha'))
    url[1] = 'python.com'
    new_url = urllib.urlunparse(url)

I think this is really clunky. Moving to a mutable return type is challenging because (to my knowledge) there are no types that are mutable and compatible with tuple. This patch removes the inheritance from namedtuple and attempts to add the necessary methods to make it backwards compatible. Does any one know of a better way to do this? It would be nice if there were a namedlist type that acted like namedtuple but was mutable. 

With these updates, urlparse can be used as follows:

    import urlparse

    url = list(urlparse.urlparse('http://www.example.com/foo/bar?hehe=haha'))
    url.netloc = 'www.python.com'
    urlparse.urlunparse(url)

I think this is much better. Let me know if you disagree...

Also, I ran the script through autopep8 because it was messy.

Also, I'm not sure if I'm supposed to duplicate this patch over to Python3. I can do that if necessary
History
Date User Action Args
2012-08-30 18:17:45mastahyetisetrecipients: + mastahyeti
2012-08-30 18:17:45mastahyetisetmessageid: <1346350665.33.0.731435453404.issue15824@psf.upfronthosting.co.za>
2012-08-30 18:17:44mastahyetilinkissue15824 messages
2012-08-30 18:17:43mastahyeticreate