Skip to content

Commit

Permalink
guess it did not trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
FBruzzesi committed Sep 15, 2024
1 parent b476f44 commit ec547ff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
10 changes: 6 additions & 4 deletions dirty_equals/_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ class IsListOrTuple(DirtyEquals[T]):
Check that some object is a list or tuple and optionally its values match some constraints.
"""

allowed_type: Union[Type[T], Tuple[Type[List[Any]], Type[Tuple[Any, ...]]]] = (list, tuple)
allowed_type: Union[
Tuple[Type[List[Any]]], Tuple[Type[Tuple[Any, ...]]], Tuple[Type[List[Any]], Type[Tuple[Any, ...]]]
] = (list, tuple)

@overload
def __init__(self, *items: Any, check_order: bool = True, length: 'LengthType' = None): ...
Expand Down Expand Up @@ -159,7 +161,7 @@ def __init__(
f'Instantiating `{self.__class__.__name__}` without any argument is ambiguous.\n'
f'- For an empty {allowed_type_names}, please specify {self.__class__.__name__}(length=0)\n'
f'- For a {allowed_type_names} of any given length, please specify {self.__class__.__name__}(length=...)'
)
)
raise TypeError(msg)

if positions is not None:
Expand Down Expand Up @@ -235,7 +237,7 @@ class IsList(IsListOrTuple[List[Any]]):
```
"""

allowed_type = (list, )
allowed_type = (list,)


class IsTuple(IsListOrTuple[Tuple[Any, ...]]):
Expand All @@ -256,7 +258,7 @@ class IsTuple(IsListOrTuple[Tuple[Any, ...]]):
```
"""

allowed_type = (tuple, )
allowed_type = (tuple,)


def _length_repr(length: 'LengthType') -> Any:
Expand Down
19 changes: 8 additions & 11 deletions tests/test_list_tuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,28 +99,25 @@ def test_wrong_length_length():
with pytest.raises(TypeError, match='length must be a tuple of length 2, not 3'):
IsList(1, 2, length=(1, 2, 3))


@pytest.mark.parametrize(
'dirty,allowed_type_names', [
(IsList, 'list'),
(IsTuple, 'tuple'),
(IsListOrTuple, 'list or tuple'),
]
'dirty,allowed_type_names',
[
(IsList, 'list'),
(IsTuple, 'tuple'),
(IsListOrTuple, 'list or tuple'),
],
)
def test_no_args(dirty: type, allowed_type_names: str):

err_msg = re.escape(
rf'Instantiating `{dirty.__name__}` without any argument is ambiguous.' + '\n'
rf'- For an empty {allowed_type_names}, please specify {dirty.__name__}(length=0)' + '\n'
rf'- For a {allowed_type_names} of any given length, please specify {dirty.__name__}(length=...)'
)
with pytest.raises(
TypeError,
match=err_msg
):
with pytest.raises(TypeError, match=err_msg):
dirty()



@pytest.mark.parametrize(
'dirty,repr_str',
[
Expand Down

0 comments on commit ec547ff

Please sign in to comment.