Skip to content

Type hints #143

@adamchainz

Description

@adamchainz

I've been rolling out Mypy on a client project. When activating the disallow_untyped_decorators flag, I found I needed type hints for parametrized. I added the below to the project's stubs folder (on mypy_path:

from __future__ import annotations

from collections.abc import Callable, Iterable, Sequence
from typing import Any, ParamSpec, TypeVar
from unittest import TestCase

P = ParamSpec("P")
T = TypeVar("T")

class param:
    def __init__(self, *args: Any, **kwargs: Any) -> None: ...

InputType = (
    Iterable[str] | Iterable[Sequence[Any]] | Iterable[dict[str, Any]] | Iterable[param]
)

class parameterized:
    def __init__(
        self,
        input: InputType,
        doc_func: Callable[[Callable[..., Any], int, param], str] | None = None,
        skip_on_empty: bool = False,
    ): ...
    def __call__(self, test_func: Callable[P, T]) -> Callable[P, T]: ...
    @classmethod
    def expand(
        cls,
        input: InputType,
        name_func: Callable[[Callable[..., Any], int, param], str] | None = None,
        skip_on_empty: bool = False,
        **legacy: Any,
    ) -> Callable[[Callable[P, T]], Callable[P, T]]: ...

_TestCaseClass = TypeVar("_TestCaseClass", bound=type[TestCase])

def parameterized_class(input: Any) -> Callable[[_TestCaseClass], _TestCaseClass]: ...

These hints cover the main usage of parameterized. If you're interested, I wouldn't mind contributing full type hint coverage to the package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions