Skip to content

Commit

Permalink
Drop re_pattern compat as lowest Python is 3.7 now
Browse files Browse the repository at this point in the history
  • Loading branch information
fliiiix committed Dec 19, 2024
1 parent a957493 commit 56f2348
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 20 deletions.
7 changes: 0 additions & 7 deletions radish/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
"""

import sys
import re

try:
re_pattern = re.Pattern # >= Python 3.7
except AttributeError:
re_pattern = re._pattern_type


# RecursionError does not exist in Python < 3.5
RecursionError = RuntimeError if sys.version_info < (3, 5) else RecursionError
1 change: 1 addition & 0 deletions radish/extensions/user_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
and provides this data as a dictionary attached to the world.config object
as per Enhancement #124.
"""

import re

from radish.terrain import world
Expand Down
3 changes: 1 addition & 2 deletions radish/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from .customtyperegistry import CustomTypeRegistry
from .exceptions import StepDefinitionNotFoundError, StepPatternError
from .compat import re_pattern

StepMatch = namedtuple("StepMatch", ["argument_match", "func"])

Expand Down Expand Up @@ -87,7 +86,7 @@ def match_step(sentence, steps):
"""
potentional_matches = []
for pattern, func in steps.items():
if isinstance(pattern, re_pattern): # pylint: disable=protected-access
if isinstance(pattern, re.Pattern): # pylint: disable=protected-access
match = pattern.search(sentence)
argument_match = RegexStepArguments(match)
if match:
Expand Down
7 changes: 3 additions & 4 deletions radish/stepregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from singleton import singleton

from .exceptions import RadishError, SameStepError, StepRegexError
from .compat import re_pattern


@singleton()
Expand Down Expand Up @@ -139,7 +138,7 @@ def given(pattern):
"""
Step decorator prefixed with the Given-keyword.
"""
if isinstance(pattern, re_pattern): # pylint: disable=protected-access
if isinstance(pattern, re.Pattern): # pylint: disable=protected-access
return step(re.compile(r"Given {0}".format(pattern.pattern)))
return step("Given {0}".format(pattern))

Expand All @@ -148,7 +147,7 @@ def when(pattern):
"""
Step decorator prefixed with the When-keyword.
"""
if isinstance(pattern, re_pattern): # pylint: disable=protected-access
if isinstance(pattern, re.Pattern): # pylint: disable=protected-access
return step(re.compile(r"When {0}".format(pattern.pattern)))
return step("When {0}".format(pattern))

Expand All @@ -157,6 +156,6 @@ def then(pattern):
"""
Step decorator prefixed with the Then-keyword.
"""
if isinstance(pattern, re_pattern): # pylint: disable=protected-access
if isinstance(pattern, re.Pattern): # pylint: disable=protected-access
return step(re.compile(r"Then {0}".format(pattern.pattern)))
return step("Then {0}".format(pattern))
1 change: 0 additions & 1 deletion tests/radish/steps_german.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Copyright: MIT, Timo Furrer <[email protected]>
"""


from radish import step


Expand Down
1 change: 0 additions & 1 deletion tests/unit/test_background.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Copyright: MIT, Timo Furrer <[email protected]>
"""


from radish.background import Background
from radish.stepmodel import Step

Expand Down
9 changes: 4 additions & 5 deletions tests/unit/test_stepregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

from radish.stepregistry import step, steps
from radish.stepregistry import given, when, then
from radish.compat import re_pattern
import radish.exceptions as errors


Expand Down Expand Up @@ -173,7 +172,7 @@ def step_a(step):

# then
assert len(stepregistry.steps) == 1
if not isinstance(pattern, re_pattern): # doesn't work for re_pattern.
if not isinstance(pattern, re.Pattern): # doesn't work for re.Pattern.
assert stepregistry.steps[pattern] == step_a


Expand All @@ -197,7 +196,7 @@ def step_a(step):

# then
assert len(stepregistry.steps) == 1
if not isinstance(pattern, re_pattern): # doesn't work for re_pattern.
if not isinstance(pattern, re.Pattern): # doesn't work for re.Pattern.
assert stepregistry.steps[expected_pattern] == step_a


Expand All @@ -221,7 +220,7 @@ def step_a(step):

# then
assert len(stepregistry.steps) == 1
if not isinstance(pattern, re_pattern): # doesn't work for re_pattern.
if not isinstance(pattern, re.Pattern): # doesn't work for re.Pattern.
assert stepregistry.steps[expected_pattern] == step_a


Expand All @@ -245,7 +244,7 @@ def step_a(step):

# then
assert len(stepregistry.steps) == 1
if not isinstance(pattern, re_pattern): # doesn't work for re_pattern.
if not isinstance(pattern, re.Pattern): # doesn't work for re.Pattern.
assert stepregistry.steps[expected_pattern] == step_a


Expand Down

0 comments on commit 56f2348

Please sign in to comment.