Skip to content

Commit c2f3588

Browse files
committed
refactor: convenient names for oft-mentioned function arguments
1 parent f5951d8 commit c2f3588

File tree

5 files changed

+40
-15
lines changed

5 files changed

+40
-15
lines changed

coverage/collector.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,15 @@
2424
from coverage.misc import human_sorted_items, isolate_module
2525
from coverage.plugin import CoveragePlugin
2626
from coverage.types import (
27-
TArc, TFileDisposition, TTraceData, TTraceFn, Tracer, TWarnFn,
27+
TArc,
28+
TCheckIncludeFn,
29+
TFileDisposition,
30+
TShouldStartContextFn,
31+
TShouldTraceFn,
32+
TTraceData,
33+
TTraceFn,
34+
Tracer,
35+
TWarnFn,
2836
)
2937

3038
os = isolate_module(os)
@@ -60,9 +68,9 @@ class Collector:
6068
def __init__(
6169
self,
6270
core: Core,
63-
should_trace: Callable[[str, FrameType], TFileDisposition],
64-
check_include: Callable[[str, FrameType], bool],
65-
should_start_context: Callable[[FrameType], str | None] | None,
71+
should_trace: TShouldTraceFn,
72+
check_include: TCheckIncludeFn,
73+
should_start_context: TShouldStartContextFn | None,
6674
file_mapper: Callable[[str], str],
6775
branch: bool,
6876
warn: TWarnFn,

coverage/context.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
from __future__ import annotations
77

88
from types import FrameType
9-
from typing import cast, Callable, Sequence
9+
from typing import cast, Sequence
10+
11+
from coverage.types import TShouldStartContextFn
1012

1113

1214
def combine_context_switchers(
13-
context_switchers: Sequence[Callable[[FrameType], str | None]],
14-
) -> Callable[[FrameType], str | None] | None:
15+
context_switchers: Sequence[TShouldStartContextFn],
16+
) -> TShouldStartContextFn | None:
1517
"""Create a single context switcher from multiple switchers.
1618
1719
`context_switchers` is a list of functions that take a frame as an

coverage/pytracer.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,16 @@
1616

1717
from coverage import env
1818
from coverage.types import (
19-
TArc, TFileDisposition, TLineNo, TTraceData, TTraceFileData, TTraceFn,
20-
Tracer, TWarnFn,
19+
TArc,
20+
TFileDisposition,
21+
TLineNo,
22+
TShouldStartContextFn,
23+
TShouldTraceFn,
24+
TTraceData,
25+
TTraceFileData,
26+
TTraceFn,
27+
TWarnFn,
28+
Tracer,
2129
)
2230

2331
# We need the YIELD_VALUE opcode below, in a comparison-friendly form.
@@ -64,9 +72,9 @@ def __init__(self) -> None:
6472
# Attributes set from the collector:
6573
self.data: TTraceData
6674
self.trace_arcs = False
67-
self.should_trace: Callable[[str, FrameType], TFileDisposition]
75+
self.should_trace: TShouldTraceFn
6876
self.should_trace_cache: dict[str, TFileDisposition | None]
69-
self.should_start_context: Callable[[FrameType], str | None] | None = None
77+
self.should_start_context: TShouldStartContextFn | None = None
7078
self.switch_context: Callable[[str | None], None] | None = None
7179
self.lock_data: Callable[[], None]
7280
self.unlock_data: Callable[[], None]

coverage/sysmon.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
TArc,
3030
TFileDisposition,
3131
TLineNo,
32+
TShouldStartContextFn,
33+
TShouldTraceFn,
3234
TTraceData,
3335
TTraceFileData,
3436
Tracer,
@@ -180,11 +182,11 @@ def __init__(self, tool_id: int) -> None:
180182
# Attributes set from the collector:
181183
self.data: TTraceData
182184
self.trace_arcs = False
183-
self.should_trace: Callable[[str, FrameType], TFileDisposition]
185+
self.should_trace: TShouldTraceFn
184186
self.should_trace_cache: dict[str, TFileDisposition | None]
185187
# TODO: should_start_context and switch_context are unused!
186188
# Change tests/testenv.py:DYN_CONTEXTS when this is updated.
187-
self.should_start_context: Callable[[FrameType], str | None] | None = None
189+
self.should_start_context: TShouldStartContextFn | None = None
188190
self.switch_context: Callable[[str | None], None] | None = None
189191
self.lock_data: Callable[[], None]
190192
self.unlock_data: Callable[[], None]

coverage/types.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,19 @@ class TFileDisposition(Protocol):
7878

7979
TTraceData = Dict[str, TTraceFileData]
8080

81+
# Functions passed into collectors.
82+
TShouldTraceFn = Callable[[str, FrameType], TFileDisposition]
83+
TCheckIncludeFn = Callable[[str, FrameType], bool]
84+
TShouldStartContextFn = Callable[[FrameType], Union[str, None]]
85+
8186
class Tracer(Protocol):
8287
"""Anything that can report on Python execution."""
8388

8489
data: TTraceData
8590
trace_arcs: bool
86-
should_trace: Callable[[str, FrameType], TFileDisposition]
91+
should_trace: TShouldTraceFn
8792
should_trace_cache: Mapping[str, TFileDisposition | None]
88-
should_start_context: Callable[[FrameType], str | None] | None
93+
should_start_context: TShouldStartContextFn | None
8994
switch_context: Callable[[str | None], None] | None
9095
lock_data: Callable[[], None]
9196
unlock_data: Callable[[], None]

0 commit comments

Comments
 (0)