Skip to content

Commit

Permalink
fix(patterns): fix pattern creation from Any typehint on python 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
kszucs committed Sep 10, 2024
1 parent c7d5f6f commit 5a24ac9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion koerce/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions koerce/tests/test_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5a24ac9

Please sign in to comment.