Skip to content

Commit 7bf847d

Browse files
committed
Fix the valid types check for Any in sphinx.config
1 parent 1e98161 commit 7bf847d

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Release 7.3.3 (in development)
44
Bugs fixed
55
----------
66

7+
* #12290: Fix a false-positive warning when setting a configuration value
8+
with ``Any`` as the valid type to a type other than the value's default.
9+
Patch by Adam Turner.
710

811
Release 7.3.2 (released Apr 17, 2024)
912
=====================================

sphinx/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ def check_confval_types(app: Sphinx | None, config: Config) -> None:
658658
if default is None and not valid_types:
659659
continue # neither inferable nor explicitly annotated types
660660

661-
if valid_types is Any: # any type of value is accepted
661+
if valid_types == frozenset({Any}): # any type of value is accepted
662662
continue
663663

664664
if isinstance(valid_types, ENUM):

tests/test_config/test_config.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import time
66
from collections import Counter
77
from pathlib import Path
8-
from typing import TYPE_CHECKING
8+
from typing import TYPE_CHECKING, Any
99
from unittest import mock
1010

1111
import pytest
@@ -552,6 +552,14 @@ def test_check_enum_for_list_failed(logger):
552552
assert logger.warning.called
553553

554554

555+
@mock.patch("sphinx.config.logger")
556+
def test_check_any(logger):
557+
config = Config({'value': None})
558+
config.add('value', 'default', '', Any)
559+
check_confval_types(None, config)
560+
logger.warning.assert_not_called() # not warned
561+
562+
555563
nitpick_warnings = [
556564
"WARNING: py:const reference target not found: prefix.anything.postfix",
557565
"WARNING: py:class reference target not found: prefix.anything",

0 commit comments

Comments
 (0)