You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
>>> from urllib.parse import urlsplit
>>> help(urlsplit)
Help on function urlsplit in module urllib.parse:
urlsplit(url, scheme='', allow_fragments=True)
Parse a URL into 5 components:
<scheme>://<netloc>/<path>?<query>#<fragment>
Return a 5-tuple: (scheme, netloc, path, query, fragment).
Note that we don't break the components up in smaller bits
(e.g. netloc is a single string) and we don't expand % escapes.
The current docstring does not describe the scheme or allow_fragments arguments. Also, the note about not splitting netloc is misleading; the components of netloc (username, password, hostname, and port) are available as extra attributes of the returned SplitResult.
urlparse has similar issues; other functions could stand to be checked.
Also, the note about not splitting netloc is misleading; the components > of netloc (username, password, hostname, and port) are available as >extra attributes of the returned SplitResult.
Also, the docs in urllib.parse.rst should also be updated to correct this misleading statement.
tmblweed commented on Sep 4, 2019
tmblweedmannequin
Mannequin
More actions
hello!
I can see that we might want to add documentation for splitting netloc, but I don't understand why we'd have scheme and netloc, but nothing for path and query. What are you suggesting we add for scheme/allow_fragements?
We don't have details regarding anything, i.e scheme, netloc, path or query or fragments. So I was curious about why we would have more documentation around netloc and scheme and nothing about path and query
Should we be adding information for all(scheme, netloc, path, query, fragment) of them, including extra attributes of the returned SplitResult?
I see. I don't think we need to describe each returned component in the docstring; they're some combination of self-explanatory, described in the reference docs, or just industry-standard terms that are easily defined from other sources. I'm not suggesting to add anything to the docstring about the scheme return component, but rather the scheme argument (which is the default value for the scheme return component when it's not found in the url). The subcomponents of netloc should be mentioned because the docstring currently gives the impression that the user has to parse them out for themselves, which is not true.
Off the top of my head, I'd suggest changing the urlsplit docstring to something like:
Parse *url* and return a SplitResult.
SplitResult is a named 5-tuple of the following components:
<scheme>://<netloc>/<path>?<query>#<fragment>
The ``username``, ``password``, ``hostname``, and ``port``
sub-components of ``netloc`` can also be accessed as
attributes of the SplitResult object.
The *scheme* argument provides the default value of the
``scheme`` component when no scheme is found in *url*.
If *allow_fragments* is False, no attempt is made to
separate the ``fragment`` component from the previous
component, which can be either ``path`` or ``query``.
Note that % escapes are not expanded.
tmblweed commented on Sep 8, 2019
tmblweedmannequin
Mannequin
More actions
got it - thanks for the detailed explanation! I'll go ahead and create a PR soon
Hi, since the original PR #18631 has been marked as stale and the author gave permission to take it over, I would like to pick this up and apply the final requested changes!
Activity
zware commentedon Aug 28, 2019
For example, urlsplit:
The current docstring does not describe the
schemeorallow_fragmentsarguments. Also, the note about not splitting netloc is misleading; the components of netloc (username, password, hostname, and port) are available as extra attributes of the returned SplitResult.urlparse has similar issues; other functions could stand to be checked.
nanjekyejoannah commentedon Aug 29, 2019
Also, the docs in urllib.parse.rst should also be updated to correct this misleading statement.
tmblweed commentedon Sep 4, 2019
hello!
I can see that we might want to add documentation for splitting netloc, but I don't understand why we'd have scheme and netloc, but nothing for path and query. What are you suggesting we add for scheme/allow_fragements?
Thanks!
zware commentedon Sep 4, 2019
I'm not sure what you mean here; can you please clarify?
Just a brief description of what effect the arguments actually have on the returned result.
tmblweed commentedon Sep 4, 2019
I guess what I'm wondering is this:
We don't have details regarding anything, i.e scheme, netloc, path or query or fragments. So I was curious about why we would have more documentation around netloc and scheme and nothing about path and query
Should we be adding information for all(scheme, netloc, path, query, fragment) of them, including extra attributes of the returned SplitResult?
p.s - newbie trying to contribute here
zware commentedon Sep 4, 2019
I see. I don't think we need to describe each returned component in the docstring; they're some combination of self-explanatory, described in the reference docs, or just industry-standard terms that are easily defined from other sources. I'm not suggesting to add anything to the docstring about the
schemereturn component, but rather the scheme argument (which is the default value for theschemereturn component when it's not found in the url). The subcomponents of netloc should be mentioned because the docstring currently gives the impression that the user has to parse them out for themselves, which is not true.Off the top of my head, I'd suggest changing the
urlsplitdocstring to something like:tmblweed commentedon Sep 8, 2019
got it - thanks for the detailed explanation! I'll go ahead and create a PR soon
idomic commentedon Sep 28, 2019
Committed a PR: #60662
I've read all of the thread and changed the docstring to the latest suggestion by @zach.ware
Ido
11 remaining items
pranavchoudhary-tech commentedon Jul 3, 2026
Hi, since the original PR #18631 has been marked as stale and the author gave permission to take it over, I would like to pick this up and apply the final requested changes!
orsenthil commentedon Jul 3, 2026
pythongh-82151: Update and improve urlsplit docstring
gh-82151: Update and improve urlsplit docstring (#152985)
[3.14] gh-82151: Update and improve urlsplit docstring (#152985) (#15…
[3.15] gh-82151: Update and improve urlsplit docstring (GH-152985) (#…
[3.13] gh-82151: Update and improve urlsplit docstring (#152985) (#15…