Skip to content

Commit c33085c

Browse files
committed
style: start gradual move to ruff 0.16
We aren't running ruff automatically yet, still on pylint. But this lets us run ruff manually and make changes.
1 parent 53a0fd5 commit c33085c

22 files changed

Lines changed: 56 additions & 106 deletions

‎coverage/cmdline.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,6 @@ def __init__(self, **kwargs: Any) -> None:
432432
class OptionParserError(Exception):
433433
"""Used to stop the optparse error handler ending the process."""
434434

435-
pass
436-
437435
def parse_args_ok(self, args: list[str]) -> tuple[bool, optparse.Values | None, list[str]]:
438436
"""Call optparse.parse_args, but return a triple:
439437
@@ -753,8 +751,7 @@ def show_help(
753751
# coverage-3.5-script.py. argv[0] is the .py file, but we want to
754752
# get back to the original form.
755753
auto_suffix = "-script.py"
756-
if program_name.endswith(auto_suffix):
757-
program_name = program_name[: -len(auto_suffix)]
754+
program_name = program_name.removesuffix(auto_suffix)
758755

759756
help_params = dict(coverage.__dict__)
760757
help_params["__url__"] = __url__

‎coverage/collector.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,7 @@ def __init__(
148148

149149
if self.concur_id_func and not hasattr(core.tracer_class, "concur_id_func"):
150150
raise ConfigError(
151-
"Can't support concurrency={} with {}, only threads are supported.".format(
152-
tried,
153-
self.tracer_name(),
154-
),
151+
f"Can't support concurrency={tried} with {self.tracer_name()}, only threads are supported.",
155152
)
156153

157154
if do_threading or not concurrency:

‎coverage/config.py‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,7 @@ def from_file(self, filename: str, warn: Callable[[str], None], our_file: bool)
344344
if real_section:
345345
for unknown in set(cp.options(section)) - options:
346346
warn(
347-
"Unrecognized option '[{}] {}=' in config file {}".format(
348-
real_section,
349-
unknown,
350-
filename,
351-
),
347+
f"Unrecognized option '[{real_section}] {unknown}=' in config file {filename}",
352348
)
353349

354350
# [paths] is special

‎coverage/control.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,10 +1048,7 @@ def _get_file_reporter(self, morf: TMorf) -> FileReporter:
10481048
file_reporter = plugin.file_reporter(mapped_morf)
10491049
if file_reporter is None:
10501050
raise PluginError(
1051-
"Plugin {!r} did not provide a file reporter for {!r}.".format(
1052-
plugin._coverage_plugin_name,
1053-
morf,
1054-
),
1051+
f"Plugin {plugin._coverage_plugin_name!r} did not provide a file reporter for {morf!r}.",
10551052
)
10561053

10571054
if file_reporter == "python":

‎coverage/exceptions.py‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,44 +30,30 @@ def __init__(
3030
class ConfigError(CoverageException):
3131
"""A problem with a config file, or a value in one."""
3232

33-
pass
34-
3533

3634
class DataError(CoverageException):
3735
"""An error in using a data file."""
3836

39-
pass
40-
4137

4238
class NoDataError(CoverageException):
4339
"""We didn't have data to work with."""
4440

45-
pass
46-
4741

4842
class NoSource(CoverageException):
4943
"""We couldn't find the source for a module."""
5044

51-
pass
52-
5345

5446
class NoCode(NoSource):
5547
"""We couldn't find any code at all."""
5648

57-
pass
58-
5949

6050
class NotPython(CoverageException):
6151
"""A source file turned out not to be parsable Python."""
6252

63-
pass
64-
6553

6654
class PluginError(CoverageException):
6755
"""A plugin misbehaved."""
6856

69-
pass
70-
7157

7258
class _ExceptionDuringRun(CoverageException):
7359
"""An exception happened while running customer code.
@@ -76,10 +62,6 @@ class _ExceptionDuringRun(CoverageException):
7662
7763
"""
7864

79-
pass
80-
8165

8266
class CoverageWarning(Warning):
8367
"""A warning from Coverage.py."""
84-
85-
pass

‎coverage/inorout.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,10 +539,7 @@ def warn_already_imported_files(self) -> None:
539539
warned.add(filename)
540540
elif self.debug and self.debug.should("trace"):
541541
self.debug.write(
542-
"Didn't trace already imported file {!r}: {}".format(
543-
disp.original_filename,
544-
disp.reason,
545-
),
542+
f"Didn't trace already imported file {disp.original_filename!r}: {disp.reason}",
546543
)
547544

548545
def warn_unimported_source(self) -> None:

‎coverage/parser.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import tokenize
1414
from collections.abc import Callable, Iterable, Sequence
1515
from dataclasses import dataclass
16-
from typing import Optional, Protocol, cast
16+
from typing import Protocol, cast
1717

1818
from coverage import env
1919
from coverage.bytecode import ByteParser
@@ -521,7 +521,7 @@ def __call__(
521521
"""
522522

523523

524-
TArcFragments = dict[TArc, list[tuple[Optional[str], Optional[str]]]]
524+
TArcFragments = dict[TArc, list[tuple[str | None, str | None]]]
525525

526526

527527
class Block:

‎coverage/plugin.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ def configure(self, config: TConfigurable) -> None:
237237
methods on the `config` object.
238238
239239
"""
240-
pass
241240

242241
def sys_info(self) -> Iterable[tuple[str, Any]]:
243242
"""Get a list of information useful for debugging.
@@ -607,7 +606,7 @@ def code_region_kinds(self) -> Iterable[tuple[str, str]]:
607606
"""
608607
return []
609608

610-
def __eq__(self, other: Any) -> bool:
609+
def __eq__(self, other: object) -> bool:
611610
return isinstance(other, FileReporter) and self.filename == other.filename
612611

613612
def __lt__(self, other: Any) -> bool:

‎coverage/plugin_support.py‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,7 @@ def has_dynamic_source_filename(self) -> bool:
226226
def dynamic_source_filename(self, filename: str, frame: FrameType) -> str | None:
227227
dyn = self.tracer.dynamic_source_filename(filename, frame)
228228
self.debug.write(
229-
"dynamic_source_filename({!r}, {}) --> {!r}".format(
230-
filename,
231-
self._show_frame(frame),
232-
dyn,
233-
)
229+
f"dynamic_source_filename({filename!r}, {self._show_frame(frame)}) --> {dyn!r}"
234230
)
235231
return dyn
236232

‎coverage/pytracer.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,7 @@ def log(self, marker: str, *args: Any) -> None:
130130
f.write(f"{marker} {self.id}[{len(self.data_stack)}]")
131131
if 0: # if you want thread ids..
132132
f.write( # type: ignore[unreachable]
133-
".{:x}.{:x}".format(
134-
self.thread.ident,
135-
self.threading.current_thread().ident,
136-
)
133+
f".{self.thread.ident:x}.{self.threading.current_thread().ident:x}"
137134
)
138135
f.write(" {}".format(" ".join(map(str, args))))
139136
if 0: # if you want callers..

0 commit comments

Comments
 (0)