classification
Title: Error in documentation for "compile" built-in function
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Raúl Núñez de Arenas, SilentGhost, berker.peksag, docs@python, python-dev
Priority: normal Keywords: patch

Created on 2016-02-21 15:35 by Raúl Núñez de Arenas, last changed 2016-02-21 20:17 by Raúl Núñez de Arenas. This issue is now closed.

Files
File name Uploaded Description Edit
issue26401.diff SilentGhost, 2016-02-21 15:47 review
issue26401_2.diff SilentGhost, 2016-02-21 18:31 review
Messages (10)
msg260613 - (view) Author: Raúl Núñez de Arenas (Raúl Núñez de Arenas) Date: 2016-02-21 15:35
According to the documentation, if the 'compile' built-in function encounters NUL bytes in the compiled source, it raises TypeError, but this is not true:

>>> source = '\u0000'
>>> compile(source, '', 'single')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: source code string cannot contain null bytes

It raises ValueError, not TypeError. And IMHO, it's the proper exception to raise...
msg260615 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2016-02-21 15:47
Here is the patch.
msg260625 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-02-21 17:58
It would be good to add a versionchanged note. Something like:

   .. versionchanged:: 3.5
      Previously, a :exc:`TypeError` was raised [...]
msg260626 - (view) Author: Raúl Núñez de Arenas (Raúl Núñez de Arenas) Date: 2016-02-21 18:00
I checked the sources at github and the change was introduced back in 2010, if I recall correctly, so maybe this change happened in 3.2? I can check again and try to determine the exact date and if at all possible the version.
msg260627 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2016-02-21 18:11
TypeError is raised in 3.4
msg260628 - (view) Author: Raúl Núñez de Arenas (Raúl Núñez de Arenas) Date: 2016-02-21 18:18
I checked the Mercurial repository directly, and the change was introduced in 2014: http://bugs.python.org/issue22215

So, yes, looks like a 3.5 change and the versionchanged note suggested by Berker is a great idea!
msg260630 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2016-02-21 18:31
Updated patch.
msg260634 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-02-21 20:00
New changeset 0cfac9efd895 by Berker Peksag in branch '3.5':
Issue #26401: Fix compile() documentation
https://hg.python.org/cpython/rev/0cfac9efd895

New changeset 45cf82f424ce by Berker Peksag in branch 'default':
Issue #26401: Fix compile() documentation
https://hg.python.org/cpython/rev/45cf82f424ce
msg260635 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-02-21 20:01
Thanks!
msg260637 - (view) Author: Raúl Núñez de Arenas (Raúl Núñez de Arenas) Date: 2016-02-21 20:17
Thanks to you, Berker, and SilentGhost, for applying and preparing the patch!
History
Date User Action Args
2016-02-21 20:17:03Raúl Núñez de Arenassetmessages: + msg260637
2016-02-21 20:01:40berker.peksagsetstatus: open -> closed
resolution: fixed
messages: + msg260635

stage: patch review -> resolved
2016-02-21 20:00:24python-devsetnosy: + python-dev
messages: + msg260634
2016-02-21 18:31:53SilentGhostsetfiles: + issue26401_2.diff

messages: + msg260630
2016-02-21 18:18:22Raúl Núñez de Arenassetmessages: + msg260628
2016-02-21 18:11:08SilentGhostsetmessages: + msg260627
2016-02-21 18:00:22Raúl Núñez de Arenassetmessages: + msg260626
2016-02-21 17:58:18berker.peksagsetnosy: + berker.peksag

messages: + msg260625
stage: patch review
2016-02-21 15:47:32SilentGhostsetfiles: + issue26401.diff
versions: + Python 3.6
nosy: + SilentGhost

messages: + msg260615

keywords: + patch
2016-02-21 15:35:43Raúl Núñez de Arenascreate