From 3920af47005f62bf182650e12782be27876d5d36 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sat, 19 Oct 2024 01:50:45 +0100 Subject: [PATCH] Enable the PLW0603 lint in Ruff --- .ruff.toml | 1 - sphinx/_cli/util/colour.py | 4 ++-- sphinx/util/docutils.py | 2 +- tests/test_extensions/test_ext_doctest.py | 6 +++--- tests/test_search.py | 22 ++++++++-------------- tests/test_versioning.py | 4 ++-- 6 files changed, 16 insertions(+), 23 deletions(-) diff --git a/.ruff.toml b/.ruff.toml index 6990d5918..4dca3d16c 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -57,7 +57,6 @@ ignore = [ "PLR6201", # Use a set literal when testing for membership "PLR6301", # Method `{method_name}` could be a function, class method, or static method # pylint ('PLW') - "PLW0603", # Using the global statement to update `{name}` is discouraged "PLW1514", # `{function_name}` in text mode without explicit `encoding` argument "PLW1641", # Object does not implement `__hash__` method "PLW2901", # Outer {outer_kind} variable `{name}` overwritten by inner {inner_kind} target diff --git a/sphinx/_cli/util/colour.py b/sphinx/_cli/util/colour.py index 13d733595..bc1a610ba 100644 --- a/sphinx/_cli/util/colour.py +++ b/sphinx/_cli/util/colour.py @@ -35,12 +35,12 @@ def terminal_supports_colour() -> bool: def disable_colour() -> None: - global _COLOURING_DISABLED + global _COLOURING_DISABLED # NoQA: PLW0603 _COLOURING_DISABLED = True def enable_colour() -> None: - global _COLOURING_DISABLED + global _COLOURING_DISABLED # NoQA: PLW0603 _COLOURING_DISABLED = False diff --git a/sphinx/util/docutils.py b/sphinx/util/docutils.py index 3a7404079..a4c1c6709 100644 --- a/sphinx/util/docutils.py +++ b/sphinx/util/docutils.py @@ -758,7 +758,7 @@ def new_document(source_path: str, settings: Any = None) -> nodes.document: caches the result of docutils' and use it on second call for instantiation. This makes an instantiation of document nodes much faster. """ - global __document_cache__ + global __document_cache__ # NoQA: PLW0603 try: cached_settings, reporter = __document_cache__ except NameError: diff --git a/tests/test_extensions/test_ext_doctest.py b/tests/test_extensions/test_ext_doctest.py index 198d2ddc4..0f141f276 100644 --- a/tests/test_extensions/test_ext_doctest.py +++ b/tests/test_extensions/test_ext_doctest.py @@ -15,7 +15,7 @@ cleanup_called = 0 @pytest.mark.sphinx('doctest', testroot='ext-doctest') def test_build(app): - global cleanup_called + global cleanup_called # NoQA: PLW0603 cleanup_called = 0 app.build(force_all=True) assert app.statuscode == 0, f'failures in doctests:\n{app.status.getvalue()}' @@ -69,7 +69,7 @@ def test_is_allowed_version(): def cleanup_call(): - global cleanup_called + global cleanup_called # NoQA: PLW0603 cleanup_called += 1 @@ -87,7 +87,7 @@ def test_skipif(app): in ``test_build`` above, and the assertion below would fail. """ - global recorded_calls + global recorded_calls # NoQA: PLW0603 recorded_calls = Counter() app.build(force_all=True) if app.statuscode != 0: diff --git a/tests/test_search.py b/tests/test_search.py index 31918587a..9f0e94f83 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -62,20 +62,6 @@ class DummyDomain: return self.data -settings = parser = None - - -def setup_module(): - global settings, parser - with warnings.catch_warnings(): - warnings.filterwarnings('ignore', category=DeprecationWarning) - # DeprecationWarning: The frontend.OptionParser class will be replaced - # by a subclass of argparse.ArgumentParser in Docutils 0.21 or later. - optparser = frontend.OptionParser(components=(rst.Parser,)) - settings = optparser.get_default_values() - parser = rst.Parser() - - def load_searchindex(path: Path) -> Any: searchindex = path.read_text(encoding='utf8') assert searchindex.startswith('Search.setIndex(') @@ -180,6 +166,14 @@ def test_term_in_raw_directive(app): def test_IndexBuilder(): + with warnings.catch_warnings(): + warnings.filterwarnings('ignore', category=DeprecationWarning) + # DeprecationWarning: The frontend.OptionParser class will be replaced + # by a subclass of argparse.ArgumentParser in Docutils 0.21 or later. + optparser = frontend.OptionParser(components=(rst.Parser,)) + settings = optparser.get_default_values() + parser = rst.Parser() + domain1 = DummyDomain( 'dummy1', [ diff --git a/tests/test_versioning.py b/tests/test_versioning.py index f74b420fe..14e7520db 100644 --- a/tests/test_versioning.py +++ b/tests/test_versioning.py @@ -8,12 +8,12 @@ import pytest from sphinx.testing.util import SphinxTestApp from sphinx.versioning import add_uids, get_ratio, merge_doctrees -app = original = original_uids = None +original = original_uids = None @pytest.fixture(scope='module', autouse=True) def _setup_module(rootdir, sphinx_test_tempdir): - global app, original, original_uids + global original, original_uids # NoQA: PLW0603 srcdir = sphinx_test_tempdir / 'test-versioning' if not srcdir.exists(): shutil.copytree(rootdir / 'test-versioning', srcdir)