Skip to content

Commit

Permalink
typing: emit empty-string instead of null for document title anchor v…
Browse files Browse the repository at this point in the history
…alues
  • Loading branch information
jayaddison committed Mar 4, 2024
1 parent 5e05a27 commit d44dc11
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion sphinx/search/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ def _visit_nodes(node):
elif isinstance(node, nodes.Text):
word_store.words.extend(split(node.astext()))
elif isinstance(node, nodes.title):
title, titleid = node.astext(), None
title, titleid = node.astext(), ''
# docutils: top-level section title can be considered the document title
if not isinstance(node.parent.parent, nodes.document):
if node.parent['ids']:
Expand Down
2 changes: 1 addition & 1 deletion sphinx/themes/basic/static/searchtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ const Search = {
results.push([
docNames[file],
titles[file] !== title ? `${titles[file]} > ${title}` : title,
id !== null ? "#" + id : "",
id ? "#" + id : "",
null,
score,
filenames[file],
Expand Down
7 changes: 3 additions & 4 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def test_IndexBuilder():
'test': [0, 1, 2, 3]},
'titles': ('title1_1', 'title1_2', 'title2_1', 'title2_2'),
'titleterms': {'section_titl': [0, 1, 2, 3]},
'alltitles': {'section_title': [(0, None), (1, None), (2, None), (3, None)]},
'alltitles': {'section_title': [(0, ''), (1, ''), (2, ''), (3, '')]},
'indexentries': {},
}
assert index._objtypes == {('dummy1', 'objtype1'): 0, ('dummy2', 'objtype1'): 1}
Expand Down Expand Up @@ -253,7 +253,7 @@ def test_IndexBuilder():
'test': [0, 1]},
'titles': ('title1_2', 'title2_2'),
'titleterms': {'section_titl': [0, 1]},
'alltitles': {'section_title': [(0, None), (1, None)]},
'alltitles': {'section_title': [(0, ''), (1, '')]},
'indexentries': {},
}
assert index._objtypes == {('dummy1', 'objtype1'): 0, ('dummy2', 'objtype1'): 1}
Expand Down Expand Up @@ -332,8 +332,7 @@ def assert_is_sorted(item, path):
assert_is_sorted(value, f'{path}.{key}')
elif isinstance(item, list):
if not is_title_tuple_type(item) and path not in lists_not_to_sort:
# sort nulls last; http://stackoverflow.com/questions/19868767/
assert item == sorted(item, key=lambda x: (x is None, x)), f'{err_path} is not sorted'
assert item == sorted(item), f'{err_path} is not sorted'
for i, child in enumerate(item):
assert_is_sorted(child, f'{path}[{i}]')

Expand Down

0 comments on commit d44dc11

Please sign in to comment.