Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/14606.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed ``list-item`` typing errors from mypy in :ref:`@pytest.mark.parametrize <pytest.mark.parametrize ref>` ``argvalues`` parameter.
26 changes: 5 additions & 21 deletions src/_pytest/mark/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import warnings

from .._code import getfslineno
from ..compat import deprecated
from ..compat import NOTSET
from ..compat import NotSetType
from _pytest.config import Config
Expand Down Expand Up @@ -537,31 +536,16 @@ def __call__(
) -> MarkDecorator: ...

class _ParametrizeMarkDecorator(MarkDecorator):
@overload # type: ignore[override,no-overload-impl]
def __call__(
self,
argnames: str | Sequence[str],
argvalues: Collection[ParameterSet | Sequence[object] | object],
*,
indirect: bool | Sequence[str] = ...,
ids: Iterable[None | str | float | int | bool | _HiddenParam]
| Callable[[Any], object | None]
| None = ...,
scope: ScopeName | None = ...,
) -> MarkDecorator: ...

@overload
@deprecated(
"Passing a non-Collection iterable to the 'argvalues' parameter of @pytest.mark.parametrize is deprecated. "
"Convert argvalues to a list or tuple.",
)
def __call__(
def __call__( # type: ignore[override]
self,
argnames: str | Sequence[str],
argvalues: Iterable[ParameterSet | Sequence[object] | object],
# TODO(pytest10): Change to below after PARAMETRIZE_NON_COLLECTION_ITERABLE deprecation.
# Overload doesn't work, see #14606.
# argvalues: Collection[ParameterSet | Sequence[object] | object],
*,
indirect: bool | Sequence[str] = ...,
ids: Iterable[None | str | float | int | bool]
ids: Iterable[None | str | float | int | bool | _HiddenParam]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_HiddenParam was missing on this overload

| Callable[[Any], object | None]
| None = ...,
scope: ScopeName | None = ...,
Expand Down
13 changes: 6 additions & 7 deletions testing/typing_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,14 @@ def test_hidden_param(x: int) -> None:
pass


# Test @pytest.mark.parametrize iterator argvalues deprecation.
# Will be complain about unused type ignore if doesn't work.
@pytest.mark.parametrize("x", iter(range(10))) # type: ignore[deprecated]
def test_it(x: int) -> None:
pass


# Issue #14137.
def check_scope_typing() -> None:

custom_scope: ScopeName = "function"
assert_type(custom_scope, ScopeName)


# Issue #14606.
@pytest.mark.parametrize("x", [ImportError, AttributeError])
def check_mypy_bug_with_argvalues(x) -> None:
pass
Loading