This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: TypeError when '\x00' in docstring
Type: behavior Stage: patch review
Components: Versions: Python 3.1
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: alexandre.vassalotti Nosy List: alexandre.vassalotti, georg.brandl, noel.cuillandre, terry.reedy
Priority: normal Keywords: patch

Created on 2009-02-26 09:42 by noel.cuillandre, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
remove_null_restriction_on_classdoc.diff alexandre.vassalotti, 2009-02-28 19:33
Messages (9)
msg82747 - (view) Author: Noel Cuillandre (noel.cuillandre) Date: 2009-02-26 09:42
The following code raises 'TypeError: __doc__ contains null-bytes'::

Python 3.1a0 (py3k, Jan 27 2009, 18:02:26) 
[GCC 4.1.1 (Gentoo 4.1.1-r1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Foo:
...  """'\x00'"""
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __doc__ contains null-bytes
msg82748 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-02-26 09:55
Why do you think this is a bug?
msg82749 - (view) Author: Noel Cuillandre (noel.cuillandre) Date: 2009-02-26 10:01
Because the same code in Python 2.5.2 does not produce a TypeError::

Python 2.5.2 (r252:60911, Oct 21 2008, 15:11:46)
[GCC 4.1.1 (Gentoo 4.1.1-r1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Foo:
...  """'\x00'"""
...
>>>
msg82750 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-02-26 10:06
Well, that per se is not an indication that it is not a valid change in
3.0. However, I can see no good reason to disallow null-bytes in class
docstrings (especially since they're still allowed in function docstrings).

Assigning to Alexandre who made this change.
msg82867 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2009-02-27 20:29
The bug is the discrepancy between doc

"[3] A string literal appearing as the first statement in the function
body is transformed into the function’s __doc__ attribute and therefore
the function’s docstring. 
[4] A string literal appearing as the first statement in the class body
is transformed into the namespace’s __doc__ item and therefore the
class’s docstring. "

and behavior. In this case, I would agree that the behavior is wrong
unless somehow justified.

I verified in 3.0.1, winxp: '\x00' ok in function, not in class.
msg82940 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2009-02-28 19:08
The motivation behind the restriction was to prevent the tp_doc member
to get truncated. Since tp_doc is a C string, it cannot contains embeded
null bytes.

However, it seems tp_doc is not used at all for heap types. So, I don't
mind lifting the restriction.
msg82942 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2009-02-28 19:31
Here is a patch that removes the restriction.
msg82946 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-02-28 21:16
Looks good. (Alternately, you could also set tp_doc to NULL in the
embedded \0 case.)
msg88860 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2009-06-04 00:43
Patch committed in r73195.
History
Date User Action Args
2022-04-11 14:56:46adminsetgithub: 49623
2009-06-04 00:43:35alexandre.vassalottisetstatus: open -> closed
resolution: accepted
messages: + msg88860
2009-02-28 21:16:55georg.brandlsetmessages: + msg82946
2009-02-28 19:33:42alexandre.vassalottisetfiles: - remove_null_restriction_on_classdoc.diff
2009-02-28 19:33:28alexandre.vassalottisetfiles: + remove_null_restriction_on_classdoc.diff
2009-02-28 19:31:44alexandre.vassalottisetfiles: + remove_null_restriction_on_classdoc.diff
messages: + msg82942
priority: normal
keywords: + patch
type: compile error -> behavior
stage: patch review
2009-02-28 19:08:44alexandre.vassalottisetmessages: + msg82940
2009-02-27 20:29:34terry.reedysetnosy: + terry.reedy
messages: + msg82867
2009-02-26 10:06:21georg.brandlsetassignee: alexandre.vassalotti
messages: + msg82750
nosy: + alexandre.vassalotti
2009-02-26 10:03:22noel.cuillandresetfiles: - unnamed
2009-02-26 10:01:30noel.cuillandresetfiles: + unnamed
messages: + msg82749
2009-02-26 09:55:00georg.brandlsetnosy: + georg.brandl
messages: + msg82748
2009-02-26 09:42:24noel.cuillandrecreate