From 7bf847d2b9f37396d609dfeff21e472b6aea4950 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Wed, 17 Apr 2024 02:24:56 +0100 Subject: [PATCH] Fix the valid types check for ``Any`` in ``sphinx.config`` --- CHANGES.rst | 3 +++ sphinx/config.py | 2 +- tests/test_config/test_config.py | 10 +++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 8f9559e85d7..fe6ebc871ca 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,9 @@ Release 7.3.3 (in development) Bugs fixed ---------- +* #12290: Fix a false-positive warning when setting a configuration value + with ``Any`` as the valid type to a type other than the value's default. + Patch by Adam Turner. Release 7.3.2 (released Apr 17, 2024) ===================================== diff --git a/sphinx/config.py b/sphinx/config.py index 29148a53afe..84e20f6e59f 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -658,7 +658,7 @@ def check_confval_types(app: Sphinx | None, config: Config) -> None: if default is None and not valid_types: continue # neither inferable nor explicitly annotated types - if valid_types is Any: # any type of value is accepted + if valid_types == frozenset({Any}): # any type of value is accepted continue if isinstance(valid_types, ENUM): diff --git a/tests/test_config/test_config.py b/tests/test_config/test_config.py index d269b7169b0..ea9eadb2397 100644 --- a/tests/test_config/test_config.py +++ b/tests/test_config/test_config.py @@ -5,7 +5,7 @@ import time from collections import Counter from pathlib import Path -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any from unittest import mock import pytest @@ -552,6 +552,14 @@ def test_check_enum_for_list_failed(logger): assert logger.warning.called +@mock.patch("sphinx.config.logger") +def test_check_any(logger): + config = Config({'value': None}) + config.add('value', 'default', '', Any) + check_confval_types(None, config) + logger.warning.assert_not_called() # not warned + + nitpick_warnings = [ "WARNING: py:const reference target not found: prefix.anything.postfix", "WARNING: py:class reference target not found: prefix.anything",