From 7e67b01ab85d3ff93c8d1825b1096df222d14bfc Mon Sep 17 00:00:00 2001 From: belthlemar Date: Tue, 1 Oct 2024 14:34:22 +0200 Subject: [PATCH] simplify small parts of code with new python api --- antarest/matrixstore/service.py | 6 +----- tests/study/storage/test_abstract_storage_service.py | 7 +------ tests/variantstudy/conftest.py | 6 +----- tests/variantstudy/test_command_factory.py | 6 +----- 4 files changed, 4 insertions(+), 21 deletions(-) diff --git a/antarest/matrixstore/service.py b/antarest/matrixstore/service.py index 7e9450fdec..b894600fb5 100644 --- a/antarest/matrixstore/service.py +++ b/antarest/matrixstore/service.py @@ -100,11 +100,7 @@ def get_matrix_id(self, matrix: t.Union[t.List[t.List[float]], str]) -> str: """ # noinspection SpellCheckingInspection if isinstance(matrix, str): - # str.removeprefix() is not available in Python 3.8 - prefix = "matrix://" - if matrix.startswith(prefix): - return matrix[len(prefix) :] - return matrix + return matrix.removeprefix("matrix://") elif isinstance(matrix, list): return self.create(matrix) else: diff --git a/tests/study/storage/test_abstract_storage_service.py b/tests/study/storage/test_abstract_storage_service.py index 97793c206d..8a7be798bd 100644 --- a/tests/study/storage/test_abstract_storage_service.py +++ b/tests/study/storage/test_abstract_storage_service.py @@ -91,12 +91,7 @@ def __init__(self, tmp_path: Path): def __eq__(self, other: Path): if isinstance(other, Path) and other.name == "tmp_copy": - # `is_relative_to` is not available for Python < 3.9 - try: - other.relative_to(self.tmp_path) - return True - except ValueError: - return False + return other.is_relative_to(self.tmp_path) def __ne__(self, other): return not self.__eq__(other) diff --git a/tests/variantstudy/conftest.py b/tests/variantstudy/conftest.py index beaaf34065..6d3039d4f9 100644 --- a/tests/variantstudy/conftest.py +++ b/tests/variantstudy/conftest.py @@ -94,11 +94,7 @@ def get_matrix_id(matrix: t.Union[t.List[t.List[float]], str]) -> str: Get the matrix ID from a matrix or a matrix link. """ if isinstance(matrix, str): - # str.removeprefix() is not available in Python 3.8 - prefix = "matrix://" - if matrix.startswith(prefix): - return matrix[len(prefix) :] - return matrix + return matrix.removeprefix("matrix://") elif isinstance(matrix, list): return create(matrix) else: diff --git a/tests/variantstudy/test_command_factory.py b/tests/variantstudy/test_command_factory.py index b78ba393e5..dd47e0453c 100644 --- a/tests/variantstudy/test_command_factory.py +++ b/tests/variantstudy/test_command_factory.py @@ -386,11 +386,7 @@ @pytest.fixture def command_factory() -> CommandFactory: def get_matrix_id(matrix: str) -> str: - # str.removeprefix() is not available in Python 3.8 - prefix = "matrix://" - if matrix.startswith(prefix): - return matrix[len(prefix) :] - return matrix + return matrix.removeprefix("matrix://") return CommandFactory( generator_matrix_constants=Mock(spec=GeneratorMatrixConstants),