Skip to content

Commit 6b237d9

Browse files
[linkcheck] Allow integer for linkcheck_rate_limit_timeout (#12470)
Eliminate type-related warnings when users configure a valid integer value for the `linkcheck_rate_limit_timeout` config setting. Co-authored-by: Chris Sewell <[email protected]>
1 parent 2ccae70 commit 6b237d9

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ Bugs fixed
5858
Patch by Bénédikt Tran.
5959
* #12220: Fix loading custom template translations for ``en`` locale.
6060
Patch by Nicolas Peugnet.
61+
* #12459: Add valid-type arguments to the ``linkcheck_rate_limit_timeout``
62+
configuration setting.
63+
Patch by James Addison.
6164

6265
Improvements
6366
------------

doc/usage/configuration.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2950,8 +2950,8 @@ Options for the linkcheck builder
29502950

29512951
Otherwise, ``linkcheck`` waits for a minute before to retry and keeps
29522952
doubling the wait time between attempts until it succeeds or exceeds the
2953-
``linkcheck_rate_limit_timeout``. By default, the timeout is 300 seconds
2954-
and custom timeouts should be given in seconds.
2953+
``linkcheck_rate_limit_timeout``. By default, the timeout is 300 seconds.
2954+
Custom timeouts should be given as a number of seconds.
29552955

29562956
.. _Retry-After: https://datatracker.ietf.org/doc/html/rfc7231#section-7.1.3
29572957

sphinx/builders/linkcheck.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ def setup(app: Sphinx) -> ExtensionMetadata:
708708
# commonly used for dynamic pages
709709
app.add_config_value('linkcheck_anchors_ignore', ['^!'], '')
710710
app.add_config_value('linkcheck_anchors_ignore_for_url', (), '', (tuple, list))
711-
app.add_config_value('linkcheck_rate_limit_timeout', 300.0, '')
711+
app.add_config_value('linkcheck_rate_limit_timeout', 300.0, '', (int, float))
712712
app.add_config_value('linkcheck_allow_unauthorized', True, '')
713713
app.add_config_value('linkcheck_report_timeouts_as_broken', True, '', bool)
714714

tests/test_builders/test_build_linkcheck.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -936,21 +936,23 @@ def test_limit_rate_doubles_previous_wait_time(app: Sphinx) -> None:
936936
assert next_check == 120.0
937937

938938

939-
@pytest.mark.sphinx(confoverrides={'linkcheck_rate_limit_timeout': 90.0})
940-
def test_limit_rate_clips_wait_time_to_max_time(app: Sphinx) -> None:
939+
@pytest.mark.sphinx(confoverrides={'linkcheck_rate_limit_timeout': 90})
940+
def test_limit_rate_clips_wait_time_to_max_time(app: Sphinx, warning: StringIO) -> None:
941941
rate_limits = {"localhost": RateLimit(60.0, 0.0)}
942942
worker = HyperlinkAvailabilityCheckWorker(app.config, Queue(), Queue(), rate_limits)
943943
with mock.patch('time.time', return_value=0.0):
944944
next_check = worker.limit_rate(FakeResponse.url, FakeResponse.headers.get("Retry-After"))
945945
assert next_check == 90.0
946+
assert warning.getvalue() == ''
946947

947948

948949
@pytest.mark.sphinx(confoverrides={'linkcheck_rate_limit_timeout': 90.0})
949-
def test_limit_rate_bails_out_after_waiting_max_time(app: Sphinx) -> None:
950+
def test_limit_rate_bails_out_after_waiting_max_time(app: Sphinx, warning: StringIO) -> None:
950951
rate_limits = {"localhost": RateLimit(90.0, 0.0)}
951952
worker = HyperlinkAvailabilityCheckWorker(app.config, Queue(), Queue(), rate_limits)
952953
next_check = worker.limit_rate(FakeResponse.url, FakeResponse.headers.get("Retry-After"))
953954
assert next_check is None
955+
assert warning.getvalue() == ''
954956

955957

956958
@mock.patch('sphinx.util.requests.requests.Session.get_adapter')

0 commit comments

Comments
 (0)