Skip to content

Commit 24f8bfd

Browse files
committed
chore!: rename abstract generator
Make clear it is abstract by naming it `AbstractGenerator`. BREAKING CHANGE: The abstract `pact.generate.Generator` class has been renamed to `pact.generate.AbstractGenerator`. Signed-off-by: JP-Ellis <[email protected]>
1 parent 6d00c3c commit 24f8bfd

File tree

4 files changed

+46
-71
lines changed

4 files changed

+46
-71
lines changed

src/pact/generate/__init__.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393

9494
from pact._util import strftime_to_simple_date_format
9595
from pact.generate.generator import (
96-
Generator,
96+
AbstractGenerator,
9797
GenericGenerator,
9898
)
9999

@@ -116,7 +116,7 @@
116116
#
117117
# <https://github.com/pact-foundation/pact-reference/blob/303073c/rust/pact_models/src/generators/mod.rs#L121>
118118
__all__ = [
119-
"Generator",
119+
"AbstractGenerator",
120120
"bool",
121121
"boolean",
122122
"date",
@@ -172,7 +172,7 @@ def int(
172172
*,
173173
min: builtins.int | None = None,
174174
max: builtins.int | None = None,
175-
) -> Generator:
175+
) -> AbstractGenerator:
176176
"""
177177
Generate a random integer.
178178
@@ -198,7 +198,7 @@ def integer(
198198
*,
199199
min: builtins.int | None = None,
200200
max: builtins.int | None = None,
201-
) -> Generator:
201+
) -> AbstractGenerator:
202202
"""
203203
Alias for [`generate.int`][pact.generate.int].
204204
@@ -215,7 +215,7 @@ def integer(
215215
return int(min=min, max=max)
216216

217217

218-
def float(precision: builtins.int | None = None) -> Generator:
218+
def float(precision: builtins.int | None = None) -> AbstractGenerator:
219219
"""
220220
Generate a random decimal number.
221221
@@ -235,7 +235,7 @@ def float(precision: builtins.int | None = None) -> Generator:
235235
return GenericGenerator("RandomDecimal", extra_fields=params)
236236

237237

238-
def decimal(precision: builtins.int | None = None) -> Generator:
238+
def decimal(precision: builtins.int | None = None) -> AbstractGenerator:
239239
"""
240240
Alias for [`generate.float`][pact.generate.float].
241241
@@ -249,7 +249,7 @@ def decimal(precision: builtins.int | None = None) -> Generator:
249249
return float(precision=precision)
250250

251251

252-
def hex(digits: builtins.int | None = None) -> Generator:
252+
def hex(digits: builtins.int | None = None) -> AbstractGenerator:
253253
"""
254254
Generate a random hexadecimal value.
255255
@@ -266,7 +266,7 @@ def hex(digits: builtins.int | None = None) -> Generator:
266266
return GenericGenerator("RandomHexadecimal", extra_fields=params)
267267

268268

269-
def hexadecimal(digits: builtins.int | None = None) -> Generator:
269+
def hexadecimal(digits: builtins.int | None = None) -> AbstractGenerator:
270270
"""
271271
Alias for [`generate.hex`][pact.generate.hex].
272272
@@ -280,7 +280,7 @@ def hexadecimal(digits: builtins.int | None = None) -> Generator:
280280
return hex(digits=digits)
281281

282282

283-
def str(size: builtins.int | None = None) -> Generator:
283+
def str(size: builtins.int | None = None) -> AbstractGenerator:
284284
"""
285285
Generate a random string.
286286
@@ -297,7 +297,7 @@ def str(size: builtins.int | None = None) -> Generator:
297297
return GenericGenerator("RandomString", extra_fields=params)
298298

299299

300-
def string(size: builtins.int | None = None) -> Generator:
300+
def string(size: builtins.int | None = None) -> AbstractGenerator:
301301
"""
302302
Alias for [`generate.str`][pact.generate.str].
303303
@@ -311,7 +311,7 @@ def string(size: builtins.int | None = None) -> Generator:
311311
return str(size=size)
312312

313313

314-
def regex(regex: builtins.str) -> Generator:
314+
def regex(regex: builtins.str) -> AbstractGenerator:
315315
"""
316316
Generate a string matching a regex pattern.
317317
@@ -336,7 +336,7 @@ def regex(regex: builtins.str) -> Generator:
336336

337337
def uuid(
338338
format: _UUID_FORMAT_NAMES = "lowercase",
339-
) -> Generator:
339+
) -> AbstractGenerator:
340340
"""
341341
Generate a UUID.
342342
@@ -354,7 +354,7 @@ def date(
354354
format: builtins.str = "%Y-%m-%d",
355355
*,
356356
disable_conversion: builtins.bool = False,
357-
) -> Generator:
357+
) -> AbstractGenerator:
358358
"""
359359
Generate a date value.
360360
@@ -384,7 +384,7 @@ def time(
384384
format: builtins.str = "%H:%M:%S",
385385
*,
386386
disable_conversion: builtins.bool = False,
387-
) -> Generator:
387+
) -> AbstractGenerator:
388388
"""
389389
Generate a time value.
390390
@@ -413,7 +413,7 @@ def datetime(
413413
format: builtins.str,
414414
*,
415415
disable_conversion: builtins.bool = False,
416-
) -> Generator:
416+
) -> AbstractGenerator:
417417
"""
418418
Generate a datetime value.
419419
@@ -444,7 +444,7 @@ def timestamp(
444444
format: builtins.str,
445445
*,
446446
disable_conversion: builtins.bool = False,
447-
) -> Generator:
447+
) -> AbstractGenerator:
448448
"""
449449
Alias for [`generate.datetime`][pact.generate.datetime].
450450
@@ -454,7 +454,7 @@ def timestamp(
454454
return datetime(format=format, disable_conversion=disable_conversion)
455455

456456

457-
def bool() -> Generator:
457+
def bool() -> AbstractGenerator:
458458
"""
459459
Generate a random boolean value.
460460
@@ -464,7 +464,7 @@ def bool() -> Generator:
464464
return GenericGenerator("RandomBoolean")
465465

466466

467-
def boolean() -> Generator:
467+
def boolean() -> AbstractGenerator:
468468
"""
469469
Alias for [`generate.bool`][pact.generate.bool].
470470
@@ -474,7 +474,7 @@ def boolean() -> Generator:
474474
return bool()
475475

476476

477-
def provider_state(expression: builtins.str | None = None) -> Generator:
477+
def provider_state(expression: builtins.str | None = None) -> AbstractGenerator:
478478
"""
479479
Generate a value from provider state context.
480480
@@ -494,7 +494,7 @@ def provider_state(expression: builtins.str | None = None) -> Generator:
494494
def mock_server_url(
495495
regex: builtins.str | None = None,
496496
example: builtins.str | None = None,
497-
) -> Generator:
497+
) -> AbstractGenerator:
498498
"""
499499
Generate a mock server URL.
500500

src/pact/generate/generator.py

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from pact.types import GeneratorType
1515

1616

17-
class Generator(ABC):
17+
class AbstractGenerator(ABC):
1818
"""
1919
Abstract generator.
2020
@@ -34,17 +34,11 @@ class Generator(ABC):
3434
@abstractmethod
3535
def to_integration_json(self) -> dict[str, Any]:
3636
"""
37-
Convert the matcher to an integration JSON object.
37+
Convert the generator to an integration JSON object.
3838
39-
This method is used internally to convert the matcher to a JSON object
40-
which can be embedded directly in a number of places in the Pact FFI.
41-
42-
For more information about this format, see the docs:
43-
44-
> https://docs.pact.io/implementation_guides/rust/pact_ffi/integrationjson
45-
46-
Returns:
47-
The matcher as an integration JSON object.
39+
See
40+
[`AbstractGenerator.to_integration_json`][pact.generate.generator.AbstractGenerator.to_integration_json]
41+
for more information.
4842
"""
4943

5044
@abstractmethod
@@ -55,20 +49,17 @@ def to_generator_json(self) -> dict[str, Any]:
5549
This method is used internally to convert the generator to a JSON object
5650
which can be embedded directly in a number of places in the Pact FFI.
5751
58-
For more information about this format, see the docs:
59-
60-
> https://github.com/pact-foundation/pact-specification/tree/version-4
61-
62-
and
63-
64-
> https://github.com/pact-foundation/pact-specification/tree/version-2?tab=readme-ov-file#matchers
52+
For more information about this format, refer to the [Pact
53+
specification](https://github.com/pact-foundation/pact-specification/tree/version-4)
54+
and the [matchers
55+
section](https://github.com/pact-foundation/pact-specification/tree/version-2?tab=readme-ov-file#matchers)
6556
6657
Returns:
6758
The generator as a generator JSON object.
6859
"""
6960

7061

71-
class GenericGenerator(Generator):
62+
class GenericGenerator(AbstractGenerator):
7263
"""
7364
Generic generator.
7465
@@ -108,17 +99,11 @@ def __init__(
10899

109100
def to_integration_json(self) -> dict[str, Any]:
110101
"""
111-
Convert the matcher to an integration JSON object.
112-
113-
This method is used internally to convert the matcher to a JSON object
114-
which can be embedded directly in a number of places in the Pact FFI.
115-
116-
For more information about this format, see the docs:
102+
Convert the generator to an integration JSON object.
117103
118-
> https://docs.pact.io/implementation_guides/rust/pact_ffi/integrationjson
119-
120-
Returns:
121-
The matcher as an integration JSON object.
104+
See
105+
[`AbstractGenerator.to_integration_json`][pact.generate.generator.AbstractGenerator.to_integration_json]
106+
for more information.
122107
"""
123108
return {
124109
"pact:generator:type": self.type,
@@ -129,19 +114,9 @@ def to_generator_json(self) -> dict[str, Any]:
129114
"""
130115
Convert the generator to a generator JSON object.
131116
132-
This method is used internally to convert the generator to a JSON object
133-
which can be embedded directly in a number of places in the Pact FFI.
134-
135-
For more information about this format, see the docs:
136-
137-
> https://github.com/pact-foundation/pact-specification/tree/version-4
138-
139-
and
140-
141-
> https://github.com/pact-foundation/pact-specification/tree/version-2?tab=readme-ov-file#matchers
142-
143-
Returns:
144-
The generator as a generator JSON object.
117+
See
118+
[`AbstractGenerator.to_generator_json`][pact.generate.generator.AbstractGenerator.to_generator_json]
119+
for more information.
145120
"""
146121
return {
147122
"type": self.type,

src/pact/match/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@
261261
from collections.abc import Mapping, Sequence
262262
from types import ModuleType
263263

264-
from pact.generate import Generator
264+
from pact.generate import AbstractGenerator
265265

266266
# ruff: noqa: A001
267267
# We provide a more 'Pythonic' interface by matching the names of the
@@ -541,7 +541,7 @@ def str(
541541
/,
542542
*,
543543
size: builtins.int | None = None,
544-
generator: Generator | None = None,
544+
generator: AbstractGenerator | None = None,
545545
) -> AbstractMatcher[builtins.str]:
546546
"""
547547
Match a string value, optionally with a specific length.
@@ -587,7 +587,7 @@ def string(
587587
/,
588588
*,
589589
size: builtins.int | None = None,
590-
generator: Generator | None = None,
590+
generator: AbstractGenerator | None = None,
591591
) -> AbstractMatcher[builtins.str]:
592592
"""
593593
Alias for [`match.str`][pact.match.str].
@@ -938,7 +938,7 @@ def type(
938938
*,
939939
min: builtins.int | None = None,
940940
max: builtins.int | None = None,
941-
generator: Generator | None = None,
941+
generator: AbstractGenerator | None = None,
942942
) -> AbstractMatcher[_T]:
943943
"""
944944
Match a value by type (primitive or complex).
@@ -973,7 +973,7 @@ def like(
973973
*,
974974
min: builtins.int | None = None,
975975
max: builtins.int | None = None,
976-
generator: Generator | None = None,
976+
generator: AbstractGenerator | None = None,
977977
) -> AbstractMatcher[_T]:
978978
"""
979979
Alias for [`match.type`][pact.match.type].
@@ -1016,7 +1016,7 @@ def includes(
10161016
value: builtins.str,
10171017
/,
10181018
*,
1019-
generator: Generator | None = None,
1019+
generator: AbstractGenerator | None = None,
10201020
) -> AbstractMatcher[builtins.str]:
10211021
"""
10221022
Match a string that includes a given value.

src/pact/match/matcher.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from json import JSONEncoder
1616
from typing import Any, Generic, TypeVar
1717

18-
from pact.generate.generator import Generator
18+
from pact.generate.generator import AbstractGenerator
1919
from pact.types import UNSET, Matchable, MatcherType, Unset
2020

2121
_T_co = TypeVar("_T_co", covariant=True)
@@ -85,7 +85,7 @@ def __init__(
8585
type: MatcherType, # noqa: A002
8686
/,
8787
value: _T_co | Unset = UNSET,
88-
generator: Generator | None = None,
88+
generator: AbstractGenerator | None = None,
8989
extra_fields: Mapping[str, Any] | None = None,
9090
**kwargs: Matchable,
9191
) -> None:
@@ -359,6 +359,6 @@ def default(self, o: Any) -> Any: # noqa: ANN401
359359
"""
360360
if isinstance(o, AbstractMatcher):
361361
return o.to_integration_json()
362-
if isinstance(o, Generator):
362+
if isinstance(o, AbstractGenerator):
363363
return o.to_integration_json()
364364
return super().default(o)

0 commit comments

Comments
 (0)