Skip to content

Commit a7daab6

Browse files
authored
Merge branch 'master' into master
2 parents 851968f + ae51974 commit a7daab6

File tree

17 files changed

+128
-63
lines changed

17 files changed

+128
-63
lines changed

.github/ISSUE_TEMPLATE/bug-report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Bug report
22
description: Something is not working correctly.
3-
labels: "bug"
3+
labels: "type:bug"
44

55
body:
66
- type: textarea

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name: Feature request
33
about: Suggest an idea for this project
44
title: '<short description for the feature>'
5-
labels: 'enhancement'
5+
labels: 'type:proposal'
66
assignees: ''
77

88
---

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ Features added
3333
Bugs fixed
3434
----------
3535

36+
* #11959: Fix multiple term matching when word appears in both title and document.
37+
Patch by Will Lachance.
38+
* #11958: HTML Search: Fix partial matches overwriting full matches.
39+
Patch by William Lachance.
3640
* #11944: Use anchor in search preview.
3741
Patch by Will Lachance.
3842
* #11668: Raise a useful error when ``theme.conf`` is missing.
@@ -84,6 +88,8 @@ Bugs fixed
8488
Patch by James Addison.
8589
* #11962: Fix target resolution when using ``:paramtype:`` fields.
8690
Patch by Bénédikt Tran.
91+
* #12008: Fix case-sensitive lookup of ``std:label`` names in intersphinx inventory.
92+
Patch by Michael Goerz.
8793

8894
Testing
8995
-------

sphinx/builders/html/transforms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def run(self, **kwargs: Any) -> None:
4747
matcher = NodeMatcher(nodes.literal, classes=["kbd"])
4848
# this list must be pre-created as during iteration new nodes
4949
# are added which match the condition in the NodeMatcher.
50-
for node in list(self.document.findall(matcher)): # type: nodes.literal
50+
for node in list(matcher.findall(self.document)):
5151
parts = self.pattern.split(node[-1].astext())
5252
if len(parts) == 1 or self.is_multiwords_key(parts):
5353
continue

sphinx/builders/latex/transforms.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class FootnoteDocnameUpdater(SphinxTransform):
3737

3838
def apply(self, **kwargs: Any) -> None:
3939
matcher = NodeMatcher(*self.TARGET_NODES)
40-
for node in self.document.findall(matcher): # type: Element
40+
for node in matcher.findall(self.document):
4141
node['docname'] = self.env.docname
4242

4343

@@ -538,7 +538,7 @@ class CitationReferenceTransform(SphinxPostTransform):
538538
def run(self, **kwargs: Any) -> None:
539539
domain = cast(CitationDomain, self.env.get_domain('citation'))
540540
matcher = NodeMatcher(addnodes.pending_xref, refdomain='citation', reftype='ref')
541-
for node in self.document.findall(matcher): # type: addnodes.pending_xref
541+
for node in matcher.findall(self.document):
542542
docname, labelid, _ = domain.citations.get(node['reftarget'], ('', '', 0))
543543
if docname:
544544
citation_ref = nodes.citation_reference('', '', *node.children,
@@ -574,7 +574,7 @@ class LiteralBlockTransform(SphinxPostTransform):
574574

575575
def run(self, **kwargs: Any) -> None:
576576
matcher = NodeMatcher(nodes.container, literal_block=True)
577-
for node in self.document.findall(matcher): # type: nodes.container
577+
for node in matcher.findall(self.document):
578578
newnode = captioned_literal_block('', *node.children, **node.attributes)
579579
node.replace_self(newnode)
580580

sphinx/ext/doctest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,12 @@ def init(self) -> None:
311311
'==================================%s\n') %
312312
(date, '=' * len(date)))
313313

314+
def __del__(self) -> None:
315+
# free resources upon destruction (the file handler might not be
316+
# closed if the builder is never used)
317+
if hasattr(self, 'outfile'):
318+
self.outfile.close()
319+
314320
def _out(self, text: str) -> None:
315321
logger.info(text, nonl=True)
316322
self.outfile.write(text)

sphinx/ext/intersphinx.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,10 @@ def _resolve_reference_in_domain_by_target(
334334
if target in inventory[objtype]:
335335
# Case sensitive match, use it
336336
data = inventory[objtype][target]
337-
elif objtype == 'std:term':
338-
# Check for potential case insensitive matches for terms only
337+
elif objtype in {'std:label', 'std:term'}:
338+
# Some types require case insensitive matches:
339+
# * 'term': https://github.com/sphinx-doc/sphinx/issues/9291
340+
# * 'label': https://github.com/sphinx-doc/sphinx/issues/12008
339341
target_lower = target.lower()
340342
insensitive_matches = list(filter(lambda k: k.lower() == target_lower,
341343
inventory[objtype].keys()))

sphinx/themes/basic/static/searchtools.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -477,14 +477,18 @@ const Search = {
477477
// add support for partial matches
478478
if (word.length > 2) {
479479
const escapedWord = _escapeRegExp(word);
480-
Object.keys(terms).forEach((term) => {
481-
if (term.match(escapedWord) && !terms[word])
482-
arr.push({ files: terms[term], score: Scorer.partialTerm });
483-
});
484-
Object.keys(titleTerms).forEach((term) => {
485-
if (term.match(escapedWord) && !titleTerms[word])
486-
arr.push({ files: titleTerms[word], score: Scorer.partialTitle });
487-
});
480+
if (!terms.hasOwnProperty(word)) {
481+
Object.keys(terms).forEach((term) => {
482+
if (term.match(escapedWord))
483+
arr.push({ files: terms[term], score: Scorer.partialTerm });
484+
});
485+
}
486+
if (!titleTerms.hasOwnProperty(word)) {
487+
Object.keys(titleTerms).forEach((term) => {
488+
if (term.match(escapedWord))
489+
arr.push({ files: titleTerms[word], score: Scorer.partialTitle });
490+
});
491+
}
488492
}
489493

490494
// no match but word was a required one
@@ -507,9 +511,8 @@ const Search = {
507511

508512
// create the mapping
509513
files.forEach((file) => {
510-
if (fileMap.has(file) && fileMap.get(file).indexOf(word) === -1)
511-
fileMap.get(file).push(word);
512-
else fileMap.set(file, [word]);
514+
if (!fileMap.has(file)) fileMap.set(file, [word]);
515+
else if (fileMap.get(file).indexOf(word) === -1) fileMap.get(file).push(word);
513516
});
514517
});
515518

sphinx/transforms/i18n.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def update_title_mapping(self) -> bool:
182182

183183
# replace target's refname to new target name
184184
matcher = NodeMatcher(nodes.target, refname=old_name)
185-
for old_target in self.document.findall(matcher): # type: nodes.target
185+
for old_target in matcher.findall(self.document):
186186
old_target['refname'] = new_name
187187

188188
processed = True
@@ -198,10 +198,8 @@ def list_replace_or_append(lst: list[N], old: N, new: N) -> None:
198198
lst.append(new)
199199

200200
is_autofootnote_ref = NodeMatcher(nodes.footnote_reference, auto=Any)
201-
old_foot_refs: list[nodes.footnote_reference] = [
202-
*self.node.findall(is_autofootnote_ref)]
203-
new_foot_refs: list[nodes.footnote_reference] = [
204-
*self.patch.findall(is_autofootnote_ref)]
201+
old_foot_refs = list(is_autofootnote_ref.findall(self.node))
202+
new_foot_refs = list(is_autofootnote_ref.findall(self.patch))
205203
self.compare_references(old_foot_refs, new_foot_refs,
206204
__('inconsistent footnote references in translated message.' +
207205
' original: {0}, translated: {1}'))
@@ -240,8 +238,8 @@ def update_refnamed_references(self) -> None:
240238
# * use translated refname for section refname.
241239
# * inline reference "`Python <...>`_" has no 'refname'.
242240
is_refnamed_ref = NodeMatcher(nodes.reference, refname=Any)
243-
old_refs: list[nodes.reference] = [*self.node.findall(is_refnamed_ref)]
244-
new_refs: list[nodes.reference] = [*self.patch.findall(is_refnamed_ref)]
241+
old_refs = list(is_refnamed_ref.findall(self.node))
242+
new_refs = list(is_refnamed_ref.findall(self.patch))
245243
self.compare_references(old_refs, new_refs,
246244
__('inconsistent references in translated message.' +
247245
' original: {0}, translated: {1}'))
@@ -264,10 +262,8 @@ def update_refnamed_references(self) -> None:
264262
def update_refnamed_footnote_references(self) -> None:
265263
# refnamed footnote should use original 'ids'.
266264
is_refnamed_footnote_ref = NodeMatcher(nodes.footnote_reference, refname=Any)
267-
old_foot_refs: list[nodes.footnote_reference] = [*self.node.findall(
268-
is_refnamed_footnote_ref)]
269-
new_foot_refs: list[nodes.footnote_reference] = [*self.patch.findall(
270-
is_refnamed_footnote_ref)]
265+
old_foot_refs = list(is_refnamed_footnote_ref.findall(self.node))
266+
new_foot_refs = list(is_refnamed_footnote_ref.findall(self.patch))
271267
refname_ids_map: dict[str, list[str]] = {}
272268
self.compare_references(old_foot_refs, new_foot_refs,
273269
__('inconsistent footnote references in translated message.' +
@@ -282,8 +278,8 @@ def update_refnamed_footnote_references(self) -> None:
282278
def update_citation_references(self) -> None:
283279
# citation should use original 'ids'.
284280
is_citation_ref = NodeMatcher(nodes.citation_reference, refname=Any)
285-
old_cite_refs: list[nodes.citation_reference] = [*self.node.findall(is_citation_ref)]
286-
new_cite_refs: list[nodes.citation_reference] = [*self.patch.findall(is_citation_ref)]
281+
old_cite_refs = list(is_citation_ref.findall(self.node))
282+
new_cite_refs = list(is_citation_ref.findall(self.patch))
287283
self.compare_references(old_cite_refs, new_cite_refs,
288284
__('inconsistent citation references in translated message.' +
289285
' original: {0}, translated: {1}'))
@@ -549,7 +545,7 @@ def apply(self, **kwargs: Any) -> None:
549545
return
550546

551547
total = translated = 0
552-
for node in self.document.findall(NodeMatcher(translated=Any)): # type: nodes.Element
548+
for node in NodeMatcher(nodes.Element, translated=Any).findall(self.document):
553549
total += 1
554550
if node['translated']:
555551
translated += 1
@@ -588,7 +584,7 @@ def apply(self, **kwargs: Any) -> None:
588584
'True, False, "translated" or "untranslated"')
589585
raise ConfigError(msg)
590586

591-
for node in self.document.findall(NodeMatcher(translated=Any)): # type: nodes.Element
587+
for node in NodeMatcher(nodes.Element, translated=Any).findall(self.document):
592588
if node['translated']:
593589
if add_translated:
594590
node.setdefault('classes', []).append('translated')
@@ -610,7 +606,7 @@ def apply(self, **kwargs: Any) -> None:
610606
return
611607

612608
matcher = NodeMatcher(nodes.inline, translatable=Any)
613-
for inline in list(self.document.findall(matcher)): # type: nodes.inline
609+
for inline in matcher.findall(self.document):
614610
inline.parent.remove(inline)
615611
inline.parent += inline.children
616612

sphinx/util/docfields.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def make_field(
236236
inliner: Inliner | None = None,
237237
location: Element | None = None,
238238
) -> nodes.field:
239-
def handle_item(fieldarg: str, content: str) -> nodes.paragraph:
239+
def handle_item(fieldarg: str, content: list[Node]) -> nodes.paragraph:
240240
par = nodes.paragraph()
241241
par.extend(self.make_xrefs(self.rolename, domain, fieldarg,
242242
addnodes.literal_strong, env=env))
@@ -254,8 +254,10 @@ def handle_item(fieldarg: str, content: str) -> nodes.paragraph:
254254
else:
255255
par += fieldtype
256256
par += nodes.Text(')')
257-
par += nodes.Text(' -- ')
258-
par += content
257+
has_content = any(c.astext().strip() for c in content)
258+
if has_content:
259+
par += nodes.Text(' -- ')
260+
par += content
259261
return par
260262

261263
fieldname = nodes.field_name('', self.label)

0 commit comments

Comments
 (0)