diff options
author | Tom Oinn <tomoinn@gmail.com> | 2021-06-04 20:51:02 +0100 |
---|---|---|
committer | Tom Oinn <tomoinn@crypticsquid.com> | 2021-06-04 20:51:02 +0100 |
commit | 676983e177397fe2b0f33d00fa8cfe014b2cc23c (patch) | |
tree | 6a7bd0a29c4c2f39cddcb3f39692feb971ebe17b | |
parent | 732a7d673d2af00e20c402780096a06f9881a735 (diff) | |
download | sphinx-git-676983e177397fe2b0f33d00fa8cfe014b2cc23c.tar.gz |
Somewhat more efficient fix.
Only looks for case insensitive match if there isn't a case sensitive one, and uses filter to build a list of case insensitive matches rather than building a dict.
-rw-r--r-- | sphinx/ext/intersphinx.py | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/sphinx/ext/intersphinx.py b/sphinx/ext/intersphinx.py index a24208718..4795d1ae2 100644 --- a/sphinx/ext/intersphinx.py +++ b/sphinx/ext/intersphinx.py @@ -305,19 +305,28 @@ def missing_reference(app: Sphinx, env: BuildEnvironment, node: pending_xref, to_try.append((inventories.named_inventory[setname], full_qualified_name)) for inventory, target in to_try: for objtype in objtypes: - # Special case handling for term to search in a case insensitive fashion - if objtype == 'std:term' and objtype in inventory: - cased_keys = {k.lower(): k for k in inventory[objtype].keys()} - if target.lower() in cased_keys: - corrected_target = cased_keys[target.lower()] - proj, version, uri, dispname = inventory[objtype][corrected_target] + if objtype not in inventory: + # Continue if there's nothing of this kind in the inventory + continue + if target in inventory[objtype]: + # Case sensitive match, use it + proj, version, uri, dispname = inventory[objtype][target] + elif objtype == 'std:term': + # Check for potential case insensitive matches for terms only + target_lower = target.lower() + insensitive_matches = list(filter(lambda k: k.lower() == target_lower, + inventory[objtype].keys())) + if insensitive_matches: + proj, version, uri, dispname = inventory[objtype][insensitive_matches[0]] else: + # No case insensitive match either, continue to the next candidate continue else: - # Default behaviour pre-patch - if objtype not in inventory or target not in inventory[objtype]: - continue - proj, version, uri, dispname = inventory[objtype][target] + # Could reach here if we're not a term but have a case insensitive match. + # This is a fix for terms specifically, but potentially should apply to + # other types. + continue + if '://' not in uri and node.get('refdoc'): # get correct path in case of subdirectories uri = path.join(relative_path(node['refdoc'], '.'), uri) |