Skip to content

Fix sphinx-doc__sphinx-9711: needs_extensions checks versions using strings#14384

Closed
piyushhhxyz wants to merge 1 commit intosphinx-doc:masterfrom
piyushhhxyz:fix-sphinx-doc__sphinx-9711
Closed

Fix sphinx-doc__sphinx-9711: needs_extensions checks versions using strings#14384
piyushhhxyz wants to merge 1 commit intosphinx-doc:masterfrom
piyushhhxyz:fix-sphinx-doc__sphinx-9711

Conversation

@piyushhhxyz
Copy link
Copy Markdown

Summary

Fix needs_extensions version comparison to use proper semantic versioning instead of string comparison.

Problem

The verify_needs_extensions function in sphinx/extension.py compared version strings using plain Python string comparison (reqversion > extension.version). This causes incorrect results for multi-digit version components because string comparison is lexicographic:

  • '0.6' > '0.10' evaluates to True (because '6' > '1')
  • But semantically, version 0.10 is newer than 0.6

This meant extensions at version 0.10+ would be incorrectly rejected when the minimum required version was lower (e.g., 0.6).

Fix

Replace the string comparison with packaging.version.parse() for proper semantic version comparison:

# Before (string comparison - broken)
if extension.version == 'unknown version' or reqversion > extension.version:

# After (semantic version comparison - correct)  
if extension.version == 'unknown version' or parse_version(reqversion) > parse_version(extension.version):

packaging is already a dependency of Sphinx and is used elsewhere in the codebase (e.g., sphinx/ext/doctest.py).

Fixes #9711

The needs_extensions check was comparing version strings using plain string
comparison, which incorrectly treats '0.6' > '0.10' because '6' > '1' in
lexicographic order. This caused extensions with versions >= 0.10 to be
rejected when the minimum required version was lower (e.g., 0.6).

Fix by using packaging.version.parse() for proper semantic version comparison.

Fixes sphinx-doc#9711
@piyushhhxyz piyushhhxyz deleted the fix-sphinx-doc__sphinx-9711 branch April 10, 2026 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant