diff --git a/src/pact/v3/match/types.py b/src/pact/v3/match/types.py index 393f8ae220..90b06c9f15 100644 --- a/src/pact/v3/match/types.py +++ b/src/pact/v3/match/types.py @@ -2,9 +2,18 @@ Typing definitions for the matchers. """ -from typing import Any, TypeAlias +from typing import Any, TypeAlias, TypeVar + +# Make _MatchableT explicitly public, despite ultimately only being used +# privately. +__all__ = ["Matchable", "_MatchableT"] Matchable: TypeAlias = Any """ All supported matchable types. """ + +_MatchableT = TypeVar("_MatchableT") +""" +Matchable type variable. +""" diff --git a/src/pact/v3/match/types.pyi b/src/pact/v3/match/types.pyi index eefda39c63..e3fcd6dfd3 100644 --- a/src/pact/v3/match/types.pyi +++ b/src/pact/v3/match/types.pyi @@ -2,10 +2,14 @@ from collections.abc import Collection, Mapping, Sequence from collections.abc import Set as AbstractSet from decimal import Decimal from fractions import Fraction -from typing import TypeAlias +from typing import TypeAlias, TypeVar from pydantic import BaseModel +# Make _MatchableT explicitly public, despite ultimately only being used +# privately. +__all__ = ["Matchable", "_MatchableT"] + _BaseMatchable: TypeAlias = ( int | float | complex | bool | str | bytes | bytearray | memoryview | None ) @@ -34,3 +38,23 @@ Matchable: TypeAlias = _BaseMatchable | _ContainerMatchable | _ExtraMatchable """ All supported matchable types. """ + +_MatchableT = TypeVar( + "_MatchableT", + int, + float, + complex, + bool, + str, + bytes, + bytearray, + memoryview, + None, + Sequence[Matchable], + AbstractSet[Matchable], + Mapping[_BaseMatchable, Matchable], + Collection[Matchable], + BaseModel, + Decimal, + Fraction, +)