diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8668c18..d64d981 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,6 +12,10 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - id: check-executables-have-shebangs + - repo: https://github.com/asottile/pyupgrade + rev: v3.3.1 + hooks: + - id: pyupgrade - repo: https://github.com/psf/black rev: 22.12.0 hooks: diff --git a/pyproject.toml b/pyproject.toml index f03d865..e6cc00f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,11 +23,11 @@ classifiers = [ "Operating System :: POSIX :: Linux", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Topic :: System :: Systems Administration", "Topic :: Utilities", ] @@ -36,7 +36,7 @@ keywords = [ "rst", "linter", ] -requires-python = ">=3.7" +requires-python = ">=3.8" dependencies = [ # Ceiled due to DeprecationWarning: The frontend.OptionParser class will be # replaced by a subclass of argparse.ArgumentParser in Docutils 0.21 or later. @@ -71,6 +71,7 @@ filterwarnings = [ ] [[tool.mypy.overrides]] +python_version = "3.8" module = [ "doc8._version", "restructuredtext_lint", @@ -78,6 +79,9 @@ module = [ ] ignore_missing_imports = true +[tool.pylint.MAIN] +py-version = "3.8.0" + [tool.pylint."MESSAGES CONTROL"] disable = [ diff --git a/src/doc8/checks.py b/src/doc8/checks.py index 67c073d..6d9a574 100644 --- a/src/doc8/checks.py +++ b/src/doc8/checks.py @@ -313,5 +313,4 @@ def report_iter(self, parsed_file): checker_func = self._txt_checker else: checker_func = self._rst_checker - for issue in checker_func(parsed_file): - yield issue + yield from checker_func(parsed_file) diff --git a/src/doc8/main.py b/src/doc8/main.py index 2dfe85f..c061cc6 100644 --- a/src/doc8/main.py +++ b/src/doc8/main.py @@ -85,7 +85,7 @@ def parse_ignore_path_errors(entries): def from_ini(fp): parser = configparser.RawConfigParser() - with open(fp, "r", encoding="utf-8") as fh: + with open(fp, encoding="utf-8") as fh: parser.read_file(fh) cfg = {} @@ -275,10 +275,14 @@ def validate(cfg, files, result=None): line_num = "?" if cfg.get("verbose"): print( - " - %s:%s: %s %s" % (f.filename, line_num, code, message) + " - {}:{}: {} {}".format( + f.filename, line_num, code, message + ) ) elif not result.capture: - print("%s:%s: %s %s" % (f.filename, line_num, code, message)) + print( + "{}:{}: {} {}".format(f.filename, line_num, code, message) + ) result.error(check_name, f.filename, line_num, code, message) error_counts[check_name] += 1 elif isinstance(c, checks.LineCheck): @@ -293,12 +297,14 @@ def validate(cfg, files, result=None): ) elif not result.capture: print( - "%s:%s: %s %s" % (f.filename, line_num, code, message) + "{}:{}: {} {}".format( + f.filename, line_num, code, message + ) ) result.error(check_name, f.filename, line_num, code, message) error_counts[check_name] += 1 else: - raise TypeError("Unknown check type: %s, %s" % (type(c), c)) + raise TypeError("Unknown check type: {}, {}".format(type(c), c)) return error_counts @@ -321,7 +327,7 @@ def get_defaults(): } -class Result(object): +class Result: def __init__(self): self.files_selected = 0 self.files_ignored = 0 @@ -360,7 +366,7 @@ def report(self): lines.append("Detailed error counts:") for check_name in sorted(self.error_counts.keys()): check_errors = self.error_counts[check_name] - lines.append(" - %s = %s" % (check_name, check_errors)) + lines.append(" - {} = {}".format(check_name, check_errors)) return "\n".join(lines) diff --git a/src/doc8/parser.py b/src/doc8/parser.py index f9c17aa..28652f7 100644 --- a/src/doc8/parser.py +++ b/src/doc8/parser.py @@ -22,7 +22,7 @@ import restructuredtext_lint as rl -class ParsedFile(object): +class ParsedFile: FALLBACK_ENCODING = "utf-8" def __init__(self, filename, encoding=None, default_extension=""): @@ -127,7 +127,7 @@ def contents(self): return self._content def __str__(self): - return "%s (%s, %s chars, %s lines)" % ( + return "{} ({}, {} chars, {} lines)".format( self.filename, self.encoding, len(self.contents), @@ -137,5 +137,5 @@ def __str__(self): def parse(filename, encoding=None, default_extension=""): if not os.path.isfile(filename): - raise IOError(errno.ENOENT, "File not found", filename) + raise OSError(errno.ENOENT, "File not found", filename) return ParsedFile(filename, encoding=encoding, default_extension=default_extension) diff --git a/src/doc8/tests/test_checks.py b/src/doc8/tests/test_checks.py index 79e0618..fb19ff7 100644 --- a/src/doc8/tests/test_checks.py +++ b/src/doc8/tests/test_checks.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (C) 2014 Yahoo! Inc. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/src/doc8/tests/test_main.py b/src/doc8/tests/test_main.py index f52322c..8fcd595 100644 --- a/src/doc8/tests/test_main.py +++ b/src/doc8/tests/test_main.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import os from io import StringIO import unittest @@ -79,7 +77,7 @@ - doc8.checks.CheckValidity = 0""" -class Capture(object): +class Capture: """ Context manager to capture output on stdout and stderr """ @@ -100,7 +98,7 @@ def __exit__(self, *args): sys.stderr = self.err -class TmpFs(object): +class TmpFs: """ Context manager to create and clean a temporary file area for testing """ @@ -134,7 +132,7 @@ def expected(self, template): return template.format(path=self.path) -class FakeResult(object): +class FakeResult: """ Minimum valid result returned from doc8 """ diff --git a/src/doc8/utils.py b/src/doc8/utils.py index b8bd08a..9606976 100644 --- a/src/doc8/utils.py +++ b/src/doc8/utils.py @@ -53,7 +53,7 @@ def path_ignorable(path): if extension_matches(path): yield (path, path_ignorable(path)) else: - raise IOError("Invalid path: %s" % path) + raise OSError("Invalid path: %s" % path) def filtered_traverse(document, filter_func): diff --git a/src/doc8/version.py b/src/doc8/version.py index fe71aec..36e6f0e 100644 --- a/src/doc8/version.py +++ b/src/doc8/version.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (C) 2014 Yahoo! Inc. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may