[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-04-13 00:00:18 +00:00
parent 72ad6dc953
commit f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions

View file

@ -1,17 +1,16 @@
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
"""Source file annotation for coverage.py."""
from __future__ import annotations
import os
import re
from typing import Iterable, TYPE_CHECKING
from typing import Iterable
from typing import TYPE_CHECKING
from coverage.files import flat_rootname
from coverage.misc import ensure_dir, isolate_module
from coverage.misc import ensure_dir
from coverage.misc import isolate_module
from coverage.plugin import FileReporter
from coverage.report_core import get_analysis_to_report
from coverage.results import Analysis
@ -50,8 +49,8 @@ class AnnotateReporter:
self.config = self.coverage.config
self.directory: str | None = None
blank_re = re.compile(r"\s*(#|$)")
else_re = re.compile(r"\s*else\s*:\s*(#|$)")
blank_re = re.compile(r'\s*(#|$)')
else_re = re.compile(r'\s*else\s*:\s*(#|$)')
def report(self, morfs: Iterable[TMorf] | None, directory: str | None = None) -> None:
"""Run the report.
@ -77,13 +76,13 @@ class AnnotateReporter:
if self.directory:
ensure_dir(self.directory)
dest_file = os.path.join(self.directory, flat_rootname(fr.relative_filename()))
if dest_file.endswith("_py"):
dest_file = dest_file[:-3] + ".py"
dest_file += ",cover"
if dest_file.endswith('_py'):
dest_file = dest_file[:-3] + '.py'
dest_file += ',cover'
else:
dest_file = fr.filename + ",cover"
dest_file = fr.filename + ',cover'
with open(dest_file, "w", encoding="utf-8") as dest:
with open(dest_file, 'w', encoding='utf-8') as dest:
i = j = 0
covered = True
source = fr.source()
@ -95,20 +94,20 @@ class AnnotateReporter:
if i < len(statements) and statements[i] == lineno:
covered = j >= len(missing) or missing[j] > lineno
if self.blank_re.match(line):
dest.write(" ")
dest.write(' ')
elif self.else_re.match(line):
# Special logic for lines containing only "else:".
if j >= len(missing):
dest.write("> ")
dest.write('> ')
elif statements[i] == missing[j]:
dest.write("! ")
dest.write('! ')
else:
dest.write("> ")
dest.write('> ')
elif lineno in excluded:
dest.write("- ")
dest.write('- ')
elif covered:
dest.write("> ")
dest.write('> ')
else:
dest.write("! ")
dest.write('! ')
dest.write(line)