Skip to content

Commit 9d47ddf

Browse files
committed
fix lint
1 parent f803333 commit 9d47ddf

6 files changed

Lines changed: 109 additions & 88 deletions

File tree

pyiceberg/catalog/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@
6767
TableVersion,
6868
)
6969
from pyiceberg.utils.config import Config, merge_config
70-
from pyiceberg.utils.properties import property_as_bool, property_as_int
71-
from pyiceberg.utils.retry import RetryConfig, run_with_suppressed_failure
70+
from pyiceberg.utils.properties import property_as_bool
7271

7372
if TYPE_CHECKING:
7473
import pyarrow as pa

pyiceberg/table/__init__.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
from pydantic import Field
3636
from sortedcontainers import SortedList
3737

38-
from pyiceberg.exceptions import CommitFailedException
3938
import pyiceberg.expressions.parser as parser
39+
from pyiceberg.exceptions import CommitFailedException
4040
from pyiceberg.expressions import (
4141
AlwaysFalse,
4242
AlwaysTrue,
@@ -292,7 +292,7 @@ class Transaction:
292292
_autocommit: bool
293293
_updates: tuple[TableUpdate, ...]
294294
_requirements: tuple[TableRequirement, ...]
295-
_pending_updates: list[_StaticUpdate | UpdateTableMetadata]
295+
_pending_updates: list[_StaticUpdate | UpdateTableMetadata[Any]]
296296
# NOTE: Whenever _updates is modified, _working_metadata must be updated via update_table_metadata()
297297
_working_metadata: TableMetadata
298298

@@ -328,7 +328,7 @@ def _apply(
328328
self,
329329
updates: tuple[TableUpdate, ...],
330330
requirements: tuple[TableRequirement, ...] = (),
331-
pending_update: _StaticUpdate | UpdateTableMetadata | None = None,
331+
pending_update: _StaticUpdate | UpdateTableMetadata[Any] | None = None,
332332
) -> Transaction:
333333
"""Check if the requirements are met, and applies the updates to the metadata."""
334334
for requirement in requirements:
@@ -340,12 +340,12 @@ def _apply(
340340

341341
# For the requirements, it does not make sense to add a requirement more than once
342342
# For example, you cannot assert that the current schema has two different IDs
343-
existing_requirements = {req.key() for req in self._requirements}
343+
existing_requirement_keys = {req.key() for req in self._requirements}
344344
for new_requirement in requirements:
345345
key = new_requirement.key()
346-
if key not in existing_requirements:
346+
if key not in existing_requirement_keys:
347347
self._requirements += (new_requirement,)
348-
existing_requirements.add(key)
348+
existing_requirement_keys.add(key)
349349

350350
if pending_update is not None:
351351
self._pending_updates.append(pending_update)
@@ -1034,7 +1034,6 @@ def _commit_with_retry(self) -> None:
10341034
On retry, refreshes table metadata and regenerates snapshots from
10351035
the pending snapshot producers.
10361036
"""
1037-
10381037
properties = self._table.metadata.properties
10391038

10401039
retry_config = RetryConfig(
@@ -1116,12 +1115,15 @@ def _reapply_updates(self) -> None:
11161115
self._updates += updates
11171116
self._working_metadata = update_table_metadata(self._working_metadata, updates)
11181117

1119-
existing_requirements = {req.key() for r in self._requirements}
1118+
existing_requirement_keys: set[tuple[Any, ...]] = set()
1119+
existing_req: TableRequirement
1120+
for existing_req in self._requirements:
1121+
existing_requirement_keys.add(existing_req.key())
11201122
for req in requirements:
11211123
key = req.key()
1122-
if key not in existing_requirements:
1124+
if key not in existing_requirement_keys:
11231125
self._requirements += (req,)
1124-
existing_requirements.add(key)
1126+
existing_requirement_keys.add(key)
11251127

11261128
self._requirements += (AssertTableUUID(uuid=self.table_metadata.table_uuid),)
11271129

pyiceberg/table/update/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ def validate(self, base_metadata: TableMetadata | None) -> None:
754754
"""
755755
...
756756

757-
def key(self) -> tuple:
757+
def key(self) -> tuple[Any, ...]:
758758
"""Return a deduplication key for this requirement."""
759759
return (type(self),)
760760

@@ -816,7 +816,7 @@ def validate(self, base_metadata: TableMetadata | None) -> None:
816816
elif self.snapshot_id is not None:
817817
raise CommitFailedException(f"Requirement failed: branch or tag {self.ref} is missing, expected {self.snapshot_id}")
818818

819-
def key(self) -> tuple:
819+
def key(self) -> tuple[Any, ...]:
820820
return (type(self), self.ref)
821821

822822

pyiceberg/table/update/snapshot.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
from sortedcontainers import SortedList
3131

3232
from pyiceberg.avro.codecs import AvroCompressionCodec
33+
from pyiceberg.exceptions import (
34+
CommitFailedException,
35+
CommitStateUnknownException,
36+
)
3337
from pyiceberg.expressions import (
3438
AlwaysFalse,
3539
BooleanExpression,
@@ -58,6 +62,7 @@
5862
from pyiceberg.partitioning import (
5963
PartitionSpec,
6064
)
65+
from pyiceberg.table.metadata import TableMetadata
6166
from pyiceberg.table.refs import MAIN_BRANCH, SnapshotRefType
6267
from pyiceberg.table.snapshots import (
6368
Operation,
@@ -66,11 +71,6 @@
6671
Summary,
6772
update_snapshot_summaries,
6873
)
69-
from pyiceberg.exceptions import (
70-
CommitFailedException,
71-
CommitStateUnknownException,
72-
)
73-
from pyiceberg.table.metadata import TableMetadata
7474
from pyiceberg.table.update import (
7575
AddSnapshotUpdate,
7676
AssertRefSnapshotId,
@@ -293,9 +293,7 @@ def _build_updates(self) -> UpdatesAndRequirements:
293293
"""Build the updates and requirements for this snapshot operation."""
294294
# Recalculate parent snapshot ID from current table_metadata
295295
self._parent_snapshot_id = (
296-
snapshot.snapshot_id
297-
if (snapshot := self._transaction.table_metadata.snapshot_by_name(self._target_branch))
298-
else None
296+
snapshot.snapshot_id if (snapshot := self._transaction.table_metadata.snapshot_by_name(self._target_branch)) else None
299297
)
300298

301299
new_manifests = self._manifests()
@@ -416,9 +414,7 @@ def _reset_state(self) -> None:
416414
self._manifest_num_counter = itertools.count(0)
417415

418416
self._parent_snapshot_id = (
419-
snapshot.snapshot_id
420-
if (snapshot := self._transaction.table_metadata.snapshot_by_name(self._target_branch))
421-
else None
417+
snapshot.snapshot_id if (snapshot := self._transaction.table_metadata.snapshot_by_name(self._target_branch)) else None
422418
)
423419

424420
# Clear cached properties that depend on snapshot state
@@ -483,9 +479,7 @@ def do_commit() -> None:
483479

484480
updates, requirements = self._commit()
485481

486-
requirements = requirements + (
487-
AssertTableUUID(uuid=self._transaction.table_metadata.table_uuid),
488-
)
482+
requirements = requirements + (AssertTableUUID(uuid=self._transaction.table_metadata.table_uuid),)
489483

490484
# Directly commit to catalog (bypassing transaction accumulation)
491485
# This is necessary because:
@@ -503,7 +497,7 @@ def do_commit() -> None:
503497
retry_on=(CommitFailedException,),
504498
)
505499
except CommitStateUnknownException:
506-
# NOTE: Use the function like checkCommitStatus() in Java
500+
# NOTE: Use the function like checkCommitStatus() in Java
507501
# to determine if the commit succeeded before raising this exception.
508502
raise
509503

pyiceberg/utils/retry.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,12 @@ def run_with_retry(
8585
"""
8686
start_time_ms = int(time.time() * 1000)
8787
attempt = 0
88-
last_exception: Exception | None = None
8988

9089
while True:
9190
attempt += 1
9291
try:
9392
return task()
9493
except Exception as e:
95-
last_exception = e
96-
9794
if not isinstance(e, retry_on):
9895
raise
9996

0 commit comments

Comments
 (0)