From 6865c678544719810aafeb6be96b06f428fc2122 Mon Sep 17 00:00:00 2001 From: Till Hartmann Date: Fri, 23 Oct 2026 11:53:46 +0200 Subject: [PATCH 1/2] fix: fall back to a local StrEnum on Python < 3.11 --- src/snakemake_interface_common/io.py | 10 +++++++++- tests/tests.py | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/snakemake_interface_common/io.py b/src/snakemake_interface_common/io.py index a6d65bb..d2abd35 100644 --- a/src/snakemake_interface_common/io.py +++ b/src/snakemake_interface_common/io.py @@ -1,7 +1,15 @@ from abc import ABC, abstractmethod -from enum import StrEnum from typing import Any, Dict, Optional +try: + from enum import StrEnum +except ImportError: # Python < 3.11, e.g. in script envs + from enum import Enum + + class StrEnum(str, Enum): + def __str__(self): + return str(self.value) + class AccessPattern(StrEnum): RANDOM = "random" diff --git a/tests/tests.py b/tests/tests.py index a6ad793..b17bb84 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -138,3 +138,10 @@ def __init__(self): assert settings.required_int == 789 assert settings.optional_int is None + + +def test_access_pattern_str(): + from snakemake_interface_common.io import AccessPattern + + assert str(AccessPattern.RANDOM) == "random" + assert f"{AccessPattern.MULTI}" == "multi" From edaadd2e765f020a625612aef6f2c98e230e8784 Mon Sep 17 00:00:00 2001 From: Till Hartmann Date: Fri, 23 Oct 2026 13:21:43 +0200 Subject: [PATCH 2/2] fix: use a version check for the StrEnum fallback to satisfy mypy --- src/snakemake_interface_common/io.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/snakemake_interface_common/io.py b/src/snakemake_interface_common/io.py index d2abd35..e8be2fb 100644 --- a/src/snakemake_interface_common/io.py +++ b/src/snakemake_interface_common/io.py @@ -1,13 +1,14 @@ +import sys from abc import ABC, abstractmethod from typing import Any, Dict, Optional -try: +if sys.version_info >= (3, 11): from enum import StrEnum -except ImportError: # Python < 3.11, e.g. in script envs +else: # e.g. in script envs from enum import Enum class StrEnum(str, Enum): - def __str__(self): + def __str__(self) -> str: return str(self.value)