diff --git a/sphinx/builders/linkcheck.py b/sphinx/builders/linkcheck.py index d657e6d10ba..b8b93828fc9 100644 --- a/sphinx/builders/linkcheck.py +++ b/sphinx/builders/linkcheck.py @@ -407,8 +407,8 @@ def _check_uri(self, uri: str, hyperlink: Hyperlink) -> tuple[str, str, int]: _tls_info=(self.tls_verify, self.tls_cacerts), ) as response: if (self.check_anchors and response.ok and anchor - and not contains_anchor(response, anchor)): - raise Exception(__(f'Anchor {anchor!r} not found')) + and not contains_anchor(response, anchor)): + raise Exception(__(f'Anchor {anchor!r} not found')) # Copy data we need from the (closed) response status_code = response.status_code