Skip to content

Commit 05e221c

Browse files
danceratopzmarioevz
authored andcommitted
refactor: use removeprefix/removesuffix for string operations
Replace manual string slicing patterns with Python 3.9+ removeprefix/removesuffix methods for cleaner, more readable code that explicitly shows intent to remove specific prefixes or suffixes.
1 parent a961e5f commit 05e221c

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

src/ethereum_test_fixtures/collector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ class TestInfo:
3434
def strip_test_name(cls, name: str) -> str:
3535
"""Remove test prefix from a python test case name."""
3636
if name.startswith(cls.test_prefix):
37-
return name[len(cls.test_prefix) :]
37+
return name.removeprefix(cls.test_prefix)
3838
if name.endswith(cls.filler_suffix):
39-
return name[: -len(cls.filler_suffix)]
39+
return name.removesuffix(cls.filler_suffix)
4040
return name
4141

4242
def get_name_and_parameters(self) -> Tuple[str, str]:

src/ethereum_test_rpc/rpc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def __init_subclass__(cls) -> None:
7171
"""Set namespace of the RPC class to the lowercase of the class name."""
7272
namespace = cls.__name__
7373
if namespace.endswith("RPC"):
74-
namespace = namespace[:-3]
74+
namespace = namespace.removesuffix("RPC")
7575
cls.namespace = namespace.lower()
7676

7777
def post_request(self, method: str, *params: Any, extra_headers: Dict | None = None) -> Any:

src/pytest_plugins/consume/consume.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,16 @@ def from_string(cls, pattern: str) -> "SimLimitBehavior":
214214
return cls(pattern=".*", collectonly=True)
215215

216216
if pattern.startswith("collectonly:id:"):
217-
literal_id = pattern[len("collectonly:id:") :]
217+
literal_id = pattern.removeprefix("collectonly:id:")
218218
if not literal_id:
219219
raise ValueError("Empty literal ID provided.")
220220
return cls(pattern=cls._escape_id(literal_id), collectonly=True)
221221

222222
if pattern.startswith("collectonly:"):
223-
return cls(pattern=pattern[len("collectonly:") :], collectonly=True)
223+
return cls(pattern=pattern.removeprefix("collectonly:"), collectonly=True)
224224

225225
if pattern.startswith("id:"):
226-
literal_id = pattern[len("id:") :]
226+
literal_id = pattern.removeprefix("id:")
227227
if not literal_id:
228228
raise ValueError("Empty literal ID provided.")
229229
return cls(pattern=cls._escape_id(literal_id))
@@ -442,4 +442,4 @@ def pytest_collection_modifyitems(items):
442442
original_name = item.originalname
443443
remove = f"{original_name}["
444444
if item.name.startswith(remove):
445-
item.name = item.name[len(remove) : -1]
445+
item.name = item.name.removeprefix(remove)[:-1]

src/pytest_plugins/pytest_hive/pytest_hive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def hive_test(request, test_suite: HiveTestSuite):
270270
call_out = stdout
271271
# If call output starts with setup output, strip it
272272
if call_out.startswith(setup_out):
273-
stdout = call_out[len(setup_out) :]
273+
stdout = call_out.removeprefix(setup_out)
274274

275275
captured.append(
276276
f"# Captured Output from Test {phase.capitalize()}\n\n"

0 commit comments

Comments
 (0)