[New-bugs-announce] [issue31822] Document that urllib.parse.{Defrag, Split, Parse}Result are namedtuples

Allen Li report at bugs.python.org
Thu Oct 19 14:54:33 EDT 2017

New submission from Allen Li <vianchielfaura at gmail.com>:

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)

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

 u = urllib.parse.SplitResult(  # Very ugly

assignee: docs at python
components: Documentation
messages: 304637
nosy: Allen Li, docs at python
priority: normal
severity: normal
status: open
title: Document that urllib.parse.{Defrag,Split,Parse}Result are namedtuples
type: enhancement
versions: Python 2.7, Python 3.6

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list