From da33081795333dba2e98cdc1dba68de79d16f5df Mon Sep 17 00:00:00 2001 From: Lynn Root Date: Fri, 12 Apr 2024 22:44:40 -0400 Subject: [PATCH] Add type hints (finally) --- .github/workflows/main.yml | 4 ++++ src/interrogate/badge_gen.py | 4 +++- src/interrogate/cli.py | 6 +++--- src/interrogate/config.py | 3 ++- src/interrogate/visit.py | 8 +++++--- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c948b45..bd4e783 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -50,6 +50,10 @@ jobs: python -Im pip install --upgrade tox - name: Run tox targets for ${{ matrix.python-version }} run: python -Im tox run -f py$(echo ${{ matrix.python-version }} | tr -d .) + + - name: Run mypy + run: python -Im tox run -e mypy + if: matrix.python-version == '3.11' - name: Run mypy run: python -Im tox run -e mypy diff --git a/src/interrogate/badge_gen.py b/src/interrogate/badge_gen.py index 6b18518..21cf37a 100644 --- a/src/interrogate/badge_gen.py +++ b/src/interrogate/badge_gen.py @@ -8,6 +8,8 @@ import os import sys +from typing import Union + from importlib import resources from xml.dom import minidom @@ -20,7 +22,7 @@ from interrogate.coverage import InterrogateResults -NumberType = int | float +NumberType = Union[int, float] DEFAULT_FILENAME: str = "interrogate_badge" COLORS: dict[str, str] = { diff --git a/src/interrogate/cli.py b/src/interrogate/cli.py index 5306b4f..19f0997 100644 --- a/src/interrogate/cli.py +++ b/src/interrogate/cli.py @@ -5,7 +5,7 @@ import re import sys -from typing import List, Optional, Tuple, Union +from typing import List, Optional, Pattern, Tuple, Union import click import colorama @@ -330,9 +330,9 @@ def main( ignore_property_decorators: bool, ignore_setters: bool, ignore_semiprivate: bool, - ignore_regex: Optional[List[re.Pattern[str]]], + ignore_regex: Optional[List[Pattern[str]]], ext: Tuple[str], - whitelist_regex: Optional[List[re.Pattern[str]]], + whitelist_regex: Optional[List[Pattern[str]]], style: str, output: Optional[str], color: bool, diff --git a/src/interrogate/config.py b/src/interrogate/config.py index 6a9d71e..13dc0ac 100644 --- a/src/interrogate/config.py +++ b/src/interrogate/config.py @@ -11,7 +11,8 @@ import pathlib import re -from typing import Any, Sequence +from collections.abc import Sequence +from typing import Any import attr import click diff --git a/src/interrogate/visit.py b/src/interrogate/visit.py index fb48f12..e9aa906 100644 --- a/src/interrogate/visit.py +++ b/src/interrogate/visit.py @@ -5,14 +5,16 @@ import ast import os +from typing import Union + import attr from interrogate.config import InterrogateConfig -DocumentableFunc = ast.AsyncFunctionDef | ast.FunctionDef -DocumentableFuncOrClass = DocumentableFunc | ast.ClassDef -DocumentableNode = DocumentableFuncOrClass | ast.Module +DocumentableFunc = Union[ast.AsyncFunctionDef, ast.FunctionDef] +DocumentableFuncOrClass = Union[DocumentableFunc, ast.ClassDef] +DocumentableNode = Union[DocumentableFuncOrClass, ast.Module] @attr.s(eq=False)