@@ -179,7 +179,7 @@ def process_result(self, result: CheckResult) -> None:
179
179
text = 'with unknown code'
180
180
linkstat ['text' ] = text
181
181
redirection = f'{ text } to { result .message } '
182
- if self .config .linkcheck_allowed_redirects is not None :
182
+ if self .config .linkcheck_allowed_redirects is not _sentinel_lar :
183
183
msg = f'redirect { res_uri } - { redirection } '
184
184
logger .warning (msg , location = (result .docname , result .lineno ))
185
185
else :
@@ -387,7 +387,7 @@ def __init__(
387
387
)
388
388
self .check_anchors : bool = config .linkcheck_anchors
389
389
self .allowed_redirects : dict [re .Pattern [str ], re .Pattern [str ]]
390
- self .allowed_redirects = config .linkcheck_allowed_redirects or {}
390
+ self .allowed_redirects = config .linkcheck_allowed_redirects
391
391
self .retries : int = config .linkcheck_retries
392
392
self .rate_limit_timeout = config .linkcheck_rate_limit_timeout
393
393
self ._allow_unauthorized = config .linkcheck_allow_unauthorized
@@ -722,6 +722,8 @@ def handle_starttag(self, tag: Any, attrs: Any) -> None:
722
722
def _allowed_redirect (
723
723
url : str , new_url : str , allowed_redirects : dict [re .Pattern [str ], re .Pattern [str ]]
724
724
) -> bool :
725
+ if allowed_redirects is _sentinel_lar :
726
+ return True
725
727
return any (
726
728
from_url .match (url ) and to_url .match (new_url )
727
729
for from_url , to_url in allowed_redirects .items ()
@@ -751,7 +753,6 @@ def rewrite_github_anchor(app: Sphinx, uri: str) -> str | None:
751
753
def compile_linkcheck_allowed_redirects (app : Sphinx , config : Config ) -> None :
752
754
"""Compile patterns to the regexp objects."""
753
755
if config .linkcheck_allowed_redirects is _sentinel_lar :
754
- config .linkcheck_allowed_redirects = None
755
756
return
756
757
if not isinstance (config .linkcheck_allowed_redirects , dict ):
757
758
raise ConfigError
0 commit comments