Repository: sphinx-doc/sphinx

Issue:
Failing test_enum_class with Python 3.13.0a5
### Describe the bug

I try to build sphinx in Fedora Linux 41 with Python 3.13.0a5.
`test_enum_class` fails.
repr of the Enum class has changed. Now there's `names=<not given>` instead of None. This is an expected change, see: https://github.com/python/cpython/pull/116508#issuecomment-2015319193

```
_______________________________ test_enum_class ________________________________

app = <SphinxTestApp buildername='html'>

    @pytest.mark.sphinx('html', testroot='ext-autodoc')
    def test_enum_class(app):
        options = {"members": None}
        actual = do_autodoc(app, 'class', 'target.enums.EnumCls', options)
    
        if sys.version_info[:2] >= (3, 12):
            args = ('(value, names=None, *values, module=None, '
                    'qualname=None, type=None, start=1, boundary=None)')
        elif sys.version_info[:2] >= (3, 11):
            args = ('(value, names=None, *, module=None, qualname=None, '
                    'type=None, start=1, boundary=None)')
        else:
            args = '(value)'
    
>       assert list(actual) == [
            '',
            '.. py:class:: EnumCls' + args,
            '   :module: target.enums',
            '',
            '   this is enum class',
            '',
            '',
            '   .. py:method:: EnumCls.say_goodbye()',
            '      :module: target.enums',
            '      :classmethod:',
            '',
            '      a classmethod says good-bye to you.',
            '',
            '',
            '   .. py:method:: EnumCls.say_hello()',
            '      :module: target.enums',
            '',
            '      a method says hello to you.',
            '',
            '',
            '   .. py:attribute:: EnumCls.val1',
            '      :module: target.enums',
            '      :value: 12',
            '',
            '      doc for val1',
            '',
            '',
            '   .. py:attribute:: EnumCls.val2',
            '      :module: target.enums',
            '      :value: 23',
            '',
            '      doc for val2',
            '',
            '',
            '   .. py:attribute:: EnumCls.val3',
            '      :module: target.enums',
            '      :value: 34',
            '',
            '      doc for val3',
            '',
        ]
E       AssertionError: assert ['', '.. py:c...ass', '', ...] == ['', '.. py:c...ass', '', ...]
E         At index 1 diff: '.. py:class:: EnumCls(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)' != '.. py:class:: EnumCls(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)'
```

### How to Reproduce

Probably by running tests with Python 3.13.0a5, but I haven't tried it on the upstream code.

### Environment Information

```text
Sphinx 7.2.6
```


### Sphinx extensions

_No response_

### Additional context

_No response_

Discussion:

Patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index f0c7f5730..c97caebbe 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,9 +1,35 @@
-Release 7.3.2 (in development)
+Release 7.3.5 (in development)
 ==============================
 
 Bugs fixed
 ----------
 
+
+Release 7.3.4 (released Apr 17, 2024)
+=====================================
+
+Bugs fixed
+----------
+
+* Handle cases when ``Any`` is not an instance of ``type``.
+  Patch by Adam Turner.
+
+Release 7.3.3 (released Apr 17, 2024)
+=====================================
+
+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)
+=====================================
+
+Bugs fixed
+----------
+
 * Preload all themes defined via entry points.
   Patch by Adam Turner.
 * Fix a bad interaction between the ``'Furo'`` theme and the new-style for
diff --git a/sphinx/__init__.py b/sphinx/__init__.py
index 7a5ff1131..0fff74d32 100644
--- a/sphinx/__init__.py
+++ b/sphinx/__init__.py
@@ -1,6 +1,6 @@
 """The Sphinx documentation toolchain."""
 
-__version__ = '7.3.2'
+__version__ = '7.3.5'
 __display_version__ = __version__  # used for command line version
 
 # Keep this file executable as-is in Python 3!
@@ -28,7 +28,7 @@
 #:
 #: .. versionadded:: 1.2
 #:    Before version 1.2, check the string ``sphinx.__version__``.
-version_info = (7, 3, 2, 'beta', 0)
+version_info = (7, 3, 5, 'beta', 0)
 
 package_dir = path.abspath(path.dirname(__file__))
 
diff --git a/sphinx/config.py b/sphinx/config.py
index 29148a53a..ee7f5806c 100644
--- a/sphinx/config.py
+++ b/sphinx/config.py
@@ -534,6 +534,8 @@ def _validate_valid_types(
         return valid_types
     if isinstance(valid_types, type):
         return frozenset((valid_types,))
+    if valid_types is Any:
+        return frozenset({Any})  # type: ignore[arg-type]
     if isinstance(valid_types, set):
         return frozenset(valid_types)
     if not isinstance(valid_types, tuple):
@@ -658,7 +660,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):


Test patch:
diff --git a/tests/test_config/test_config.py b/tests/test_config/test_config.py
index d269b7169..ea9eadb23 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",
diff --git a/tests/test_extensions/test_ext_autodoc.py b/tests/test_extensions/test_ext_autodoc.py
index 254f1d9dd..54f81f2c2 100644
--- a/tests/test_extensions/test_ext_autodoc.py
+++ b/tests/test_extensions/test_ext_autodoc.py
@@ -1454,7 +1454,7 @@ def brief(self, doc: str, *, indent: int = 0, **options: Any) -> list[str]:
         """Generate the brief part of the class being documented."""
         assert doc, f'enumeration class {self.target!r} should have an explicit docstring'
 
-        if sys.version_info[:2] >= (3, 13):
+        if sys.version_info[:2] >= (3, 13) or sys.version_info[:3] >= (3, 12, 3):
             args = ('(value, names=<not given>, *values, module=None, '
                     'qualname=None, type=None, start=1, boundary=None)')
         elif sys.version_info[:2] >= (3, 12):