From c05d753112d07e7cc55269f51986f0e992db375a Mon Sep 17 00:00:00 2001 From: Orest Tokovenko Date: Wed, 28 Oct 2026 20:03:21 -0700 Subject: [PATCH] Use StrEnum for the four enums that subclass str Python 3.11 added enum.StrEnum, and ruff's UP042 (preview) asks for it. HttpMethod, FileFormat, IsolationLevel and SnapshotRefType all qualify. SnapshotRefType.__str__ goes away because StrEnum already returns the value. For the other three, str() and f-strings now render the value instead of the class-qualified name, so FileFormat.AVRO prints as AVRO where it used to print as FileFormat.AVRO. repr() keeps the class name, and the values, equality, hashing and JSON output are unchanged. No code or test in the repository relied on the old strings. --- pyiceberg/catalog/rest/__init__.py | 4 ++-- pyiceberg/manifest.py | 4 ++-- pyiceberg/table/refs.py | 8 ++------ pyiceberg/table/snapshots.py | 4 ++-- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/pyiceberg/catalog/rest/__init__.py b/pyiceberg/catalog/rest/__init__.py index 5cccddc6b4..c8e2399fe8 100644 --- a/pyiceberg/catalog/rest/__init__.py +++ b/pyiceberg/catalog/rest/__init__.py @@ -20,7 +20,7 @@ import time from collections import deque from collections.abc import Mapping -from enum import Enum +from enum import Enum, StrEnum from typing import ( TYPE_CHECKING, Any, @@ -113,7 +113,7 @@ logger = logging.getLogger(__name__) -class HttpMethod(str, Enum): +class HttpMethod(StrEnum): GET = "GET" HEAD = "HEAD" POST = "POST" diff --git a/pyiceberg/manifest.py b/pyiceberg/manifest.py index 88ca051015..0881273c45 100644 --- a/pyiceberg/manifest.py +++ b/pyiceberg/manifest.py @@ -21,7 +21,7 @@ from abc import ABC, abstractmethod from collections.abc import Callable, Iterator from copy import copy -from enum import Enum +from enum import Enum, StrEnum from types import TracebackType from typing import ( Any, @@ -111,7 +111,7 @@ def __repr__(self) -> str: return f"ManifestEntryStatus.{self.name}" -class FileFormat(str, Enum): +class FileFormat(StrEnum): AVRO = "AVRO" PARQUET = "PARQUET" ORC = "ORC" diff --git a/pyiceberg/table/refs.py b/pyiceberg/table/refs.py index 0cbc11689a..ccb5a6cf99 100644 --- a/pyiceberg/table/refs.py +++ b/pyiceberg/table/refs.py @@ -14,7 +14,7 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -from enum import Enum +from enum import StrEnum from typing import Annotated from pydantic import Field, model_validator @@ -25,7 +25,7 @@ MAIN_BRANCH = "main" -class SnapshotRefType(str, Enum): +class SnapshotRefType(StrEnum): BRANCH = "branch" TAG = "tag" @@ -33,10 +33,6 @@ def __repr__(self) -> str: """Return the string representation of the SnapshotRefType class.""" return f"SnapshotRefType.{self.name}" - def __str__(self) -> str: - """Return the string representation of the SnapshotRefType class.""" - return self.value - class SnapshotRef(IcebergBaseModel): snapshot_id: int = Field(alias="snapshot-id") diff --git a/pyiceberg/table/snapshots.py b/pyiceberg/table/snapshots.py index 0450df2861..66d3d7f239 100644 --- a/pyiceberg/table/snapshots.py +++ b/pyiceberg/table/snapshots.py @@ -20,7 +20,7 @@ import warnings from collections import defaultdict from collections.abc import Iterable, Mapping -from enum import Enum +from enum import Enum, StrEnum from typing import TYPE_CHECKING, Any from pydantic import Field, PrivateAttr, model_serializer @@ -87,7 +87,7 @@ def __repr__(self) -> str: return f"Operation.{self.name}" -class IsolationLevel(str, Enum): +class IsolationLevel(StrEnum): """Transaction isolation level for concurrent write validation.""" SERIALIZABLE = "serializable"