Skip to content

Commit 6289be8

Browse files
committed
refactor: use dataclasses, no namedtuple
1 parent 5a031b0 commit 6289be8

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

coverage/parser.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import token
1414
import tokenize
1515

16+
from dataclasses import dataclass
1617
from types import CodeType
1718
from typing import (
1819
cast, Any, Callable, Dict, Iterable, List, Optional, Protocol, Sequence,
@@ -462,7 +463,8 @@ def _find_statements(self) -> Iterable[TLineNo]:
462463
# AST analysis
463464
#
464465

465-
class ArcStart(collections.namedtuple("Arc", "lineno, cause")):
466+
@dataclass(frozen=True, order=True)
467+
class ArcStart:
466468
"""The information needed to start an arc.
467469
468470
`lineno` is the line number the arc starts from.
@@ -474,8 +476,8 @@ class ArcStart(collections.namedtuple("Arc", "lineno, cause")):
474476
to have `lineno` interpolated into it.
475477
476478
"""
477-
def __new__(cls, lineno: TLineNo, cause: str | None = None) -> ArcStart:
478-
return super().__new__(cls, lineno, cause)
479+
lineno: TLineNo
480+
cause: str = ""
479481

480482

481483
class TAddArcFn(Protocol):
@@ -1256,7 +1258,7 @@ def _combine_finally_starts(self, starts: set[ArcStart], exits: set[ArcStart]) -
12561258
"""
12571259
causes = []
12581260
for start in sorted(starts):
1259-
if start.cause is not None:
1261+
if start.cause:
12601262
causes.append(start.cause.format(lineno=start.lineno))
12611263
cause = " or ".join(causes)
12621264
exits = {ArcStart(xit.lineno, cause) for xit in exits}

coverage/sysmon.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from __future__ import annotations
77

8-
import dataclasses
98
import functools
109
import inspect
1110
import os
@@ -14,6 +13,7 @@
1413
import threading
1514
import traceback
1615

16+
from dataclasses import dataclass
1717
from types import CodeType, FrameType
1818
from typing import (
1919
Any,
@@ -151,7 +151,7 @@ def _decorator(meth: AnyCallable) -> AnyCallable:
151151
return _decorator
152152

153153

154-
@dataclasses.dataclass
154+
@dataclass
155155
class CodeInfo:
156156
"""The information we want about each code object."""
157157

lab/benchmark/benchmark.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import collections
44
import contextlib
5-
import dataclasses
65
import itertools
76
import os
87
import random
@@ -13,6 +12,7 @@
1312
import time
1413
from pathlib import Path
1514

15+
from dataclasses import dataclass
1616
from typing import Any, Dict, Iterable, Iterator, List, Optional, Tuple
1717

1818
import tabulate
@@ -480,7 +480,7 @@ def __init__(self, path, slug):
480480
self.toxenv = None
481481

482482

483-
@dataclasses.dataclass
483+
@dataclass
484484
class Coverage:
485485
"""A version of coverage.py to use, maybe None."""
486486

@@ -537,7 +537,7 @@ def __init__(self, directory, slug="source", tweaks=None, env_vars=None):
537537
)
538538

539539

540-
@dataclasses.dataclass
540+
@dataclass
541541
class Env:
542542
"""An environment to run a test suite in."""
543543

0 commit comments

Comments
 (0)