[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)
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)
----------
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>
<https://bugs.python.org/issue31822>
_______________________________________
More information about the New-bugs-announce
mailing list