Repository: numpy/numpy
File: tools/pyright_completeness.py (Python)

Code before:
import subprocess
import sys
from collections.abc import Sequence


def main(argv: Sequence[str] | None = None) -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--exclude-like",
        required=False,
        nargs="*",
        type=str,
        help="Exclude symbols whose names matches this glob pattern",
    )
    args, unknownargs = parser.parse_known_args(argv)
    pyright_args = list(unknownargs)
    if "--outputjson" not in pyright_args:
        pyright_args.append("--outputjson")
    return run_pyright_with_coverage(pyright_args, args.exclude_like)


def run_pyright_with_coverage(
    pyright_args: list[str],
    exclude_like: Sequence[str],
) -> int:
    result = subprocess.run(["pyright", *pyright_args], capture_output=True, text=True)

    try:
        data = json.loads(result.stdout)
    except json.decoder.JSONDecodeError:
        sys.stdout.write(result.stdout)
        sys.stderr.write(result.stderr)
        return 1

    if exclude_like:
        symbols = data["typeCompleteness"]["symbols"]
        matched_symbols = [
            x
            for x in symbols
            if not any(fnmatch.fnmatch(x["name"], pattern) for pattern in exclude_like)
            and x["isExported"]
        ]
        cov_percent = (
            sum(x["isTypeKnown"] for x in matched_symbols) / len(matched_symbols) * 100
        )
    else:
        cov_percent = data["typeCompleteness"]["completenessScore"] * 100

    sys.stderr.write(result.stderr)
    if cov_percent < 100:
        sys.stdout.write(

Review comment (suggestion):
see above

```suggestion
    result = subprocess.run(
        ["basedpyright", *pyright_args],
        capture_output=True,
        text=True,
    )
```

Code after:
import json
import subprocess
import sys
from collections.abc import Sequence


def main(argv: Sequence[str] | None = None) -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--exclude-like",
        required=False,
        nargs="*",
        type=str,
        help="Exclude symbols whose names matches this glob pattern",
    )
    args, unknownargs = parser.parse_known_args(argv)
    pyright_args = list(unknownargs)
    if "--outputjson" not in pyright_args:
        pyright_args.append("--outputjson")
    return run_pyright_with_coverage(pyright_args, args.exclude_like)


def run_pyright_with_coverage(
    pyright_args: list[str],
    exclude_like: Sequence[str],
) -> int:
    result = subprocess.run(
        ["pyright", *pyright_args], capture_output=True, text=True
    )

    try:
        data = json.loads(result.stdout)
    except json.decoder.JSONDecodeError:
        sys.stdout.write(result.stdout)
        sys.stderr.write(result.stderr)
        return 1

    if exclude_like:
        symbols = data["typeCompleteness"]["symbols"]
        matched_symbols = [
            x
            for x in symbols
            if not any(fnmatch.fnmatch(x["name"], pattern) for pattern in exclude_like)
            and x["isExported"]
        ]
        covered = sum(x["isTypeKnown"] for x in matched_symbols) / len(matched_symbols)
    else:
        covered = data["typeCompleteness"]["completenessScore"]
    sys.stderr.write(result.stderr)
    if covered < 1:
        sys.stdout.write(f"Coverage {covered:.1%} is below minimum required 100%\n")