[issue23040] Better documentation for the urlencode safe parameter
New submission from Wojtek Ruszczewski:
The documentation for urlencode() [1] isn't very clear on how the safe parameter is used, it would better not list it together with encoding and error as only applying to strings.
[1] https://docs.python.org/3.5/library/urllib.parse.html#urllib.parse.urlencode
----------
assignee: docs@python
components: Documentation
files: urlencode-safe.diff
keywords: patch
messages: 232556
nosy: docs@python, wrwrwr
priority: normal
severity: normal
status: open
title: Better documentation for the urlencode safe parameter
type: enhancement
versions: Python 3.5
Added file: http://bugs.python.org/file37426/urlencode-safe.diff
_______________________________________
Python tracker
R. David Murray added the comment:
The current documentation looks very clear to me, and I don't understand your changed version. Can you give an example of how the existing text is inaccurate or results in confusion?
----------
nosy: +r.david.murray
_______________________________________
Python tracker
Wojtek Ruszczewski added the comment: I was looking at the sentence: "When query parameter is a str, the safe, encoding and error parameters are passed down to quote_plus() for encoding." The query argument can't be a string itself (gives a TypeError with 3.5a0 and I think it's only intended to accept dicts or sequences of 2-tuples). The "parameter" then must refer to a component of the query -- a key or a value. The safe argument is passed down and is effective no matter if a component is of str or bytes type (or a sequence with doseq), for example:
urlencode({b'/ n': ''}, safe='/') '/+n=' (note the "b"; without "safe" the slash would get encoded as %2F).
Maybe it would also be good to change "query parameter" to "query component" in that sentence.
----------
_______________________________________
Python tracker
R. David Murray added the comment:
OK, now I understand. How about this phrasing:
"The *safe*, *encoding*, and *error* parameters are passed down to :func:`quote_plus` (the *encoding* and *error* parameters are only passed when the query element is a :class:`str`).
----------
_______________________________________
Python tracker
Wojtek Ruszczewski added the comment:
Thanks, that's right and better, as it doesn't replicate the safe explanation.
I've just noticed another small one, the docstring for quote() [2] says:
"encoding must not be specified if string is a str" -- that should be "... is a bytes".
[2] https://hg.python.org/cpython/file/default/Lib/urllib/parse.py#l690
----------
_______________________________________
Python tracker
Wojtek Ruszczewski added the comment:
Updated the patch, additionally changing "be" to "contain" in the first sentence.
----------
Added file: http://bugs.python.org/file37439/urlencode-safe-v2.diff
_______________________________________
Python tracker
Roundup Robot added the comment:
New changeset 126aff7c6a33 by R David Murray in branch '3.4':
#23040: Clarify treatment of encoding and errors when component is bytes.
https://hg.python.org/cpython/rev/126aff7c6a33
New changeset 367ba031a743 by R David Murray in branch 'default':
Merge: #23040: Clarify treatment of encoding and errors when component is bytes.
https://hg.python.org/cpython/rev/367ba031a743
----------
nosy: +python-dev
_______________________________________
Python tracker
R. David Murray added the comment:
Thanks, Wojtek.
----------
resolution: -> fixed
stage: -> resolved
status: open -> closed
versions: +Python 3.4
_______________________________________
Python tracker
participants (3)
-
R. David Murray
-
Roundup Robot
-
Wojtek Ruszczewski