[issue8143] urlparse has a duplicate of urllib.unquote

Matt Giuca report at bugs.python.org
Mon Mar 15 02:06:49 CET 2010


New submission from Matt Giuca <matt.giuca at gmail.com>:

urlparse contains a complete copy of the urllib.unquote function. This is extremely nasty code duplication -- I have two patches pending on urllib.unquote (#8135 and #8136) and I only just realised that I missed urlparse.unquote!

The reason given for this is:
"Cannot use directly from urllib as it would create circular reference.
urllib uses urlparse methods ( urljoin)"

I don't see that as a reason for code duplication. The fix is to make a local import of unquote in parse_qsl, like this:

def parse_qsl(qs, keep_blank_values=0, strict_parsing=0):
    from urllib import unquote

I am aware that this possibly violates PEP 8 (all imports should be at the top of the module), but I'd say this is the lesser of two evils.

A patch is attached. Commit log: "urlparse: Removed duplicate of urllib.unquote. Replaced with a local import."

----------
components: Library (Lib)
files: urlparse-unquote.patch
keywords: patch
messages: 101075
nosy: mgiuca
severity: normal
status: open
title: urlparse has a duplicate of urllib.unquote
versions: Python 2.6, Python 2.7
Added file: http://bugs.python.org/file16550/urlparse-unquote.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8143>
_______________________________________


More information about the Python-bugs-list mailing list