Skip to content
Open
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
10 changes: 9 additions & 1 deletion test/collection/test_validator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List
from typing import Any, List, Sequence, Union

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -28,6 +28,14 @@
False,
),
(pl.Series([1, 1]), [_ExtraTypes.PANDAS, _ExtraTypes.NUMPY, List], True),
# Tests for Sequence[Union[...]] pattern, which was flaky in Python 3.12
(["a", 1], [Sequence[Union[str, int]]], False),
([1, "a"], [Sequence[Union[str, int]]], False),
([1, 2], [Sequence[Union[str, int]]], False),
(["a", "b"], [Sequence[Union[str, int]]], False),
(["a", 1], [str, Sequence[Union[str, int]]], False), # matches Sequence[Union[str, int]]
# Non-sequence values are not valid Sequence types: int is not iterable
(42, [Sequence[Union[str, int]]], True),
],
)
def test_validator(inputs: Any, expected: List[Any], error: bool) -> None:
Expand Down
5 changes: 3 additions & 2 deletions weaviate/validator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Sequence as ABCSequence
from dataclasses import dataclass
from typing import Any, List, Sequence, Union, get_args, get_origin

Expand Down Expand Up @@ -48,9 +49,9 @@ def _is_valid(expected: Any, value: Any) -> bool:
args = get_args(expected)
return any(isinstance(value, arg) for arg in args)
if expected_origin is not None and (
issubclass(expected_origin, Sequence) or expected_origin is list
issubclass(expected_origin, ABCSequence) or expected_origin is list
):
if not isinstance(value, Sequence) and not isinstance(value, list):
if not isinstance(value, (ABCSequence, list)):
return False
args = get_args(expected)
if len(args) == 1:
Expand Down