From cc0b41a99498f76a8e15f3ece70ee8dd52bd4a9d Mon Sep 17 00:00:00 2001 From: Rob Percival Date: Fri, 10 Nov 2023 17:53:03 +0000 Subject: [PATCH] Fix type hints for `unittest.util.unorderable_list_difference()` (#11012) Fix type hints for unorderable_list_difference() It claimed that the arguments were `Sequence` types (immutable), but the function removes elements from them, so they must be `MutableSequence` types. Specifically, it calls `pop()` on the first argument and `remove()` on the second argument. See the function implementation for details: https://github.com/python/cpython/blame/0b06d2482d77e02c5d40e221f6046c9c355458b2/Lib/unittest/util.py#L98-L113 --- stdlib/unittest/util.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/unittest/util.pyi b/stdlib/unittest/util.pyi index 845accfeb..c42d1346e 100644 --- a/stdlib/unittest/util.pyi +++ b/stdlib/unittest/util.pyi @@ -1,4 +1,4 @@ -from collections.abc import Sequence +from collections.abc import MutableSequence, Sequence from typing import Any, TypeVar from typing_extensions import TypeAlias @@ -17,7 +17,7 @@ def _common_shorten_repr(*args: str) -> tuple[str, ...]: ... def safe_repr(obj: object, short: bool = False) -> str: ... def strclass(cls: type) -> str: ... def sorted_list_difference(expected: Sequence[_T], actual: Sequence[_T]) -> tuple[list[_T], list[_T]]: ... -def unorderable_list_difference(expected: Sequence[_T], actual: Sequence[_T]) -> tuple[list[_T], list[_T]]: ... +def unorderable_list_difference(expected: MutableSequence[_T], actual: MutableSequence[_T]) -> tuple[list[_T], list[_T]]: ... def three_way_cmp(x: Any, y: Any) -> int: ... def _count_diff_all_purpose(actual: Sequence[_T], expected: Sequence[_T]) -> list[_Mismatch[_T]]: ... def _count_diff_hashable(actual: Sequence[_T], expected: Sequence[_T]) -> list[_Mismatch[_T]]: ...