Repository navigation
Closed
Labels
stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement
Description
| BPO | 22891 |
|---|---|
| Nosy | @gpshead, @orsenthil, @vadmium, @timgraham, @atodorov, @miss-islington |
| PRs | |
| Dependencies | |
| Files |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = None
closed_at = <Date 2021-05-19.01:37:03.557>
created_at = <Date 2014-11-17.10:42:24.782>
labels = ['type-feature', 'library']
title = 'code removal from urllib.parse.urlsplit()'
updated_at = <Date 2021-05-19.01:37:03.554>
user = 'https://github.com/atodorov'bugs.python.org fields:
activity = <Date 2021-05-19.01:37:03.554>
actor = 'gregory.p.smith'
assignee = 'none'
closed = True
closed_date = <Date 2021-05-19.01:37:03.557>
closer = 'gregory.p.smith'
components = ['Library (Lib)']
creation = <Date 2014-11-17.10:42:24.782>
creator = 'Alexander.Todorov'
dependencies = ['27657']
files = ['37212']
hgrepos = []
issue_num = 22891
keywords = ['patch']
message_count = 10.0
messages = ['231278', '231283', '231309', '238254', '271712', '289586', '354890', '354895', '354904', '393915']
nosy_count = 6.0
nosy_names = ['gregory.p.smith', 'orsenthil', 'martin.panter', 'Tim.Graham', 'Alexander.Todorov', 'miss-islington']
pr_nums = ['661', '16837', '16839']
priority = 'normal'
resolution = 'out of date'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue22891'
versions = ['Python 3.5']Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement
Activity
atodorov commentedon Nov 17, 2014
In the urllib.parse (or urlparse on Python 2.X) module there is this function:
There is an issue here (or a few of them) as follows:
if url[:1] is already lowercase (equals "http") (line 173) then .lower() on line 174 is reduntant:
174 scheme = url[:i].lower() # <--- no need for .lower() b/c value is "http"
OTOH line 173 could refactor the condition and match URLs where the scheme is uppercase. For example
173 if url[:i].lower() == 'http': # optimize the common case
The code as is returns the same results (as far as I've tested it) for both:
urlsplit("http://github.com/atodorov/repo.git?param=value#myfragment")
urlsplit("HTTP://github.com/atodorov/repo.git?param=value#myfragment")
urlsplit("HTtP://github.com/atodorov/repo.git?param=value#myfragment")
but the last 2 invocations also go through lines 185-199
My personal vote goes for removal of lines 173-184.
Version-Release number of selected component (if applicable):
This is present in both Python 3 and Python 2 on all versions I have access to:
python3-libs-3.4.1-16.fc21.x86_64.rpm
python-libs-2.7.8-5.fc21.x86_64.rpm
python-libs-2.7.5-16.el7.x86_64.rpm
python-libs-2.6.6-52.el6.x86_64
Versions are from Fedora Rawhide and RHEL. Also the same code is present in the Mercurial repository.
Bug first reported as
https://bugzilla.redhat.com/show_bug.cgi?id=1160603
and now filing here for upstream consideration.
[-][patch]: code removal from urllib.parse.urlsplit()[/-][+]code removal from urllib.parse.urlsplit()[/+]orsenthil commentedon Nov 17, 2014
Thanks for filing this. Does test cases pass after removal of those lines? (I will be surprised) and if the tests fail, then after analyzing it, this could only be considered a new change (thus change to made in latest python) in order not to break compatibility.
atodorov commentedon Nov 18, 2014
Yes they do. Also see my detailed explanation above, there's no reason for test cases to fail.
vadmium commentedon Mar 17, 2015
The patch seems sensible. The only behaviour change I can forsee would be the odd case of http:1234 no longer being parsed like this:
>>> urlsplit("http:1234") SplitResult(scheme='http', netloc='', path='1234', query='', fragment='')Instead it would be parsed the same as HTTP:1234 (or tel:1234!):
>>> urlsplit("HTTP:1234") SplitResult(scheme='', netloc='', path='HTTP:1234', query='', fragment='')If optimizing for “http:” really is important, it might still be done without the code duplication. Other options might be factoring a subroutine, using str.strip(), set.issubset(), or regular expressions.
vadmium commentedon Jul 30, 2016
bpo-27657 has been opened about the quirk with numeric URLs
timgraham commentedon Mar 14, 2017
I sent a pull request for this issue's dependency (bpo-27657) and added a second commit there with this patch. A test added in the first commit demonstrates that removing this code no longer results in the behavior change described in msg238254.
orsenthil commentedon Oct 18, 2019
New changeset 5a88d50 by Senthil Kumaran (Tim Graham) in branch 'master':
bpo-27657: Fix urlparse() with numeric paths (#661)
5a88d50
miss-islington commentedon Oct 18, 2019
New changeset 82b5f6b by Miss Islington (bot) in branch '3.7':
bpo-27657: Fix urlparse() with numeric paths (GH-661)
82b5f6b
orsenthil commentedon Oct 18, 2019
New changeset 0f3187c by Senthil Kumaran in branch '3.8':
[3.8] bpo-27657: Fix urlparse() with numeric paths (GH-661) (bpo-16839)
0f3187c
gpshead commentedon May 19, 2021
There are still a lot of cleanliness and even logical issues lurking within urllib.parse. But this bug is dated and other changes have happened since. I'm closing it as out of date. Open new issues for specific action items.