Skip to content

Commit 2f33caf

Browse files
committed
feat: add matchable typevar
This is the TypeVar equivalent of the Matchable union type. Signed-off-by: JP-Ellis <[email protected]>
1 parent 0dfc73c commit 2f33caf

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/pact/v3/match/types.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@
22
Typing definitions for the matchers.
33
"""
44

5-
from typing import Any, TypeAlias
5+
from typing import Any, TypeAlias, TypeVar
6+
7+
# Make _MatchableT explicitly public, despite ultimately only being used
8+
# privately.
9+
__all__ = ["Matchable", "_MatchableT"]
610

711
Matchable: TypeAlias = Any
812
"""
913
All supported matchable types.
1014
"""
15+
16+
_MatchableT = TypeVar("_MatchableT")
17+
"""
18+
Matchable type variable.
19+
"""

src/pact/v3/match/types.pyi

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ from collections.abc import Collection, Mapping, Sequence
22
from collections.abc import Set as AbstractSet
33
from decimal import Decimal
44
from fractions import Fraction
5-
from typing import TypeAlias
5+
from typing import TypeAlias, TypeVar
66

77
from pydantic import BaseModel
88

9+
# Make _MatchableT explicitly public, despite ultimately only being used
10+
# privately.
11+
__all__ = ["Matchable", "_MatchableT"]
12+
913
_BaseMatchable: TypeAlias = (
1014
int | float | complex | bool | str | bytes | bytearray | memoryview | None
1115
)
@@ -34,3 +38,23 @@ Matchable: TypeAlias = _BaseMatchable | _ContainerMatchable | _ExtraMatchable
3438
"""
3539
All supported matchable types.
3640
"""
41+
42+
_MatchableT = TypeVar(
43+
"_MatchableT",
44+
int,
45+
float,
46+
complex,
47+
bool,
48+
str,
49+
bytes,
50+
bytearray,
51+
memoryview,
52+
None,
53+
Sequence[Matchable],
54+
AbstractSet[Matchable],
55+
Mapping[_BaseMatchable, Matchable],
56+
Collection[Matchable],
57+
BaseModel,
58+
Decimal,
59+
Fraction,
60+
)

0 commit comments

Comments
 (0)