From c84dad28e9b1fa89b4c5bf61d48f39ba62335723 Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Fri, 22 Jan 2016 18:14:04 +0300 Subject: [PATCH] transforms: Don't try to call has_child on parent nodes that are None Otherwise the build can fail with the following error: File "/usr/lib/python2.7/dist-packages/sphinx/environment.py", line 791, in read_doc pub.publish() File "/usr/lib/python2.7/dist-packages/docutils/core.py", line 218, in publish self.apply_transforms() File "/usr/lib/python2.7/dist-packages/docutils/core.py", line 199, in apply_transforms self.document.transformer.apply_transforms() File "/usr/lib/python2.7/dist-packages/docutils/transforms/__init__.py", line 171, in apply_transforms transform.apply(**kwargs) File "/usr/lib/python2.7/dist-packages/sphinx/transforms.py", line 124, in apply if has_child(node.parent, nodes.caption): File "/usr/lib/python2.7/dist-packages/sphinx/transforms.py", line 117, in has_child return any(isinstance(child, cls) for child in node) TypeError: 'NoneType' object is not iterable The error could be reproduced with lp:autopilot/legacy branch from Launchpad. --- sphinx/transforms.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sphinx/transforms.py b/sphinx/transforms.py index 49c0aba1e..4619449e7 100644 --- a/sphinx/transforms.py +++ b/sphinx/transforms.py @@ -121,13 +121,13 @@ class AutoNumbering(Transform): if has_child(node, nodes.caption): self.document.note_implicit_target(node) elif isinstance(node, nodes.image): - if has_child(node.parent, nodes.caption): + if node.parent and has_child(node.parent, nodes.caption): self.document.note_implicit_target(node.parent) elif isinstance(node, nodes.table): if has_child(node, nodes.title): self.document.note_implicit_target(node) elif isinstance(node, nodes.literal_block): - if has_child(node.parent, nodes.caption): + if node.parent and has_child(node.parent, nodes.caption): self.document.note_implicit_target(node.parent)