diff --git a/koerce/patterns.py b/koerce/patterns.py index bed45c1..3c5b1f3 100644 --- a/koerce/patterns.py +++ b/koerce/patterns.py @@ -2385,7 +2385,7 @@ def pattern( The constructed pattern. """ - if obj is Ellipsis: + if obj is Ellipsis or obj is Any: return _any elif isinstance(obj, Pattern): return obj diff --git a/koerce/tests/test_patterns.py b/koerce/tests/test_patterns.py index a9e8ac4..e4f021f 100644 --- a/koerce/tests/test_patterns.py +++ b/koerce/tests/test_patterns.py @@ -1434,6 +1434,12 @@ def test_pattern_from_typehint_with_coercion(annot, expected): assert Pattern.from_typehint(annot, allow_coercion=True) == expected +def test_pattern_from_annotated(): + p = Pattern.from_typehint(Annotated[Any, ...]) + assert p == AllOf(Anything(), Anything()) + assert pattern(Any) == Anything() + + @pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher") def test_pattern_from_typehint_uniontype(): # uniontype marks `type1 | type2` annotations and it's different from