Skip to content

Commit ee3bf45

Browse files
authoredAug 6, 2023
pythongh-106368: Improve coverage reports for argument clinic (python#107693)
1 parent 9564e31 commit ee3bf45

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed
 

‎.coveragerc

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ exclude_lines =
77
# Don't complain if non-runnable code isn't run:
88
if 0:
99
if __name__ == .__main__.:
10+
raise AssertionError\(
11+
12+
# Empty bodies in protocols or abstract methods
13+
^\s*def [a-zA-Z0-9_]+\(.*\)(\s*->.*)?:\s*\.\.\.(\s*#.*)?$
14+
^\s*\.\.\.(\s*#.*)?$
1015

1116
.*# pragma: no cover
1217
.*# pragma: no branch

‎Tools/clinic/clinic.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -469,18 +469,18 @@ class Language(metaclass=abc.ABCMeta):
469469
checksum_line = ""
470470

471471
def __init__(self, filename: str) -> None:
472-
pass
472+
...
473473

474474
@abc.abstractmethod
475475
def render(
476476
self,
477477
clinic: Clinic | None,
478478
signatures: Iterable[Module | Class | Function]
479479
) -> str:
480-
pass
480+
...
481481

482482
def parse_line(self, line: str) -> None:
483-
pass
483+
...
484484

485485
def validate(self) -> None:
486486
def assert_only_one(
@@ -2862,6 +2862,9 @@ def __getattr__(self, attr):
28622862
f"Note: accessing self.function inside converter_init is disallowed!"
28632863
)
28642864
return super().__getattr__(attr)
2865+
# this branch is just here for coverage reporting
2866+
else: # pragma: no cover
2867+
pass
28652868

28662869
def converter_init(self) -> None:
28672870
pass
@@ -3990,7 +3993,7 @@ def correct_name_for_self(
39903993
return "void *", "null"
39913994
if f.kind in (CLASS_METHOD, METHOD_NEW):
39923995
return "PyTypeObject *", "type"
3993-
raise RuntimeError("Unhandled type of function f: " + repr(f.kind))
3996+
raise AssertionError(f"Unhandled type of function f: {f.kind!r}")
39943997

39953998
def required_type_for_self_for_parser(
39963999
f: Function

‎Tools/clinic/cpp.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,17 @@ def pop_stack() -> TokenAndCondition:
178178
if self.verbose:
179179
print(self.status())
180180

181-
if __name__ == '__main__':
182-
for filename in sys.argv[1:]:
181+
182+
def _main(filenames: list[str] | None = None) -> None:
183+
filenames = filenames or sys.argv[1:]
184+
for filename in filenames:
183185
with open(filename) as f:
184186
cpp = Monitor(filename, verbose=True)
185187
print()
186188
print(filename)
187189
for line_number, line in enumerate(f.read().split('\n'), 1):
188190
cpp.writeline(line)
191+
192+
193+
if __name__ == '__main__':
194+
_main()

0 commit comments

Comments
 (0)