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 Allen Li
Recipients Allen Li, docs@python
Date 2017-10-19.18:54:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1508439273.05.0.213398074469.issue31822@psf.upfronthosting.co.za>
In-reply-to
Content
It would be useful to document that urllib.parse.{Defrag,Split,Parse}Result are namedtuples, and make that API officially public if it was not otherwise.

These classes are implemented as namedtuples in Python 2 and 3, and I am not aware of a reason that that would need to change in the future.

In particular, the namedtuple _replace() method is very useful for modifying parts of a URL, a common use case.

 u = urllib.parse.urlsplit(some_url)
 u = u._replace(netloc=other_netloc)
 urllib.parse.urlunsplit(u)

 # Alternatives not depending on namedtuple API
 parts = list(u)
 parts[1] = other_netloc  # Using a magic index
 urllib.parse.urlunsplit(u)

 u = urllib.parse.SplitResult(  # Very ugly
     scheme=u.scheme,
     netloc=other_netloc,
     path=u.path,
     query=u.query,
     fragment=u.fragment)
History
Date User Action Args
2017-10-19 18:54:33Allen Lisetrecipients: + Allen Li, docs@python
2017-10-19 18:54:33Allen Lisetmessageid: <1508439273.05.0.213398074469.issue31822@psf.upfronthosting.co.za>
2017-10-19 18:54:32Allen Lilinkissue31822 messages
2017-10-19 18:54:32Allen Licreate