diff options
author | Adam Turner <9087854+aa-turner@users.noreply.github.com> | 2023-03-05 12:54:01 +0000 |
---|---|---|
committer | Adam Turner <9087854+aa-turner@users.noreply.github.com> | 2023-03-05 12:54:24 +0000 |
commit | 18f8c0bfc8fcb2121bc3670baca670211fe77966 (patch) | |
tree | 92bffb9f6275455fb701adf75e64664adaf465a5 | |
parent | ba080286b06cb9e0cadec59a6cf1f96aa11aef5a (diff) | |
download | sphinx-git-18f8c0bfc8fcb2121bc3670baca670211fe77966.tar.gz |
Resolve lint errors from Ruff 0.0.254
-rw-r--r-- | pyproject.toml | 5 | ||||
-rw-r--r-- | sphinx/util/logging.py | 41 | ||||
-rw-r--r-- | tests/test_quickstart.py | 2 | ||||
-rw-r--r-- | tests/typing_test_data.py | 2 |
4 files changed, 25 insertions, 25 deletions
diff --git a/pyproject.toml b/pyproject.toml index 7d3d0624b..15ea09c71 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -166,6 +166,7 @@ ignore = [ # flake8-bugbear 'B006', # do not use mutable data structures for argument default 'B023', # function definition does not bind loop variable + "B026", # keyword argument ... must come after starred arguments # flake8-bugbear opinionated (disabled by default in flake8) 'B904', # within an except clause, raise exceptions with `raise ... from ...` # flake8-blind-except @@ -217,6 +218,9 @@ ignore = [ "PLR0912", # too many branches "PLR0913", # too many arguments to function call "PLR0915", # too many statements + "PLR5501", # consider using elif to remove an indentation level + "PLW0603", # using the global statement to update variables is discouraged + "PLW2901", # outer loop variable overwritten by inner assignment # flake8-pytest-style "PT003", # `scope='function'` is implied in `@pytest.fixture()` "PT006", # wrong name type in `@pytest.mark.parametrize`, @@ -235,7 +239,6 @@ ignore = [ # Ruff-specific rules "RUF001", # string contains ambiguous unicode character "RUF003", # comment contains ambiguous unicode character - "RUF004", # keyword argument ... must come after starred arguments "RUF005", # consider unpacking instead of concatenation # flake8-bandit "S101", # assert used diff --git a/sphinx/util/logging.py b/sphinx/util/logging.py index da7f01ba0..369aa4137 100644 --- a/sphinx/util/logging.py +++ b/sphinx/util/logging.py @@ -23,8 +23,7 @@ if TYPE_CHECKING: NAMESPACE = 'sphinx' VERBOSE = 15 -LEVEL_NAMES: dict[str, int] = defaultdict(lambda: logging.WARNING) -LEVEL_NAMES.update({ +LEVEL_NAMES: defaultdict[str, int] = defaultdict(lambda: logging.WARNING, { 'CRITICAL': logging.CRITICAL, 'SEVERE': logging.CRITICAL, 'ERROR': logging.ERROR, @@ -34,19 +33,17 @@ LEVEL_NAMES.update({ 'DEBUG': logging.DEBUG, }) -VERBOSITY_MAP: dict[int, int] = defaultdict(lambda: 0) -VERBOSITY_MAP.update({ +VERBOSITY_MAP: defaultdict[int, int] = defaultdict(lambda: logging.NOTSET, { 0: logging.INFO, 1: VERBOSE, 2: logging.DEBUG, }) -COLOR_MAP = defaultdict(lambda: 'blue', - { - logging.ERROR: 'darkred', - logging.WARNING: 'red', - logging.DEBUG: 'darkgray', - }) +COLOR_MAP: defaultdict[int, str] = defaultdict(lambda: 'blue', { + logging.ERROR: 'darkred', + logging.WARNING: 'red', + logging.DEBUG: 'darkgray', +}) def getLogger(name: str) -> SphinxLoggerAdapter: @@ -490,16 +487,17 @@ class SphinxLogRecordTranslator(logging.Filter): location = getattr(record, 'location', None) if isinstance(location, tuple): docname, lineno = location - if docname and lineno: - record.location = f'{self.app.env.doc2path(docname)}:{lineno}' - elif docname: - record.location = '%s' % self.app.env.doc2path(docname) + if docname: + if lineno: + record.location = f'{self.app.env.doc2path(docname)}:{lineno}' + else: + record.location = f'{self.app.env.doc2path(docname)}' else: record.location = None elif isinstance(location, nodes.Node): record.location = get_node_location(location) elif location and ':' not in location: - record.location = '%s' % self.app.env.doc2path(location) + record.location = f'{self.app.env.doc2path(location)}' return True @@ -515,17 +513,16 @@ class WarningLogRecordTranslator(SphinxLogRecordTranslator): def get_node_location(node: Node) -> str | None: - (source, line) = get_source_line(node) + source, line = get_source_line(node) if source: source = abspath(source) if source and line: return f"{source}:{line}" - elif source: - return "%s:" % source - elif line: - return "<unknown>:%s" % line - else: - return None + if source: + return f"{source}:" + if line: + return f"<unknown>:{line}" + return None class ColorizeFormatter(logging.Formatter): diff --git a/tests/test_quickstart.py b/tests/test_quickstart.py index fd9ab4277..bba97f5e3 100644 --- a/tests/test_quickstart.py +++ b/tests/test_quickstart.py @@ -185,7 +185,7 @@ def test_generated_files_eol(tempdir): def assert_eol(filename, eol): content = filename.read_bytes().decode() - assert all([l[-len(eol):] == eol for l in content.splitlines(True)]) + assert all(l[-len(eol):] == eol for l in content.splitlines(keepends=True)) assert_eol(tempdir / 'make.bat', '\r\n') assert_eol(tempdir / 'Makefile', '\n') diff --git a/tests/typing_test_data.py b/tests/typing_test_data.py index 4f0e45742..26f619fdc 100644 --- a/tests/typing_test_data.py +++ b/tests/typing_test_data.py @@ -1,5 +1,5 @@ from inspect import Signature -from numbers import Integral # NoQA: TCH003 +from numbers import Integral from typing import Any, Callable, Dict, List, Optional, Tuple, TypeVar, Union |