Skip to content

Commit 12d21fc

Browse files
authored
Fix missing Python parameter type defaults (#259)
1 parent 8719afe commit 12d21fc

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1313

1414
### Fixed
1515
- Removed repeated 'the' from error message for use of alternations inside optionals ([#252](https://github.com/cucumber/cucumber-expressions/issues/252))
16+
- [Python] Missing keyword argument defaults in parameter type class ([#259](https://github.com/cucumber/cucumber-expressions/pull/259))
1617

1718
## [17.0.1] - 2023-11-24
1819
### Fixed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ Then this expression would match the following example:
224224
I have 1 \{what} cucumber in my belly \(amazing!)
225225
I have 42 \{what} cucumbers in my belly \(amazing!)
226226

227-
There is currently no way to escape a `/` character - it will always be interpreted
228-
as alternative text.
227+
The `/` character will always be interpreted as an alternative, unless escaped, such as with `\/`.
229228

230229
## Architecture
231230

python/cucumber_expressions/parameter_type.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import re
4-
from typing import List, Pattern, Union
4+
from typing import Pattern
55

66
from cucumber_expressions.errors import CucumberExpressionError
77

@@ -48,8 +48,8 @@ def __init__(
4848
regexp,
4949
type,
5050
transformer,
51-
use_for_snippets,
52-
prefer_for_regexp_match,
51+
use_for_snippets: bool = True,
52+
prefer_for_regexp_match: bool = False,
5353
):
5454
"""Creates a new Parameter
5555
:param name: name of the parameter type
@@ -96,11 +96,9 @@ def _get_regexp_source(regexp_pattern: Pattern) -> str:
9696
)
9797
return regexp_pattern.pattern
9898

99-
def to_array(
100-
self, regexps: Union[List[str], str, List[Pattern], Pattern]
101-
) -> List[str]:
99+
def to_array(self, regexps: list[str] | str | list[Pattern] | Pattern) -> list[str]:
102100
"""Make a list of regexps if not already"""
103-
array: List = regexps if isinstance(regexps, list) else [regexps]
101+
array: list = regexps if isinstance(regexps, list) else [regexps]
104102
return [
105103
regexp if isinstance(regexp, str) else self._get_regexp_source(regexp)
106104
for regexp in array

python/tests/test_custom_parameter_type.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,24 @@ def test_matches_parameters_with_custom_parameter_type(self):
6262
transformed_argument_value = expression.match("I have a red ball")[0]
6363
assert transformed_argument_value.value == Color("red")
6464

65+
def test_matches_parameters_without_snippet_and_regex_parameters(
66+
self,
67+
):
68+
parameter_type_registry = ParameterTypeRegistry()
69+
parameter_type_registry.define_parameter_type(
70+
ParameterType(
71+
"color",
72+
r"red|blue|yellow",
73+
Color,
74+
lambda s: Color(s),
75+
)
76+
)
77+
expression = CucumberExpression(
78+
"I have a {color} ball", parameter_type_registry
79+
)
80+
argument_value = expression.match("I have a red ball")[0].value
81+
assert argument_value == Color("red")
82+
6583
def test_matches_parameters_with_multiple_capture_groups(self):
6684
self._parameter_type_registry.define_parameter_type(
6785
ParameterType(

0 commit comments

Comments
 (0)