Skip to content

Commit

Permalink
refactor: don't test arcs, test branches
Browse files Browse the repository at this point in the history
This required some other changes:

- `with` statements jump back to the with when leaving, but that
  confuses the branches, so fix the arcs to hide that fact.
  • Loading branch information
nedbat committed Aug 26, 2024
1 parent 468aa22 commit 2afe04d
Show file tree
Hide file tree
Showing 19 changed files with 548 additions and 976 deletions.
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ upgrading your version of coverage.py.
Unreleased
----------

Nothing yet.
- Fewer things are considered branches now:

- Lambdas, comprehensions, and generator expressions are no longer marked as
missing branches if they don't complete execution.


.. scriv-start-here
Expand Down
17 changes: 13 additions & 4 deletions coverage/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
from coverage.exceptions import ConfigError
from coverage.pytracer import PyTracer
from coverage.sysmon import SysMonitor
from coverage.types import TFileDisposition, Tracer, TWarnFn
from coverage.types import (
TFileDisposition,
Tracer,
TWarnFn,
)


try:
Expand Down Expand Up @@ -45,7 +49,14 @@ class Core:
packed_arcs: bool
systrace: bool

def __init__(self, warn: TWarnFn, timid: bool, metacov: bool) -> None:
def __init__(self,
warn: TWarnFn,
timid: bool,
metacov: bool,
) -> None:
# Defaults
self.tracer_kwargs = {}

core_name: str | None
if timid:
core_name = "pytrace"
Expand Down Expand Up @@ -74,14 +85,12 @@ def __init__(self, warn: TWarnFn, timid: bool, metacov: bool) -> None:
self.systrace = False
elif core_name == "ctrace":
self.tracer_class = CTracer
self.tracer_kwargs = {}
self.file_disposition_class = CFileDisposition
self.supports_plugins = True
self.packed_arcs = True
self.systrace = True
elif core_name == "pytrace":
self.tracer_class = PyTracer
self.tracer_kwargs = {}
self.file_disposition_class = FileDisposition
self.supports_plugins = False
self.packed_arcs = False
Expand Down
13 changes: 0 additions & 13 deletions coverage/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,6 @@ class PYBEHAVIOR:
# 3.7 changed how functions with only docstrings are numbered.
docstring_only_function = (not PYPY) and (PYVERSION <= (3, 10))

# When a break/continue/return statement in a try block jumps to a finally
# block, does the finally jump back to the break/continue/return (pre-3.10)
# to do the work?
finally_jumps_back = (PYVERSION < (3, 10))

# CPython 3.11 now jumps to the decorator line again while executing
# the decorator.
trace_decorator_line_again = (CPYTHON and PYVERSION > (3, 11, 0, "alpha", 3, 0))

# CPython 3.9a1 made sys.argv[0] and other reported files absolute paths.
report_absolute_files = (
(CPYTHON or (PYPY and PYPYVERSION >= (7, 3, 10)))
Expand Down Expand Up @@ -112,10 +103,6 @@ class PYBEHAVIOR:
# only a 0-number line, which is ignored, giving a truly empty module.
empty_is_empty = (PYVERSION >= (3, 11, 0, "beta", 4))

# Are comprehensions inlined (new) or compiled as called functions (old)?
# Changed in https://github.com/python/cpython/pull/101441
comprehensions_are_functions = (PYVERSION <= (3, 12, 0, "alpha", 7, 0))

# PEP669 Low Impact Monitoring: https://peps.python.org/pep-0669/
pep669 = bool(getattr(sys, "monitoring", None))

Expand Down
4 changes: 2 additions & 2 deletions coverage/execfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,13 @@ def run_python_file(args: list[str]) -> None:

def make_code_from_py(filename: str) -> CodeType:
"""Get source from `filename` and make a code object of it."""
# Open the source file.
try:
source = get_python_source(filename)
except (OSError, NoSource) as exc:
raise NoSource(f"No file to run: '{filename}'") from exc

return compile(source, filename, "exec", dont_inherit=True)
code = compile(source, filename, mode="exec", dont_inherit=True)
return code


def make_code_from_pyc(filename: str) -> CodeType:
Expand Down
Loading

0 comments on commit 2afe04d

Please sign in to comment.