Skip to content

Commit 4b268cd

Browse files
committed
Specify valid types for configuration options
1 parent 0b0f818 commit 4b268cd

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

sphinxext/opengraph/__init__.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
from sphinxext.opengraph._meta_parser import get_meta_description
1313
from sphinxext.opengraph._title_parser import get_title
1414

15+
try:
16+
from types import NoneType
17+
except ImportError:
18+
NoneType = type(None)
19+
1520
if TYPE_CHECKING:
1621
from typing import Any
1722

@@ -326,17 +331,32 @@ def make_tag(property: str, content: str, type_: str = 'property') -> str:
326331
def setup(app: Sphinx) -> ExtensionMetadata:
327332
# ogp_site_url="" allows relative by default, even though it's not
328333
# officially supported by OGP.
329-
app.add_config_value('ogp_site_url', '', 'html')
330-
app.add_config_value('ogp_canonical_url', '', 'html')
331-
app.add_config_value('ogp_description_length', DEFAULT_DESCRIPTION_LENGTH, 'html')
332-
app.add_config_value('ogp_image', None, 'html')
333-
app.add_config_value('ogp_image_alt', None, 'html')
334-
app.add_config_value('ogp_use_first_image', False, 'html')
335-
app.add_config_value('ogp_type', 'website', 'html')
336-
app.add_config_value('ogp_site_name', None, 'html')
337-
app.add_config_value('ogp_social_cards', None, 'html')
338-
app.add_config_value('ogp_custom_meta_tags', (), 'html')
339-
app.add_config_value('ogp_enable_meta_description', True, 'html')
334+
app.add_config_value('ogp_site_url', '', 'html', types=frozenset({str}))
335+
app.add_config_value('ogp_canonical_url', '', 'html', types=frozenset({str}))
336+
app.add_config_value(
337+
'ogp_description_length',
338+
DEFAULT_DESCRIPTION_LENGTH,
339+
'html',
340+
types=frozenset({int}),
341+
)
342+
app.add_config_value('ogp_image', None, 'html', types=frozenset({str, NoneType}))
343+
app.add_config_value(
344+
'ogp_image_alt', None, 'html', types=frozenset({str, bool, NoneType})
345+
)
346+
app.add_config_value('ogp_use_first_image', False, 'html', types=frozenset({bool}))
347+
app.add_config_value('ogp_type', 'website', 'html', types=frozenset({str}))
348+
app.add_config_value(
349+
'ogp_site_name', None, 'html', types=frozenset({str, bool, NoneType})
350+
)
351+
app.add_config_value(
352+
'ogp_social_cards', None, 'html', types=frozenset({dict, NoneType})
353+
)
354+
app.add_config_value(
355+
'ogp_custom_meta_tags', (), 'html', types=frozenset({list, tuple})
356+
)
357+
app.add_config_value(
358+
'ogp_enable_meta_description', True, 'html', types=frozenset({bool})
359+
)
340360

341361
# Main Sphinx OpenGraph linking
342362
app.connect('html-page-context', html_page_context)

0 commit comments

Comments
 (0)