Skip to content

Commit

Permalink
Merge pull request #72 from zopefoundation/issue69
Browse files Browse the repository at this point in the history
Fix passing ``None`` as the description to a field constructor.
  • Loading branch information
jamadden committed Sep 19, 2018
2 parents b5964f5 + 39d1732 commit 934400d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
numeric and bytes fields, as well as ``URI``, ``DottedName``, and
``Id``.

- Fix passing ``None`` as the description to a field constructor. See
`issue 69 <https://github.com/zopefoundation/zope.schema/issues/69>`_.

4.7.0 (2018-09-11)
==================
Expand Down
4 changes: 3 additions & 1 deletion src/zope/schema/_bootstrapfields.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ def __init__(self, title=u'', description=u'', __name__='',
# Fix leading whitespace that occurs when using multi-line
# strings, but don't overwrite the original, we need to
# preserve it (it could be a MessageID).
doc_description = '\n'.join(_DocStringHelpers.docstring_to_lines(description)[:-1])
doc_description = '\n'.join(
_DocStringHelpers.docstring_to_lines(description or u'')[:-1]
)

if title:
if doc_description:
Expand Down
25 changes: 25 additions & 0 deletions src/zope/schema/tests/test__bootstrapfields.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,31 @@ def test_ctor_description_preserved(self):
""")
)

def test_ctor_description_none(self):
# None values for description don't break the docs.
import textwrap

description = None

title = u'A title'

field = self._makeOne(title=title, description=description)

self.assertIs(field.title, title)
self.assertIs(field.description, description)

self.assertEqual(
field.getDoc(),
textwrap.dedent("""\
A title
:Implementation: :class:`zope.schema.Field`
:Read Only: False
:Required: True
:Default Value: None
""")
)

def test_ctor_defaults(self):

field = self._makeOne()
Expand Down

0 comments on commit 934400d

Please sign in to comment.