Skip to content

Commit 40cf10e

Browse files
committed
replace string literals
1 parent ad1ec67 commit 40cf10e

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

pyiceberg/cli/console.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from pyiceberg.catalog import Catalog, load_catalog
3333
from pyiceberg.cli.output import ConsoleOutput, JsonOutput, Output
3434
from pyiceberg.exceptions import NoSuchNamespaceError, NoSuchPropertyException, NoSuchTableError
35-
from pyiceberg.table.refs import SnapshotRef
35+
from pyiceberg.table.refs import SnapshotRef, SnapshotRefType
3636

3737
DEFAULT_MIN_SNAPSHOTS_TO_KEEP = 1
3838
DEFAULT_MAX_SNAPSHOT_AGE_MS = 432000000
@@ -388,7 +388,7 @@ def list_refs(ctx: Context, identifier: str, type: str, verbose: bool) -> None:
388388
refs = table.refs()
389389
if type:
390390
type = type.lower()
391-
if type not in {"branch", "tag"}:
391+
if type not in {SnapshotRefType.BRANCH, SnapshotRefType.TAG}:
392392
raise ValueError(f"Type must be either branch or tag, got: {type}")
393393

394394
relevant_refs = [
@@ -402,7 +402,7 @@ def list_refs(ctx: Context, identifier: str, type: str, verbose: bool) -> None:
402402

403403
def _retention_properties(ref: SnapshotRef, table_properties: Dict[str, str]) -> Dict[str, str]:
404404
retention_properties = {}
405-
if ref.snapshot_ref_type == "branch":
405+
if ref.snapshot_ref_type == SnapshotRefType.BRANCH:
406406
default_min_snapshots_to_keep = table_properties.get(
407407
"history.expire.min-snapshots-to-keep", DEFAULT_MIN_SNAPSHOTS_TO_KEEP
408408
)

pyiceberg/table/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
create_mapping_from_schema,
9191
parse_mapping_from_json,
9292
)
93-
from pyiceberg.table.refs import MAIN_BRANCH, SnapshotRef
93+
from pyiceberg.table.refs import MAIN_BRANCH, SnapshotRef, SnapshotRefType
9494
from pyiceberg.table.snapshots import (
9595
Operation,
9696
Snapshot,
@@ -391,7 +391,7 @@ class AddSnapshotUpdate(TableUpdate):
391391
class SetSnapshotRefUpdate(TableUpdate):
392392
action: TableUpdateAction = TableUpdateAction.set_snapshot_ref
393393
ref_name: str = Field(alias="ref-name")
394-
type: Literal["tag", "branch"]
394+
type: Literal[SnapshotRefType.TAG, SnapshotRefType.BRANCH]
395395
snapshot_id: int = Field(alias="snapshot-id")
396396
max_ref_age_ms: Annotated[Optional[int], Field(alias="max-ref-age-ms", default=None)]
397397
max_snapshot_age_ms: Annotated[Optional[int], Field(alias="max-snapshot-age-ms", default=None)]
@@ -2445,7 +2445,10 @@ def commit(self) -> Snapshot:
24452445
with self._table.transaction() as tx:
24462446
tx.add_snapshot(snapshot=snapshot)
24472447
tx.set_ref_snapshot(
2448-
snapshot_id=self._snapshot_id, parent_snapshot_id=self._parent_snapshot_id, ref_name=MAIN_BRANCH, type="branch"
2448+
snapshot_id=self._snapshot_id,
2449+
parent_snapshot_id=self._parent_snapshot_id,
2450+
ref_name=MAIN_BRANCH,
2451+
type=SnapshotRefType.BRANCH,
24492452
)
24502453

24512454
return snapshot

0 commit comments

Comments
 (0)