Skip to content

Commit 5a24ac9

Browse files
committed
fix(patterns): fix pattern creation from Any typehint on python 3.10
1 parent c7d5f6f commit 5a24ac9

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

koerce/patterns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2385,7 +2385,7 @@ def pattern(
23852385
The constructed pattern.
23862386
23872387
"""
2388-
if obj is Ellipsis:
2388+
if obj is Ellipsis or obj is Any:
23892389
return _any
23902390
elif isinstance(obj, Pattern):
23912391
return obj

koerce/tests/test_patterns.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,12 @@ def test_pattern_from_typehint_with_coercion(annot, expected):
14341434
assert Pattern.from_typehint(annot, allow_coercion=True) == expected
14351435

14361436

1437+
def test_pattern_from_annotated():
1438+
p = Pattern.from_typehint(Annotated[Any, ...])
1439+
assert p == AllOf(Anything(), Anything())
1440+
assert pattern(Any) == Anything()
1441+
1442+
14371443
@pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher")
14381444
def test_pattern_from_typehint_uniontype():
14391445
# uniontype marks `type1 | type2` annotations and it's different from

0 commit comments

Comments
 (0)