Skip to content

Commit 60ebe93

Browse files
Enable up037 (#2739)
<!-- Thanks for opening a pull request! --> Part of #2700 <!-- In the case this PR will resolve an issue, please replace ${GITHUB_ISSUE_ID} below with the actual Github issue id. --> <!-- Closes #${GITHUB_ISSUE_ID} --> # Rationale for this change This enables linter rule UP037 ## Are these changes tested? `make lint` and `make test` should pass. ## Are there any user-facing changes? <!-- In the case of user-facing changes, please add the changelog label. --> Co-authored-by: Kevin Liu <kevinjqliu@users.noreply.github.com>
1 parent ff0fa55 commit 60ebe93

File tree

8 files changed

+41
-42
lines changed

8 files changed

+41
-42
lines changed

pyiceberg/catalog/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def __init__(self, name: str, **properties: str):
361361
def create_table(
362362
self,
363363
identifier: str | Identifier,
364-
schema: Schema | "pa.Schema",
364+
schema: Schema | pa.Schema,
365365
location: str | None = None,
366366
partition_spec: PartitionSpec = UNPARTITIONED_PARTITION_SPEC,
367367
sort_order: SortOrder = UNSORTED_SORT_ORDER,
@@ -388,7 +388,7 @@ def create_table(
388388
def create_table_transaction(
389389
self,
390390
identifier: str | Identifier,
391-
schema: Schema | "pa.Schema",
391+
schema: Schema | pa.Schema,
392392
location: str | None = None,
393393
partition_spec: PartitionSpec = UNPARTITIONED_PARTITION_SPEC,
394394
sort_order: SortOrder = UNSORTED_SORT_ORDER,
@@ -411,7 +411,7 @@ def create_table_transaction(
411411
def create_table_if_not_exists(
412412
self,
413413
identifier: str | Identifier,
414-
schema: Schema | "pa.Schema",
414+
schema: Schema | pa.Schema,
415415
location: str | None = None,
416416
partition_spec: PartitionSpec = UNPARTITIONED_PARTITION_SPEC,
417417
sort_order: SortOrder = UNSORTED_SORT_ORDER,
@@ -753,7 +753,7 @@ def _load_file_io(self, properties: Properties = EMPTY_DICT, location: str | Non
753753

754754
@staticmethod
755755
def _convert_schema_if_needed(
756-
schema: Schema | "pa.Schema", format_version: TableVersion = TableProperties.DEFAULT_FORMAT_VERSION
756+
schema: Schema | pa.Schema, format_version: TableVersion = TableProperties.DEFAULT_FORMAT_VERSION
757757
) -> Schema:
758758
if isinstance(schema, Schema):
759759
return schema
@@ -799,7 +799,7 @@ def close(self) -> None: # noqa: B027
799799
Default implementation does nothing. Override in subclasses that need cleanup.
800800
"""
801801

802-
def __enter__(self) -> "Catalog":
802+
def __enter__(self) -> Catalog:
803803
"""Enter the context manager.
804804
805805
Returns:
@@ -829,7 +829,7 @@ def __init__(self, name: str, **properties: str):
829829
def create_table_transaction(
830830
self,
831831
identifier: str | Identifier,
832-
schema: Schema | "pa.Schema",
832+
schema: Schema | pa.Schema,
833833
location: str | None = None,
834834
partition_spec: PartitionSpec = UNPARTITIONED_PARTITION_SPEC,
835835
sort_order: SortOrder = UNSORTED_SORT_ORDER,
@@ -869,7 +869,7 @@ def purge_table(self, identifier: str | Identifier) -> None:
869869
def _create_staged_table(
870870
self,
871871
identifier: str | Identifier,
872-
schema: Schema | "pa.Schema",
872+
schema: Schema | pa.Schema,
873873
location: str | None = None,
874874
partition_spec: PartitionSpec = UNPARTITIONED_PARTITION_SPEC,
875875
sort_order: SortOrder = UNSORTED_SORT_ORDER,

pyiceberg/catalog/glue.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def primitive(self, primitive: PrimitiveType) -> str:
199199

200200

201201
def _to_columns(metadata: TableMetadata) -> List["ColumnTypeDef"]:
202-
results: Dict[str, "ColumnTypeDef"] = {}
202+
results: Dict[str, ColumnTypeDef] = {}
203203

204204
def _append_to_results(field: NestedField, is_current: bool) -> None:
205205
if field.name in results:
@@ -241,7 +241,7 @@ def _construct_table_input(
241241
glue_table: Optional["TableTypeDef"] = None,
242242
prev_metadata_location: str | None = None,
243243
) -> "TableInputTypeDef":
244-
table_input: "TableInputTypeDef" = {
244+
table_input: TableInputTypeDef = {
245245
"Name": table_name,
246246
"TableType": EXTERNAL_TABLE,
247247
"Parameters": _construct_parameters(metadata_location, glue_table, prev_metadata_location, properties),
@@ -258,7 +258,7 @@ def _construct_table_input(
258258

259259

260260
def _construct_rename_table_input(to_table_name: str, glue_table: "TableTypeDef") -> "TableInputTypeDef":
261-
rename_table_input: "TableInputTypeDef" = {"Name": to_table_name}
261+
rename_table_input: TableInputTypeDef = {"Name": to_table_name}
262262
# use the same Glue info to create the new table, pointing to the old metadata
263263
if not glue_table["TableType"]:
264264
raise ValueError("Glue table type is missing, cannot rename table")
@@ -283,7 +283,7 @@ def _construct_rename_table_input(to_table_name: str, glue_table: "TableTypeDef"
283283

284284

285285
def _construct_database_input(database_name: str, properties: Properties) -> "DatabaseInputTypeDef":
286-
database_input: "DatabaseInputTypeDef" = {"Name": database_name}
286+
database_input: DatabaseInputTypeDef = {"Name": database_name}
287287
parameters = {}
288288
for k, v in properties.items():
289289
if k == "Description":
@@ -506,7 +506,7 @@ def commit_table(
506506
table_identifier = table.name()
507507
database_name, table_name = self.identifier_to_database_and_table(table_identifier, NoSuchTableError)
508508

509-
current_glue_table: "TableTypeDef" | None
509+
current_glue_table: TableTypeDef | None
510510
glue_table_version_id: str | None
511511
current_table: Table | None
512512
try:
@@ -718,7 +718,7 @@ def list_tables(self, namespace: str | Identifier) -> List[Identifier]:
718718
NoSuchNamespaceError: If a namespace with the given name does not exist, or the identifier is invalid.
719719
"""
720720
database_name = self.identifier_to_database(namespace, NoSuchNamespaceError)
721-
table_list: List["TableTypeDef"] = []
721+
table_list: List[TableTypeDef] = []
722722
next_token: str | None = None
723723
try:
724724
while True:
@@ -746,7 +746,7 @@ def list_namespaces(self, namespace: str | Identifier = ()) -> List[Identifier]:
746746
if namespace:
747747
return []
748748

749-
database_list: List["DatabaseTypeDef"] = []
749+
database_list: List[DatabaseTypeDef] = []
750750
next_token: str | None = None
751751

752752
while True:

pyiceberg/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def as_struct(self) -> StructType:
186186
"""Return the schema as a struct."""
187187
return StructType(*self.fields)
188188

189-
def as_arrow(self) -> "pa.Schema":
189+
def as_arrow(self) -> pa.Schema:
190190
"""Return the schema as an Arrow schema."""
191191
from pyiceberg.io.pyarrow import schema_to_pyarrow
192192

pyiceberg/table/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,7 @@ def to_polars(self) -> pl.LazyFrame:
15551555

15561556
return pl.scan_iceberg(self)
15571557

1558-
def __datafusion_table_provider__(self) -> "IcebergDataFusionTable":
1558+
def __datafusion_table_provider__(self) -> IcebergDataFusionTable:
15591559
"""Return the DataFusion table provider PyCapsule interface.
15601560
15611561
To support DataFusion features such as push down filtering, this function will return a PyCapsule

pyiceberg/table/inspect.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _get_snapshot(self, snapshot_id: int | None = None) -> Snapshot:
6060
else:
6161
raise ValueError("Cannot get a snapshot as the table does not have any.")
6262

63-
def snapshots(self) -> "pa.Table":
63+
def snapshots(self) -> pa.Table:
6464
import pyarrow as pa
6565

6666
snapshots_schema = pa.schema(
@@ -98,7 +98,7 @@ def snapshots(self) -> "pa.Table":
9898
schema=snapshots_schema,
9999
)
100100

101-
def entries(self, snapshot_id: int | None = None) -> "pa.Table":
101+
def entries(self, snapshot_id: int | None = None) -> pa.Table:
102102
import pyarrow as pa
103103

104104
from pyiceberg.io.pyarrow import schema_to_pyarrow
@@ -229,7 +229,7 @@ def _readable_metrics_struct(bound_type: PrimitiveType) -> pa.StructType:
229229
schema=entries_schema,
230230
)
231231

232-
def refs(self) -> "pa.Table":
232+
def refs(self) -> pa.Table:
233233
import pyarrow as pa
234234

235235
ref_schema = pa.schema(
@@ -264,7 +264,7 @@ def partitions(
264264
snapshot_id: int | None = None,
265265
row_filter: str | BooleanExpression = ALWAYS_TRUE,
266266
case_sensitive: bool = True,
267-
) -> "pa.Table":
267+
) -> pa.Table:
268268
import pyarrow as pa
269269

270270
from pyiceberg.io.pyarrow import schema_to_pyarrow
@@ -368,7 +368,7 @@ def _update_partitions_map_from_manifest_entry(
368368
else:
369369
raise ValueError(f"Unknown DataFileContent ({file.content})")
370370

371-
def _get_manifests_schema(self) -> "pa.Schema":
371+
def _get_manifests_schema(self) -> pa.Schema:
372372
import pyarrow as pa
373373

374374
partition_summary_schema = pa.struct(
@@ -398,14 +398,14 @@ def _get_manifests_schema(self) -> "pa.Schema":
398398
)
399399
return manifest_schema
400400

401-
def _get_all_manifests_schema(self) -> "pa.Schema":
401+
def _get_all_manifests_schema(self) -> pa.Schema:
402402
import pyarrow as pa
403403

404404
all_manifests_schema = self._get_manifests_schema()
405405
all_manifests_schema = all_manifests_schema.append(pa.field("reference_snapshot_id", pa.int64(), nullable=False))
406406
return all_manifests_schema
407407

408-
def _generate_manifests_table(self, snapshot: Snapshot | None, is_all_manifests_table: bool = False) -> "pa.Table":
408+
def _generate_manifests_table(self, snapshot: Snapshot | None, is_all_manifests_table: bool = False) -> pa.Table:
409409
import pyarrow as pa
410410

411411
def _partition_summaries_to_rows(
@@ -474,10 +474,10 @@ def _partition_summaries_to_rows(
474474
schema=self._get_all_manifests_schema() if is_all_manifests_table else self._get_manifests_schema(),
475475
)
476476

477-
def manifests(self) -> "pa.Table":
477+
def manifests(self) -> pa.Table:
478478
return self._generate_manifests_table(self.tbl.current_snapshot())
479479

480-
def metadata_log_entries(self) -> "pa.Table":
480+
def metadata_log_entries(self) -> pa.Table:
481481
import pyarrow as pa
482482

483483
from pyiceberg.table.snapshots import MetadataLogEntry
@@ -513,7 +513,7 @@ def metadata_log_entry_to_row(metadata_entry: MetadataLogEntry) -> Dict[str, Any
513513
schema=table_schema,
514514
)
515515

516-
def history(self) -> "pa.Table":
516+
def history(self) -> pa.Table:
517517
import pyarrow as pa
518518

519519
history_schema = pa.schema(
@@ -546,7 +546,7 @@ def history(self) -> "pa.Table":
546546

547547
def _get_files_from_manifest(
548548
self, manifest_list: ManifestFile, data_file_filter: Set[DataFileContent] | None = None
549-
) -> "pa.Table":
549+
) -> pa.Table:
550550
import pyarrow as pa
551551

552552
files: list[dict[str, Any]] = []
@@ -610,7 +610,7 @@ def _get_files_from_manifest(
610610
schema=self._get_files_schema(),
611611
)
612612

613-
def _get_files_schema(self) -> "pa.Schema":
613+
def _get_files_schema(self) -> pa.Schema:
614614
import pyarrow as pa
615615

616616
from pyiceberg.io.pyarrow import schema_to_pyarrow
@@ -663,7 +663,7 @@ def _readable_metrics_struct(bound_type: PrimitiveType) -> pa.StructType:
663663
)
664664
return files_schema
665665

666-
def _files(self, snapshot_id: int | None = None, data_file_filter: Set[DataFileContent] | None = None) -> "pa.Table":
666+
def _files(self, snapshot_id: int | None = None, data_file_filter: Set[DataFileContent] | None = None) -> pa.Table:
667667
import pyarrow as pa
668668

669669
if not snapshot_id and not self.tbl.metadata.current_snapshot():
@@ -680,29 +680,29 @@ def _files(self, snapshot_id: int | None = None, data_file_filter: Set[DataFileC
680680
)
681681
return pa.concat_tables(results)
682682

683-
def files(self, snapshot_id: int | None = None) -> "pa.Table":
683+
def files(self, snapshot_id: int | None = None) -> pa.Table:
684684
return self._files(snapshot_id)
685685

686-
def data_files(self, snapshot_id: int | None = None) -> "pa.Table":
686+
def data_files(self, snapshot_id: int | None = None) -> pa.Table:
687687
return self._files(snapshot_id, {DataFileContent.DATA})
688688

689-
def delete_files(self, snapshot_id: int | None = None) -> "pa.Table":
689+
def delete_files(self, snapshot_id: int | None = None) -> pa.Table:
690690
return self._files(snapshot_id, {DataFileContent.POSITION_DELETES, DataFileContent.EQUALITY_DELETES})
691691

692-
def all_manifests(self) -> "pa.Table":
692+
def all_manifests(self) -> pa.Table:
693693
import pyarrow as pa
694694

695695
snapshots = self.tbl.snapshots()
696696
if not snapshots:
697697
return pa.Table.from_pylist([], schema=self._get_all_manifests_schema())
698698

699699
executor = ExecutorFactory.get_or_create()
700-
manifests_by_snapshots: Iterator["pa.Table"] = executor.map(
700+
manifests_by_snapshots: Iterator[pa.Table] = executor.map(
701701
lambda args: self._generate_manifests_table(*args), [(snapshot, True) for snapshot in snapshots]
702702
)
703703
return pa.concat_tables(manifests_by_snapshots)
704704

705-
def _all_files(self, data_file_filter: Set[DataFileContent] | None = None) -> "pa.Table":
705+
def _all_files(self, data_file_filter: Set[DataFileContent] | None = None) -> pa.Table:
706706
import pyarrow as pa
707707

708708
snapshots = self.tbl.snapshots()
@@ -720,11 +720,11 @@ def _all_files(self, data_file_filter: Set[DataFileContent] | None = None) -> "p
720720

721721
return pa.concat_tables(file_lists)
722722

723-
def all_files(self) -> "pa.Table":
723+
def all_files(self) -> pa.Table:
724724
return self._all_files()
725725

726-
def all_data_files(self) -> "pa.Table":
726+
def all_data_files(self) -> pa.Table:
727727
return self._all_files({DataFileContent.DATA})
728728

729-
def all_delete_files(self) -> "pa.Table":
729+
def all_delete_files(self) -> pa.Table:
730730
return self._all_files({DataFileContent.POSITION_DELETES, DataFileContent.EQUALITY_DELETES})

pyiceberg/table/update/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def case_sensitive(self, case_sensitive: bool) -> UpdateSchema:
145145
def union_by_name(
146146
# TODO: Move TableProperties.DEFAULT_FORMAT_VERSION to separate file and set that as format_version default.
147147
self,
148-
new_schema: Schema | "pa.Schema",
148+
new_schema: Schema | pa.Schema,
149149
format_version: TableVersion = 2,
150150
) -> UpdateSchema:
151151
from pyiceberg.catalog import Catalog

pyiceberg/table/update/snapshot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ def by_id(self, snapshot_id: int) -> ExpireSnapshots:
10121012

10131013
return self
10141014

1015-
def by_ids(self, snapshot_ids: List[int]) -> "ExpireSnapshots":
1015+
def by_ids(self, snapshot_ids: List[int]) -> ExpireSnapshots:
10161016
"""
10171017
Expire multiple snapshots by their IDs.
10181018
@@ -1027,7 +1027,7 @@ def by_ids(self, snapshot_ids: List[int]) -> "ExpireSnapshots":
10271027
self.by_id(snapshot_id)
10281028
return self
10291029

1030-
def older_than(self, dt: datetime) -> "ExpireSnapshots":
1030+
def older_than(self, dt: datetime) -> ExpireSnapshots:
10311031
"""
10321032
Expire all unprotected snapshots with a timestamp older than a given value.
10331033

ruff.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ select = [
5959
]
6060
ignore = [
6161
"E501",
62-
"UP037",
6362
"UP035",
6463
"UP006"
6564
]

0 commit comments

Comments
 (0)