mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-10-26 07:00:14 -05:00
Use frozensets for permitted types in `app.add_config_value()`
This commit is contained in:
1 parent
e7dd42ea91
commit
f6d1665f84
18 files changed
+111
-54
No files matched your search
@@ -927,7 +927,13 @@ class Sphinx:
|
||||
The *description* parameter.
|
||||
"""
|
||||
logger.debug('[app] adding config value: %r', (name, default, rebuild, types))
|
||||
self.config.add(name, default, rebuild, types, description)
|
||||
self.config.add(
|
||||
name=name,
|
||||
default=default,
|
||||
rebuild=rebuild,
|
||||
types=types,
|
||||
description=description,
|
||||
)
|
||||
|
||||
def add_event(self, name: str) -> None:
|
||||
"""Register an event called *name*.
|
||||
|
||||
@@ -314,7 +314,7 @@ def setup(app: Sphinx) -> ExtensionMetadata:
|
||||
app.add_config_value('epub_description', 'unknown', 'epub')
|
||||
app.add_config_value('epub_contributor', 'unknown', 'epub')
|
||||
app.add_config_value(
|
||||
'epub_writing_mode', 'horizontal', 'epub', ENUM('horizontal', 'vertical')
|
||||
'epub_writing_mode', 'horizontal', 'epub', types=ENUM('horizontal', 'vertical')
|
||||
)
|
||||
|
||||
# event handlers
|
||||
|
||||
@@ -343,11 +343,15 @@ def _gettext_compact_validator(app: Sphinx, config: Config) -> None:
|
||||
def setup(app: Sphinx) -> ExtensionMetadata:
|
||||
app.add_builder(MessageCatalogBuilder)
|
||||
|
||||
app.add_config_value('gettext_compact', True, 'gettext', {bool, str})
|
||||
app.add_config_value(
|
||||
'gettext_compact', True, 'gettext', types=frozenset({bool, str})
|
||||
)
|
||||
app.add_config_value('gettext_location', True, 'gettext')
|
||||
app.add_config_value('gettext_uuid', False, 'gettext')
|
||||
app.add_config_value('gettext_auto_build', True, 'env')
|
||||
app.add_config_value('gettext_additional_targets', [], 'env', types={set, list})
|
||||
app.add_config_value(
|
||||
'gettext_additional_targets', [], 'env', types=frozenset({set, list})
|
||||
)
|
||||
app.add_config_value(
|
||||
'gettext_last_translator', 'FULL NAME <EMAIL@ADDRESS>', 'gettext'
|
||||
)
|
||||
|
||||
@@ -1447,21 +1447,25 @@ def setup(app: Sphinx) -> ExtensionMetadata:
|
||||
'html_title',
|
||||
lambda c: _('%s %s documentation') % (c.project, c.release),
|
||||
'html',
|
||||
str,
|
||||
types=frozenset({str}),
|
||||
)
|
||||
app.add_config_value('html_short_title', lambda self: self.html_title, 'html')
|
||||
app.add_config_value('html_style', None, 'html', {list, str})
|
||||
app.add_config_value('html_logo', None, 'html', str)
|
||||
app.add_config_value('html_favicon', None, 'html', str)
|
||||
app.add_config_value('html_style', None, 'html', types=frozenset({list, str}))
|
||||
app.add_config_value('html_logo', None, 'html', types=frozenset({str}))
|
||||
app.add_config_value('html_favicon', None, 'html', types=frozenset({str}))
|
||||
app.add_config_value('html_css_files', [], 'html')
|
||||
app.add_config_value('html_js_files', [], 'html')
|
||||
app.add_config_value('html_static_path', [], 'html')
|
||||
app.add_config_value('html_extra_path', [], 'html')
|
||||
app.add_config_value('html_last_updated_fmt', None, 'html', str)
|
||||
app.add_config_value('html_last_updated_use_utc', False, 'html', types={bool})
|
||||
app.add_config_value('html_last_updated_fmt', None, 'html', types=frozenset({str}))
|
||||
app.add_config_value(
|
||||
'html_last_updated_use_utc', False, 'html', types=frozenset({bool})
|
||||
)
|
||||
app.add_config_value('html_sidebars', {}, 'html')
|
||||
app.add_config_value('html_additional_pages', {}, 'html')
|
||||
app.add_config_value('html_domain_indices', True, 'html', types={set, list})
|
||||
app.add_config_value(
|
||||
'html_domain_indices', True, 'html', types=frozenset({set, list})
|
||||
)
|
||||
app.add_config_value('html_permalinks', True, 'html')
|
||||
app.add_config_value('html_permalinks_icon', '¶', 'html')
|
||||
app.add_config_value('html_use_index', True, 'html')
|
||||
@@ -1470,8 +1474,8 @@ def setup(app: Sphinx) -> ExtensionMetadata:
|
||||
app.add_config_value('html_show_sourcelink', True, 'html')
|
||||
app.add_config_value('html_sourcelink_suffix', '.txt', 'html')
|
||||
app.add_config_value('html_use_opensearch', '', 'html')
|
||||
app.add_config_value('html_file_suffix', None, 'html', str)
|
||||
app.add_config_value('html_link_suffix', None, 'html', str)
|
||||
app.add_config_value('html_file_suffix', None, 'html', types=frozenset({str}))
|
||||
app.add_config_value('html_link_suffix', None, 'html', types=frozenset({str}))
|
||||
app.add_config_value('html_show_copyright', True, 'html')
|
||||
app.add_config_value('html_show_search_summary', True, 'html')
|
||||
app.add_config_value('html_show_sphinx', True, 'html')
|
||||
@@ -1479,14 +1483,14 @@ def setup(app: Sphinx) -> ExtensionMetadata:
|
||||
app.add_config_value('html_output_encoding', 'utf-8', 'html')
|
||||
app.add_config_value('html_compact_lists', True, 'html')
|
||||
app.add_config_value('html_secnumber_suffix', '. ', 'html')
|
||||
app.add_config_value('html_search_language', None, 'html', str)
|
||||
app.add_config_value('html_search_language', None, 'html', types=frozenset({str}))
|
||||
app.add_config_value('html_search_options', {}, 'html')
|
||||
app.add_config_value('html_search_scorer', '', '')
|
||||
app.add_config_value('html_scaled_image_link', True, 'html')
|
||||
app.add_config_value('html_baseurl', '', 'html')
|
||||
# removal is indefinitely on hold (ref: https://github.com/sphinx-doc/sphinx/issues/10265)
|
||||
app.add_config_value(
|
||||
'html_codeblock_linenos_style', 'inline', 'html', ENUM('table', 'inline')
|
||||
'html_codeblock_linenos_style', 'inline', 'html', types=ENUM('table', 'inline')
|
||||
)
|
||||
app.add_config_value('html_math_renderer', None, 'env')
|
||||
app.add_config_value('html4_writer', False, 'html')
|
||||
|
||||
@@ -611,25 +611,32 @@ def setup(app: Sphinx) -> ExtensionMetadata:
|
||||
'latex_engine',
|
||||
default_latex_engine,
|
||||
'',
|
||||
ENUM('pdflatex', 'xelatex', 'lualatex', 'platex', 'uplatex'),
|
||||
types=ENUM('pdflatex', 'xelatex', 'lualatex', 'platex', 'uplatex'),
|
||||
)
|
||||
app.add_config_value('latex_documents', default_latex_documents, '')
|
||||
app.add_config_value('latex_logo', None, '', str)
|
||||
app.add_config_value('latex_logo', None, '', types=frozenset({str}))
|
||||
app.add_config_value('latex_appendices', [], '')
|
||||
app.add_config_value('latex_use_latex_multicolumn', False, '')
|
||||
app.add_config_value('latex_use_xindy', default_latex_use_xindy, '', bool)
|
||||
app.add_config_value(
|
||||
'latex_toplevel_sectioning', None, '', ENUM(None, 'part', 'chapter', 'section')
|
||||
'latex_use_xindy', default_latex_use_xindy, '', types=frozenset({bool})
|
||||
)
|
||||
app.add_config_value('latex_domain_indices', True, '', types={set, list})
|
||||
app.add_config_value(
|
||||
'latex_toplevel_sectioning',
|
||||
None,
|
||||
'',
|
||||
types=ENUM(None, 'part', 'chapter', 'section'),
|
||||
)
|
||||
app.add_config_value('latex_domain_indices', True, '', types=frozenset({set, list}))
|
||||
app.add_config_value('latex_show_urls', 'no', '')
|
||||
app.add_config_value('latex_show_pagerefs', False, '')
|
||||
app.add_config_value('latex_elements', {}, '')
|
||||
app.add_config_value('latex_additional_files', [], '')
|
||||
app.add_config_value('latex_table_style', ['booktabs', 'colorrows'], '', list)
|
||||
app.add_config_value('latex_theme', 'manual', '', str)
|
||||
app.add_config_value(
|
||||
'latex_table_style', ['booktabs', 'colorrows'], '', types=frozenset({list})
|
||||
)
|
||||
app.add_config_value('latex_theme', 'manual', '', types=frozenset({str}))
|
||||
app.add_config_value('latex_theme_options', {}, '')
|
||||
app.add_config_value('latex_theme_path', [], '', list)
|
||||
app.add_config_value('latex_theme_path', [], '', types=frozenset({list}))
|
||||
|
||||
app.add_config_value('latex_docclass', default_latex_docclass, '')
|
||||
|
||||
|
||||
@@ -773,16 +773,22 @@ def setup(app: Sphinx) -> ExtensionMetadata:
|
||||
app.add_config_value('linkcheck_auth', [], '')
|
||||
app.add_config_value('linkcheck_request_headers', {}, '')
|
||||
app.add_config_value('linkcheck_retries', 1, '')
|
||||
app.add_config_value('linkcheck_timeout', 30, '', (int, float))
|
||||
app.add_config_value('linkcheck_timeout', 30, '', types=frozenset({int, float}))
|
||||
app.add_config_value('linkcheck_workers', 5, '')
|
||||
app.add_config_value('linkcheck_anchors', True, '')
|
||||
# Anchors starting with ! are ignored since they are
|
||||
# commonly used for dynamic pages
|
||||
app.add_config_value('linkcheck_anchors_ignore', ['^!'], '')
|
||||
app.add_config_value('linkcheck_anchors_ignore_for_url', (), '', (tuple, list))
|
||||
app.add_config_value('linkcheck_rate_limit_timeout', 300.0, '', (int, float))
|
||||
app.add_config_value(
|
||||
'linkcheck_anchors_ignore_for_url', (), '', types=frozenset({tuple, list})
|
||||
)
|
||||
app.add_config_value(
|
||||
'linkcheck_rate_limit_timeout', 300.0, '', types=frozenset({int, float})
|
||||
)
|
||||
app.add_config_value('linkcheck_allow_unauthorized', False, '')
|
||||
app.add_config_value('linkcheck_report_timeouts_as_broken', False, '', bool)
|
||||
app.add_config_value(
|
||||
'linkcheck_report_timeouts_as_broken', False, '', types=frozenset({bool})
|
||||
)
|
||||
|
||||
app.add_event('linkcheck-process-uri')
|
||||
|
||||
|
||||
@@ -259,7 +259,9 @@ def setup(app: Sphinx) -> ExtensionMetadata:
|
||||
app.add_config_value('texinfo_documents', default_texinfo_documents, '')
|
||||
app.add_config_value('texinfo_appendices', [], '')
|
||||
app.add_config_value('texinfo_elements', {}, '')
|
||||
app.add_config_value('texinfo_domain_indices', True, '', types={set, list})
|
||||
app.add_config_value(
|
||||
'texinfo_domain_indices', True, '', types=frozenset({set, list})
|
||||
)
|
||||
app.add_config_value('texinfo_show_urls', 'footnote', '')
|
||||
app.add_config_value('texinfo_no_detailmenu', False, '')
|
||||
app.add_config_value('texinfo_cross_references', True, '')
|
||||
|
||||
@@ -947,11 +947,18 @@ class CDomain(Domain):
|
||||
|
||||
def setup(app: Sphinx) -> ExtensionMetadata:
|
||||
app.add_domain(CDomain)
|
||||
app.add_config_value('c_id_attributes', [], 'env', types={list, tuple})
|
||||
app.add_config_value('c_paren_attributes', [], 'env', types={list, tuple})
|
||||
app.add_config_value('c_extra_keywords', _macro_keywords, 'env', types={set, list})
|
||||
app.add_config_value('c_id_attributes', [], 'env', types=frozenset({list, tuple}))
|
||||
app.add_config_value(
|
||||
'c_maximum_signature_line_length', None, 'env', types={int, type(None)}
|
||||
'c_paren_attributes', [], 'env', types=frozenset({list, tuple})
|
||||
)
|
||||
app.add_config_value(
|
||||
'c_extra_keywords', _macro_keywords, 'env', types=frozenset({set, list})
|
||||
)
|
||||
app.add_config_value(
|
||||
'c_maximum_signature_line_length',
|
||||
None,
|
||||
'env',
|
||||
types=frozenset({int, type(None)}),
|
||||
)
|
||||
app.add_post_transform(AliasTransform)
|
||||
|
||||
|
||||
@@ -1303,10 +1303,15 @@ class CPPDomain(Domain):
|
||||
def setup(app: Sphinx) -> ExtensionMetadata:
|
||||
app.add_domain(CPPDomain)
|
||||
app.add_config_value('cpp_index_common_prefix', [], 'env')
|
||||
app.add_config_value('cpp_id_attributes', [], 'env', types={list, tuple})
|
||||
app.add_config_value('cpp_paren_attributes', [], 'env', types={list, tuple})
|
||||
app.add_config_value('cpp_id_attributes', [], 'env', types=frozenset({list, tuple}))
|
||||
app.add_config_value(
|
||||
'cpp_maximum_signature_line_length', None, 'env', types={int, type(None)}
|
||||
'cpp_paren_attributes', [], 'env', types=frozenset({list, tuple})
|
||||
)
|
||||
app.add_config_value(
|
||||
'cpp_maximum_signature_line_length',
|
||||
None,
|
||||
'env',
|
||||
types=frozenset({int, type(None)}),
|
||||
)
|
||||
app.add_post_transform(AliasTransform)
|
||||
|
||||
|
||||
@@ -562,7 +562,10 @@ class JavaScriptDomain(Domain):
|
||||
def setup(app: Sphinx) -> ExtensionMetadata:
|
||||
app.add_domain(JavaScriptDomain)
|
||||
app.add_config_value(
|
||||
'javascript_maximum_signature_line_length', None, 'env', {int, type(None)}
|
||||
'javascript_maximum_signature_line_length',
|
||||
None,
|
||||
'env',
|
||||
types=frozenset({int, type(None)}),
|
||||
)
|
||||
return {
|
||||
'version': 'builtin',
|
||||
|
||||
@@ -1080,7 +1080,10 @@ def setup(app: Sphinx) -> ExtensionMetadata:
|
||||
app.add_domain(PythonDomain)
|
||||
app.add_config_value('python_use_unqualified_type_names', False, 'env')
|
||||
app.add_config_value(
|
||||
'python_maximum_signature_line_length', None, 'env', {int, type(None)}
|
||||
'python_maximum_signature_line_length',
|
||||
None,
|
||||
'env',
|
||||
types=frozenset({int, type(None)}),
|
||||
)
|
||||
app.add_config_value('python_display_short_literal_types', False, 'env')
|
||||
app.connect('object-description-transform', filter_meta_fields)
|
||||
|
||||
@@ -3141,19 +3141,19 @@ def setup(app: Sphinx) -> ExtensionMetadata:
|
||||
'autoclass_content',
|
||||
'class',
|
||||
'env',
|
||||
ENUM('both', 'class', 'init'),
|
||||
types=ENUM('both', 'class', 'init'),
|
||||
)
|
||||
app.add_config_value(
|
||||
'autodoc_member_order',
|
||||
'alphabetical',
|
||||
'env',
|
||||
ENUM('alphabetical', 'bysource', 'groupwise'),
|
||||
types=ENUM('alphabetical', 'bysource', 'groupwise'),
|
||||
)
|
||||
app.add_config_value(
|
||||
'autodoc_class_signature',
|
||||
'mixed',
|
||||
'env',
|
||||
ENUM('mixed', 'separated'),
|
||||
types=ENUM('mixed', 'separated'),
|
||||
)
|
||||
app.add_config_value('autodoc_default_options', {}, 'env')
|
||||
app.add_config_value('autodoc_docstring_signature', True, 'env')
|
||||
@@ -3162,20 +3162,20 @@ def setup(app: Sphinx) -> ExtensionMetadata:
|
||||
'autodoc_typehints',
|
||||
'signature',
|
||||
'env',
|
||||
ENUM('signature', 'description', 'none', 'both'),
|
||||
types=ENUM('signature', 'description', 'none', 'both'),
|
||||
)
|
||||
app.add_config_value(
|
||||
'autodoc_typehints_description_target',
|
||||
'all',
|
||||
'env',
|
||||
ENUM('all', 'documented', 'documented_params'),
|
||||
types=ENUM('all', 'documented', 'documented_params'),
|
||||
)
|
||||
app.add_config_value('autodoc_type_aliases', {}, 'env')
|
||||
app.add_config_value(
|
||||
'autodoc_typehints_format',
|
||||
'short',
|
||||
'env',
|
||||
ENUM('fully-qualified', 'short'),
|
||||
types=ENUM('fully-qualified', 'short'),
|
||||
)
|
||||
app.add_config_value('autodoc_warningiserror', True, 'env')
|
||||
app.add_config_value('autodoc_inherit_docstrings', True, 'env')
|
||||
|
||||
@@ -943,13 +943,19 @@ def setup(app: Sphinx) -> ExtensionMetadata:
|
||||
app.connect('builder-inited', process_generate_options)
|
||||
app.add_config_value('autosummary_context', {}, 'env')
|
||||
app.add_config_value('autosummary_filename_map', {}, 'html')
|
||||
app.add_config_value('autosummary_generate', True, 'env', {bool, list})
|
||||
app.add_config_value(
|
||||
'autosummary_generate', True, 'env', types=frozenset({bool, list})
|
||||
)
|
||||
app.add_config_value('autosummary_generate_overwrite', True, '')
|
||||
app.add_config_value(
|
||||
'autosummary_mock_imports', lambda config: config.autodoc_mock_imports, 'env'
|
||||
)
|
||||
app.add_config_value('autosummary_imported_members', False, '', bool)
|
||||
app.add_config_value('autosummary_ignore_module_all', True, 'env', bool)
|
||||
app.add_config_value(
|
||||
'autosummary_imported_members', False, '', types=frozenset({bool})
|
||||
)
|
||||
app.add_config_value(
|
||||
'autosummary_ignore_module_all', True, 'env', types=frozenset({bool})
|
||||
)
|
||||
|
||||
return {
|
||||
'version': sphinx.__display_version__,
|
||||
|
||||
@@ -525,7 +525,7 @@ class CoverageBuilder(Builder):
|
||||
|
||||
def setup(app: Sphinx) -> ExtensionMetadata:
|
||||
app.add_builder(CoverageBuilder)
|
||||
app.add_config_value('coverage_modules', (), '', types={tuple, list})
|
||||
app.add_config_value('coverage_modules', (), '', types=frozenset({tuple, list}))
|
||||
app.add_config_value('coverage_ignore_modules', [], '')
|
||||
app.add_config_value('coverage_ignore_functions', [], '')
|
||||
app.add_config_value('coverage_ignore_classes', [], '')
|
||||
@@ -534,8 +534,12 @@ def setup(app: Sphinx) -> ExtensionMetadata:
|
||||
app.add_config_value('coverage_c_regexes', {}, '')
|
||||
app.add_config_value('coverage_ignore_c_items', {}, '')
|
||||
app.add_config_value('coverage_write_headline', True, '')
|
||||
app.add_config_value('coverage_statistics_to_report', True, '', bool)
|
||||
app.add_config_value('coverage_statistics_to_stdout', True, '', bool)
|
||||
app.add_config_value(
|
||||
'coverage_statistics_to_report', True, '', types=frozenset({bool})
|
||||
)
|
||||
app.add_config_value(
|
||||
'coverage_statistics_to_stdout', True, '', types=frozenset({bool})
|
||||
)
|
||||
app.add_config_value('coverage_skip_undoc_in_source', False, '')
|
||||
app.add_config_value('coverage_show_missing_items', False, '')
|
||||
return {
|
||||
|
||||
@@ -627,7 +627,7 @@ def setup(app: Sphinx) -> ExtensionMetadata:
|
||||
app.add_directive('testoutput', TestoutputDirective)
|
||||
app.add_builder(DocTestBuilder)
|
||||
# this config value adds to sys.path
|
||||
app.add_config_value('doctest_show_successes', True, '', bool)
|
||||
app.add_config_value('doctest_show_successes', True, '', types=frozenset({bool}))
|
||||
app.add_config_value('doctest_path', (), '')
|
||||
app.add_config_value('doctest_test_doctest_blocks', 'default', '')
|
||||
app.add_config_value('doctest_global_setup', '', '')
|
||||
|
||||
@@ -431,7 +431,7 @@ def setup(app: Sphinx) -> ExtensionMetadata:
|
||||
app.add_config_value('imgmath_latex_preamble', '', 'html')
|
||||
app.add_config_value('imgmath_add_tooltips', True, 'html')
|
||||
app.add_config_value('imgmath_font_size', 12, 'html')
|
||||
app.add_config_value('imgmath_embed', False, 'html', bool)
|
||||
app.add_config_value('imgmath_embed', False, 'html', types=frozenset({bool}))
|
||||
app.connect('build-finished', clean_up_files)
|
||||
return {
|
||||
'version': sphinx.__display_version__,
|
||||
|
||||
@@ -384,7 +384,7 @@ def setup(app: Sphinx) -> ExtensionMetadata:
|
||||
app.add_config_value('viewcode_import', None, '')
|
||||
app.add_config_value('viewcode_enable_epub', False, '')
|
||||
app.add_config_value('viewcode_follow_imported_members', True, '')
|
||||
app.add_config_value('viewcode_line_numbers', False, 'env', bool)
|
||||
app.add_config_value('viewcode_line_numbers', False, 'env', types=frozenset({bool}))
|
||||
app.connect('doctree-read', doctree_read)
|
||||
app.connect('env-merge-info', env_merge_info)
|
||||
app.connect('env-purge-doc', env_purge_doc)
|
||||
|
||||
@@ -162,7 +162,7 @@ def test_config_pickle_circular_reference_in_list():
|
||||
|
||||
config = Config()
|
||||
config.add('a', [], '', types=list)
|
||||
config.add('b', [], '', types=list)
|
||||
config.add('b', [], '', types=frozenset({list}))
|
||||
config.a, config.b = a, b
|
||||
|
||||
actual = pickle.loads(pickle.dumps(config))
|
||||
@@ -244,7 +244,7 @@ def test_config_pickle_circular_reference_in_dict():
|
||||
check_is_serializable(x, circular=True)
|
||||
|
||||
config = Config()
|
||||
config.add('x', [], '', types=dict)
|
||||
config.add('x', [], '', types=frozenset({dict}))
|
||||
config.x = x
|
||||
|
||||
actual = pickle.loads(pickle.dumps(config))
|
||||
|
||||
Reference in new issue
Block a user