Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excluded decorators in excluded branches leak into the outer indentation. #1632

Closed
HexDecimal opened this issue May 25, 2023 · 1 comment
Closed
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@HexDecimal
Copy link

HexDecimal commented May 25, 2023

Describe the bug
Coverage supports excluding coverage on branches and on function decorators. Alone these features work, but together they cause a leak of the exclusion into the outer indentation, excluding everything up to the next branch. See the minimal example.

To Reproduce

  • What version of Python are you using?

Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32

Python versions 3.8 and later tested with CI.

  • What version of coverage.py shows the problem? The output of coverage debug sys is helpful.

coverage_version: 7.2.6

  • What versions of what packages do you have installed? The output of pip freeze is helpful.
$ pip freeze
coverage==7.2.6
  • What code shows the problem? Give us a specific commit of a specific repo that we can check out. If you've already worked around the problem, please provide a commit before that fix.

Real example of affected code, the exclusion leaks to the entire class below:
https://github.com/HexDecimal/python-tcod-ecs/blob/cb0ad6a3b562ceb68a8596d6fd1564b2b3ca8de2/tcod/ecs/__init__.py#L248-L262
Issue visible in Codecov:
https://app.codecov.io/gh/HexDecimal/python-tcod-ecs/commit/cb0ad6a3b562ceb68a8596d6fd1564b2b3ca8de2/blob/tcod/ecs/__init__.py#L248

Minimal example:

# pyproject.toml
[tool.coverage.report]
exclude_lines = ["if TYPE_CHECKING:", "@overload"]  # Issue triggers only with both of these exclusions.
# sample.py
from typing import TYPE_CHECKING, overload

class Test:
    if TYPE_CHECKING:
        @overload
        def test() -> None:
            ...

if True:  # Branch excluded!
    pass

if True:  # Included
    pass

if TYPE_CHECKING:
    @overload
    def test() -> None:
        ...

if True:  # Branch excluded!
    pass

if True:  # Included
    pass
  • What commands should we run to reproduce the problem? Be specific. Include everything, even git clone, pip install, and so on. Explain like we're five!

With the above two files in the working directory:

coverage run sample.py
coverage html

Expected behavior
Excluded branches should overlap without covering areas outside of either.

Additional context
I can workaround this issue if I remove @overload from the excludes and exclude ... instead, this excludes everything I want:

[tool.coverage.report]
exclude_lines = ['^\s*\.\.\.', "if TYPE_CHECKING:"]
@HexDecimal HexDecimal added bug Something isn't working needs triage labels May 25, 2023
@kevin-brown
Copy link
Contributor

This issue is a duplicate of #1779 which was recently fixed in commit 96bd930.

@nedbat nedbat closed this as completed May 20, 2024
@nedbat nedbat added duplicate This issue or pull request already exists and removed needs triage labels May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants