This is an automated email from the ASF dual-hosted git repository. github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-4180-fcb64f8107f3a9bb9d03b50b7e65587e215cf7c4 in repository https://gitbox.apache.org/repos/asf/iceberg-python.git
commit 06a529d7dcb573375fa951603f491995421ef184 Author: Orest Tokovenko <[email protected]> AuthorDate: Thu Oct 29 16:40:23 2026 +0000 chore: use StrEnum for the four enums that subclass str (#4180) 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 5cccddc6b..c8e2399fe 100644 --- a/pyiceberg/catalog/rest/__init__.py +++ b/pyiceberg/catalog/rest/__init__.py @@ -20,7 +20,7 @@ import logging 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 @@ if TYPE_CHECKING: 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 88ca05101..0881273c4 100644 --- a/pyiceberg/manifest.py +++ b/pyiceberg/manifest.py @@ -21,7 +21,7 @@ import threading 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 @@ class ManifestEntryStatus(int, Enum): 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 0cbc11689..ccb5a6cf9 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 @@ from pyiceberg.typedef import IcebergBaseModel MAIN_BRANCH = "main" -class SnapshotRefType(str, Enum): +class SnapshotRefType(StrEnum): BRANCH = "branch" TAG = "tag" @@ -33,10 +33,6 @@ class SnapshotRefType(str, Enum): """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 0450df286..66d3d7f23 100644 --- a/pyiceberg/table/snapshots.py +++ b/pyiceberg/table/snapshots.py @@ -20,7 +20,7 @@ import time 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 @@ class Operation(Enum): return f"Operation.{self.name}" -class IsolationLevel(str, Enum): +class IsolationLevel(StrEnum): """Transaction isolation level for concurrent write validation.""" SERIALIZABLE = "serializable"
