Skip to content

Commit ea7cef3

Browse files
committed
Remove removing support for py 3.8
1 parent f9a7afb commit ea7cef3

15 files changed

+199
-110
lines changed

python/cucumber_expressions/argument.py

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

3-
from typing import Optional
3+
from typing import Optional, List
44

55
from cucumber_expressions.parameter_type import ParameterType
66
from cucumber_expressions.tree_regexp import TreeRegexp, Group
@@ -19,8 +19,8 @@ def __init__(
1919
def build(
2020
tree_regexp: TreeRegexp,
2121
text: str,
22-
parameter_types_and_names: list[tuple[ParameterType, Optional[str]]],
23-
) -> Optional[list[Argument]]:
22+
parameter_types_and_names: List[tuple[ParameterType, Optional[str]]],
23+
) -> Optional[List[Argument]]:
2424
# Check if all elements in parameter_types_and_names are tuples
2525
for item in parameter_types_and_names:
2626
if not isinstance(item, tuple) or len(item) != 2:

python/cucumber_expressions/ast.py

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

33
from enum import Enum
4-
from typing import Optional, Any
4+
from typing import Optional, List, Any
55

66

77
class NodeType(Enum):
@@ -41,18 +41,38 @@ class Node:
4141
def __init__(
4242
self,
4343
ast_type: NodeType,
44-
nodes: Optional[list[Node]],
44+
nodes: Optional[List[Node]],
4545
token: Optional[str],
4646
start: int,
4747
end: int,
4848
):
4949
if nodes is None and token is None:
5050
raise Exception("Either nodes or token must be defined")
51-
self.ast_type = ast_type
52-
self.nodes = nodes
53-
self.token = token
54-
self.start = start
55-
self.end = end
51+
self._ast_type = ast_type
52+
self._nodes = nodes
53+
self._token = token
54+
self._start = start
55+
self._end = end
56+
57+
@property
58+
def ast_type(self) -> NodeType:
59+
return self._ast_type
60+
61+
@property
62+
def nodes(self) -> List[Node]:
63+
return self._nodes
64+
65+
@property
66+
def token(self) -> str:
67+
return self._token
68+
69+
@property
70+
def start(self) -> int:
71+
return self._start
72+
73+
@property
74+
def end(self) -> int:
75+
return self._end
5676

5777
@property
5878
def text(self) -> str:
@@ -71,10 +91,26 @@ def to_json(self) -> dict[str, Any]:
7191

7292
class Token:
7393
def __init__(self, ast_type: TokenType, text: str, start: int, end: int):
74-
self.ast_type = ast_type
75-
self.text = text
76-
self.start = start
77-
self.end = end
94+
self._ast_type = ast_type
95+
self._text = text
96+
self._start = start
97+
self._end = end
98+
99+
@property
100+
def ast_type(self):
101+
return self._ast_type
102+
103+
@property
104+
def text(self):
105+
return self._text
106+
107+
@property
108+
def start(self):
109+
return self._start
110+
111+
@property
112+
def end(self):
113+
return self._end
78114

79115
@staticmethod
80116
def is_escape_character(char: str) -> bool:

python/cucumber_expressions/combinatorial_generated_expression_factory.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import List
2+
13
from cucumber_expressions.generated_expression import GeneratedExpression
24
from cucumber_expressions.parameter_type import ParameterType
35

@@ -10,16 +12,16 @@ def __init__(self, expression_template, parameter_type_combinations):
1012
self.expression_template = expression_template
1113
self.parameter_type_combinations = parameter_type_combinations
1214

13-
def generate_expressions(self) -> list[GeneratedExpression]:
15+
def generate_expressions(self) -> List[GeneratedExpression]:
1416
generated_expressions = []
1517
self.generate_permutations(generated_expressions, 0, [])
1618
return generated_expressions
1719

1820
def generate_permutations(
1921
self,
20-
generated_expressions: list[GeneratedExpression],
22+
generated_expressions: List[GeneratedExpression],
2123
depth: int,
22-
current_parameter_types: list[ParameterType],
24+
current_parameter_types: List[ParameterType],
2325
):
2426
if len(generated_expressions) >= MAX_EXPRESSIONS:
2527
return

python/cucumber_expressions/expression.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional
1+
from typing import Optional, List
22

33
from cucumber_expressions.argument import Argument
44
from cucumber_expressions.ast import Node, NodeType
@@ -22,12 +22,12 @@ class CucumberExpression:
2222
def __init__(self, expression: str, parameter_type_registry: ParameterTypeRegistry):
2323
self.expression = expression
2424
self.parameter_type_registry = parameter_type_registry
25-
self.parameter_types_and_names: list[tuple[ParameterType, Optional[str]]] = []
25+
self.parameter_types_and_names: List[tuple[ParameterType, Optional[str]]] = []
2626
self.tree_regexp = TreeRegexp(
2727
self.rewrite_to_regex(CucumberExpressionParser().parse(self.expression))
2828
)
2929

30-
def match(self, text: str) -> Optional[list[Argument]]:
30+
def match(self, text: str) -> Optional[List[Argument]]:
3131
return Argument.build(self.tree_regexp, text, self.parameter_types_and_names)
3232

3333
@property
@@ -130,5 +130,5 @@ def get_possible_node_with_optionals(self, node: Node) -> Optional[Node]:
130130
return results[0] if results else None
131131

132132
@staticmethod
133-
def get_nodes_with_ast_type(node: Node, ast_type: NodeType) -> list[Node]:
133+
def get_nodes_with_ast_type(node: Node, ast_type: NodeType) -> List[Node]:
134134
return [ast_node for ast_node in node.nodes if ast_node.ast_type == ast_type]

python/cucumber_expressions/expression_generator.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import functools
22
import re
3+
from typing import List
34

45
from cucumber_expressions.generated_expression import GeneratedExpression
56
from cucumber_expressions.parameter_type import ParameterType
@@ -14,10 +15,10 @@ class CucumberExpressionGenerator:
1415
def __init__(self, parameter_type_registry: ParameterTypeRegistry):
1516
self.parameter_type_registry = parameter_type_registry
1617

17-
def generate_expressions(self, text: str) -> list[GeneratedExpression]:
18+
def generate_expressions(self, text: str) -> List[GeneratedExpression]:
1819
parameter_type_combinations = []
1920
parameter_type_matchers = self.create_parameter_type_matchers(text)
20-
expression_template: list[str] = []
21+
expression_template: List[str] = []
2122
pos = 0
2223

2324
while True:
@@ -92,7 +93,7 @@ def create_parameter_type_matchers(self, text) -> list[ParameterTypeMatcher]:
9293
@staticmethod
9394
def create_parameter_type_matchers_with_type(
9495
parameter_type, text
95-
) -> list[ParameterTypeMatcher]:
96+
) -> List[ParameterTypeMatcher]:
9697
return [
9798
ParameterTypeMatcher(parameter_type, re.compile(f"({regexp})"), text, 0)
9899
for regexp in parameter_type.regexps

python/cucumber_expressions/expression_parser.py

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

3-
from typing import NamedTuple, Optional, Callable
3+
from typing import NamedTuple, Optional, Callable, List
44

55
from cucumber_expressions.ast import Token, TokenType, Node, NodeType
66
from cucumber_expressions.errors import (
@@ -18,7 +18,7 @@ class Result(NamedTuple):
1818

1919
class Parser(NamedTuple):
2020
expression: str
21-
tokens: list[Token]
21+
tokens: List[Token]
2222
current: int
2323

2424

@@ -75,7 +75,7 @@ def parse(self, expression: str) -> Node:
7575

7676
# optional := '(' + option* + ')'
7777
# option := optional | parameter | text
78-
optional_sub_parsers: list = []
78+
optional_sub_parsers = []
7979
parse_optional = self.parse_between(
8080
NodeType.OPTIONAL,
8181
TokenType.BEGIN_OPTIONAL,
@@ -170,7 +170,7 @@ def parse_between(
170170
ast_type: NodeType,
171171
begin_token: TokenType,
172172
end_token: TokenType,
173-
parsers: list,
173+
parsers: List,
174174
) -> Callable[[Parser], Result | tuple[int, Node]]:
175175
def _parse_between(parser: Parser):
176176
if not self.looking_at(parser.tokens, parser.current, begin_token):
@@ -205,7 +205,7 @@ def _parse_between(parser: Parser):
205205

206206
@staticmethod
207207
def parse_token(
208-
expression, parsers: list, tokens: list[Token], start_at: int
208+
expression, parsers: List, tokens: List[Token], start_at: int
209209
) -> Result:
210210
for parser in parsers:
211211
consumed, ast = parser(Parser(expression, tokens, start_at))
@@ -217,14 +217,14 @@ def parse_token(
217217
def parse_tokens_until(
218218
self,
219219
expression,
220-
parsers: list,
221-
tokens: list[Token],
220+
parsers: List,
221+
tokens: List[Token],
222222
start_at: int,
223-
end_tokens: list[TokenType],
224-
) -> tuple[int, list[Node]]:
223+
end_tokens: List[TokenType],
224+
) -> tuple[int, List[Node]]:
225225
current = start_at
226226
size = len(tokens)
227-
ast: list[Node] = []
227+
ast: List[Node] = []
228228
while current < size:
229229
if self.looking_at_any(tokens, current, end_tokens):
230230
break
@@ -238,14 +238,14 @@ def parse_tokens_until(
238238
return current - start_at, ast
239239

240240
def looking_at_any(
241-
self, tokens: list[Token], position: int, token_types: list[TokenType]
241+
self, tokens: List[Token], position: int, token_types: List[TokenType]
242242
) -> bool:
243243
return any(
244244
self.looking_at(tokens, position, token_type) for token_type in token_types
245245
)
246246

247247
@staticmethod
248-
def looking_at(tokens: list[Token], position: int, token_type: TokenType) -> bool:
248+
def looking_at(tokens: List[Token], position: int, token_type: TokenType) -> bool:
249249
if position < 0:
250250
# If configured correctly this will never happen
251251
# Keep for completeness
@@ -255,8 +255,8 @@ def looking_at(tokens: list[Token], position: int, token_type: TokenType) -> boo
255255
return tokens[position].ast_type == token_type
256256

257257
def split_alternatives(
258-
self, start: int, end: int, alternation: list[Node]
259-
) -> list[Node]:
258+
self, start: int, end: int, alternation: List[Node]
259+
) -> List[Node]:
260260
separators = []
261261
alternatives = []
262262
alternative = []
@@ -272,8 +272,8 @@ def split_alternatives(
272272

273273
@staticmethod
274274
def create_alternative_nodes(
275-
start: int, end: int, separators: list, alternatives: list
276-
) -> list[Node]:
275+
start: int, end: int, separators: List, alternatives: List
276+
) -> List[Node]:
277277
for index, alternative in enumerate(alternatives):
278278
if index == 0:
279279
right_separator = separators[index]

python/cucumber_expressions/expression_tokenizer.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import List
2+
13
from cucumber_expressions.ast import TokenType, Token
24
from cucumber_expressions.errors import (
35
TheEndOfLineCannotBeEscaped,
@@ -8,11 +10,11 @@
810
class CucumberExpressionTokenizer:
911
def __init__(self):
1012
self.expression: str = ""
11-
self.buffer: list[str] = []
13+
self.buffer: List[str] = []
1214
self.escaped: int = 0
1315
self.buffer_start_index: int = 0
1416

15-
def tokenize(self, expression: str, to_json: bool = False) -> list[Token]:
17+
def tokenize(self, expression: str, to_json: bool = False) -> List[Token]:
1618
self.expression = expression
1719
tokens = []
1820
previous_token_type = TokenType.START_OF_LINE
@@ -48,7 +50,7 @@ def tokenize(self, expression: str, to_json: bool = False) -> list[Token]:
4850

4951
tokens.append(Token(TokenType.END_OF_LINE, "", len(chars), len(chars)))
5052

51-
def convert_to_json_format(_tokens: list[Token]) -> list:
53+
def convert_to_json_format(_tokens: List[Token]) -> List:
5254
return [
5355
{
5456
"type": t.ast_type.value,

python/cucumber_expressions/generated_expression.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ def __init__(self, expression_template: str, parameter_types):
55
self.usage_by_type_name = {}
66

77
@property
8-
def source(self) -> str:
8+
def source(self):
99
return self.expression_template % tuple(p.name for p in self.parameter_types)
1010

1111
@property
12-
def parameter_names(self) -> list[str]:
12+
def parameter_names(self):
1313
return [self.get_parameter_name(t.name) for t in self.parameter_types]
1414

15-
def get_parameter_name(self, type_name: str) -> str:
15+
def get_parameter_name(self, type_name):
1616
count = self.usage_by_type_name.get(type_name) or 0
1717
count = count + 1
1818
self.usage_by_type_name[type_name] = count

python/cucumber_expressions/group.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,38 @@
1+
from __future__ import annotations
2+
3+
from typing import List, Optional
4+
5+
16
class Group:
27
def __init__(
38
self,
49
value: str,
510
start: int,
611
end: int,
7-
children: list["Group"],
8-
name: str | None = None,
12+
children: List[Group],
13+
name: Optional[str] = None,
914
):
10-
self.children = children
15+
self._children = children
16+
self._value = value
17+
self._start = start
18+
self._end = end
1119
self.name = name
12-
self.value = value
13-
self.start = start
14-
self.end = end
20+
21+
@property
22+
def value(self):
23+
return self._value
24+
25+
@property
26+
def start(self):
27+
return self._start
28+
29+
@property
30+
def end(self):
31+
return self._end
32+
33+
@property
34+
def children(self):
35+
return self._children
1536

1637
@property
1738
def values(self):

0 commit comments

Comments
 (0)