Skip to content

Commit 55f39bb

Browse files
committed
fix _Opt deprecation warning
closes readthedocs#234
1 parent bf8ef76 commit 55f39bb

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

notfound/extension.py

+22-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import html
2-
import docutils.nodes
32
import os
43
import warnings
54

5+
import docutils.nodes
66
import sphinx
77
from sphinx.environment.collectors import EnvironmentCollector
88
from sphinx.errors import ExtensionError
@@ -13,7 +13,6 @@
1313

1414
class BaseURIError(ExtensionError):
1515
"""Exception for malformed base URI."""
16-
pass
1716

1817

1918
# https://www.sphinx-doc.org/en/stable/extdev/appapi.html#event-html-collect-pages
@@ -167,7 +166,11 @@ def toctree(*args, **kwargs):
167166
# We have to overwrite them here to use our own `pathto` function.
168167
# The code is borrowed exactly from Sphinx 7.2.2, there is no changes.
169168
if sphinx.version_info >= (7, 2):
170-
from sphinx.builders.html._assets import _CascadingStyleSheet, _file_checksum, _JavaScript
169+
from sphinx.builders.html._assets import (
170+
_CascadingStyleSheet,
171+
_file_checksum,
172+
_JavaScript,
173+
)
171174

172175
outdir = app.outdir
173176

@@ -266,14 +269,22 @@ def validate_configs(app, *args, **kwargs):
266269
267270
Shows a warning if one of the configs is not valid.
268271
"""
269-
default, rebuild, types = app.config.values.get('notfound_urls_prefix')
270-
if app.config.notfound_urls_prefix != default:
271-
if app.config.notfound_urls_prefix and not all([
272-
app.config.notfound_urls_prefix.startswith('/'),
273-
app.config.notfound_urls_prefix.endswith('/'),
274-
]):
275-
message = 'notfound_urls_prefix should start and end with "/" (slash)'
276-
warnings.warn(message, UserWarning, stacklevel=2)
272+
notfound_urls_prefix = app.config.notfound_urls_prefix
273+
default = (
274+
app.config.values.get("notfound_urls_prefix").default
275+
if sphinx.version_info >= (7, 2)
276+
else app.config.values.get("notfound_urls_prefix")[0]
277+
)
278+
279+
if (
280+
notfound_urls_prefix != default
281+
and notfound_urls_prefix
282+
and not (
283+
notfound_urls_prefix.startswith("/") or notfound_urls_prefix.endswith("/")
284+
)
285+
):
286+
message = 'notfound_urls_prefix should start and end with "/" (slash)'
287+
warnings.warn(message, UserWarning, stacklevel=2)
277288

278289

279290
def setup(app):

0 commit comments

Comments
 (0)