diff --git a/src/slipcover/branch.py b/src/slipcover/branch.py index 60fce8b..02c9002 100644 --- a/src/slipcover/branch.py +++ b/src/slipcover/branch.py @@ -26,22 +26,18 @@ def __init__(self): pass def _mark_branch(self, from_line: int, to_line: int) -> List[ast.stmt]: + mark = ast.Assign([ast.Name(BRANCH_NAME, ast.Store())], + ast.Tuple([ast.Constant(from_line), ast.Constant(to_line)], ast.Load())) if sys.version_info[0:2] == (3,12): - mark = ast.Assign([ast.Name(BRANCH_NAME, ast.Store())], ast.Constant(0)) for node in ast.walk(mark): node.lineno = node.end_lineno = encode_branch(from_line, to_line) - + elif sys.version_info[0:2] == (3,11): + for node in ast.walk(mark): + node.lineno = 0 # we ignore line 0, so this avoids generating extra line probes else: - mark = ast.Assign([ast.Name(BRANCH_NAME, ast.Store())], - ast.Tuple([ast.Constant(from_line), ast.Constant(to_line)], ast.Load())) - - if sys.version_info[0:2] == (3,11): - for node in ast.walk(mark): - node.lineno = 0 # we ignore line 0, so this avoids generating extra line probes - else: - for node in ast.walk(mark): - node.lineno = from_line + for node in ast.walk(mark): + node.lineno = from_line return [mark] diff --git a/tests/test_branch.py b/tests/test_branch.py index 5d40f2c..15a25b1 100644 --- a/tests/test_branch.py +++ b/tests/test_branch.py @@ -31,10 +31,7 @@ def get_branches(code): elif const is not None: if inst.opname in ('STORE_NAME', 'STORE_GLOBAL') and inst.argval == br.BRANCH_NAME: - if PYTHON_VERSION >= (3,12) and br.is_branch(inst.positions.lineno): - branches.append(br.decode_branch(inst.positions.lineno)) - else: - branches.append(const) + branches.append(const) const = None @@ -50,16 +47,10 @@ def __init__(self): def visit_Assign(self, node: ast.Assign) -> ast.Assign: if node.targets and isinstance(node.targets[0], ast.Name) \ and node.targets[0].id == br.BRANCH_NAME: - if PYTHON_VERSION >= (3,12) and br.is_branch(node.lineno): - branch = br.decode_branch(node.lineno) - value = ast.Tuple([ast.Constant(branch[0]), ast.Constant(branch[1])], ast.Load()) - value.lineno, value.end_lineno = node.lineno, node.end_lineno - else: - value = node.value return ast.AugAssign( target=node.targets[0], op=ast.Add(), - value=ast.List(elts=[value], ctx=ast.Load()), + value=ast.List(elts=[node.value], ctx=ast.Load()), ctx=ast.Load()) return node