Skip to content

Commit 7ae5b43

Browse files
committed
Define the class manually
1 parent 1a0ca8e commit 7ae5b43

File tree

1 file changed

+75
-19
lines changed

1 file changed

+75
-19
lines changed

sphinx/ext/autodoc/_shared.py

Lines changed: 75 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from __future__ import annotations
44

5-
import dataclasses
65
from typing import TYPE_CHECKING
76

87
from sphinx.util.inspect import safe_getattr
@@ -18,28 +17,44 @@ class _AttrGetter(Protocol): # NoQA: PYI046
1817
def __call__(self, obj: Any, name: str, default: Any = ..., /) -> Any: ...
1918

2019

21-
@dataclasses.dataclass(frozen=True, kw_only=True, slots=True)
2220
class _AutodocConfig:
23-
autoclass_content: Literal['both', 'class', 'init'] = 'class'
24-
autodoc_class_signature: Literal['mixed', 'separated'] = 'mixed'
25-
autodoc_default_options: Mapping[str, str | bool] = {}.keys().mapping
26-
autodoc_docstring_signature: bool = True
27-
autodoc_inherit_docstrings: bool = True
28-
autodoc_member_order: Literal['alphabetical', 'bysource', 'groupwise'] = (
29-
'alphabetical'
21+
__slots__ = (
22+
'autoclass_content',
23+
'autodoc_class_signature',
24+
'autodoc_default_options',
25+
'autodoc_docstring_signature',
26+
'autodoc_inherit_docstrings',
27+
'autodoc_member_order',
28+
'autodoc_mock_imports',
29+
'autodoc_preserve_defaults',
30+
'autodoc_type_aliases',
31+
'autodoc_typehints',
32+
'autodoc_typehints_description_target',
33+
'autodoc_typehints_format',
34+
'autodoc_use_type_comments',
35+
# non-autodoc config
36+
'python_display_short_literal_types',
37+
'strip_signature_backslash',
3038
)
31-
autodoc_mock_imports: Sequence[str] = ()
32-
autodoc_preserve_defaults: bool = False
33-
autodoc_type_aliases: Mapping[str, str] = {}.keys().mapping
34-
autodoc_typehints: Literal['signature', 'description', 'none', 'both'] = 'signature'
39+
40+
autoclass_content: Literal['both', 'class', 'init']
41+
autodoc_class_signature: Literal['mixed', 'separated']
42+
autodoc_default_options: Mapping[str, str | bool]
43+
autodoc_docstring_signature: bool
44+
autodoc_inherit_docstrings: bool
45+
autodoc_member_order: Literal['alphabetical', 'bysource', 'groupwise']
46+
autodoc_mock_imports: Sequence[str]
47+
autodoc_preserve_defaults: bool
48+
autodoc_type_aliases: Mapping[str, str]
49+
autodoc_typehints: Literal['signature', 'description', 'none', 'both']
3550
autodoc_typehints_description_target: Literal[
3651
'all', 'documented', 'documented_params'
37-
] = 'all'
38-
autodoc_typehints_format: Literal['fully-qualified', 'short'] = 'short'
39-
autodoc_use_type_comments: bool = True
40-
41-
python_display_short_literal_types: bool = False
42-
strip_signature_backslash: bool = False
52+
]
53+
autodoc_typehints_format: Literal['fully-qualified', 'short']
54+
autodoc_use_type_comments: bool
55+
# non-autodoc config
56+
python_display_short_literal_types: bool
57+
strip_signature_backslash: bool
4358

4459
@classmethod
4560
def from_config(cls, config: Config) -> _AutodocConfig:
@@ -61,6 +76,47 @@ def from_config(cls, config: Config) -> _AutodocConfig:
6176
strip_signature_backslash=config.strip_signature_backslash,
6277
)
6378

79+
def __init__(
80+
self,
81+
*,
82+
autoclass_content: Literal['both', 'class', 'init'] = 'class',
83+
autodoc_class_signature: Literal['mixed', 'separated'] = 'mixed',
84+
autodoc_default_options: Mapping[str, str | bool] = {}.keys().mapping,
85+
autodoc_docstring_signature: bool = True,
86+
autodoc_inherit_docstrings: bool = True,
87+
autodoc_member_order: Literal['alphabetical', 'bysource', 'groupwise'] = (
88+
'alphabetical'
89+
),
90+
autodoc_mock_imports: Sequence[str] = (),
91+
autodoc_preserve_defaults: bool = False,
92+
autodoc_type_aliases: Mapping[str, str] = {}.keys().mapping,
93+
autodoc_typehints: Literal[
94+
'signature', 'description', 'none', 'both'
95+
] = 'signature',
96+
autodoc_typehints_description_target: Literal[
97+
'all', 'documented', 'documented_params'
98+
] = 'all',
99+
autodoc_typehints_format: Literal['fully-qualified', 'short'] = 'short',
100+
autodoc_use_type_comments: bool = True,
101+
python_display_short_literal_types: bool = False,
102+
strip_signature_backslash: bool = False,
103+
) -> None:
104+
for name in self.__slots__:
105+
super().__setattr__(name, locals()[name])
106+
107+
def __repr__(self) -> str:
108+
items = ((name, getattr(self, name)) for name in self.__slots__)
109+
args = ', '.join(f'{name}={value!r}' for name, value in items)
110+
return f'_AutodocConfig({args})'
111+
112+
def __setattr__(self, key: str, value: Any) -> NoReturn:
113+
msg = f'{self.__class__.__name__} is immutable'
114+
raise AttributeError(msg)
115+
116+
def __delattr__(self, key: str) -> NoReturn:
117+
msg = f'{self.__class__.__name__} is immutable'
118+
raise AttributeError(msg)
119+
64120

65121
class _AutodocAttrGetter:
66122
"""getattr() override for types such as Zope interfaces."""

0 commit comments

Comments
 (0)