Skip to content

Commit

Permalink
Python: Add pyupgrade as a pre-commit hook (apache#4935)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fokko authored Jun 5, 2022
1 parent 75fb871 commit cee5f75
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 100 deletions.
5 changes: 5 additions & 0 deletions python/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,8 @@ repos:
hooks:
- id: pycln
args: [--config=python/pyproject.toml]
- repo: https://github.com/asottile/pyupgrade
rev: v2.32.1
hooks:
- id: pyupgrade
args: [--py38-plus]
40 changes: 17 additions & 23 deletions python/src/iceberg/catalog/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@
from __future__ import annotations

from abc import ABC, abstractmethod
from typing import (
List,
Optional,
Set,
Union,
)

from iceberg.catalog import Identifier, Properties
from iceberg.schema import Schema
Expand Down Expand Up @@ -59,11 +53,11 @@ def properties(self) -> Properties:
@abstractmethod
def create_table(
self,
identifier: Union[str, Identifier],
identifier: str | Identifier,
schema: Schema,
location: Optional[str] = None,
partition_spec: Optional[PartitionSpec] = None,
properties: Optional[Properties] = None,
location: str | None = None,
partition_spec: PartitionSpec | None = None,
properties: Properties | None = None,
) -> Table:
"""Create a table
Expand All @@ -82,7 +76,7 @@ def create_table(
"""

@abstractmethod
def load_table(self, identifier: Union[str, Identifier]) -> Table:
def load_table(self, identifier: str | Identifier) -> Table:
"""Loads the table's metadata and returns the table instance.
You can also use this method to check for table existence using 'try catalog.table() except TableNotFoundError'
Expand All @@ -99,7 +93,7 @@ def load_table(self, identifier: Union[str, Identifier]) -> Table:
"""

@abstractmethod
def drop_table(self, identifier: Union[str, Identifier]) -> None:
def drop_table(self, identifier: str | Identifier) -> None:
"""Drop a table.
Args:
Expand All @@ -110,7 +104,7 @@ def drop_table(self, identifier: Union[str, Identifier]) -> None:
"""

@abstractmethod
def purge_table(self, identifier: Union[str, Identifier]) -> None:
def purge_table(self, identifier: str | Identifier) -> None:
"""Drop a table and purge all data and metadata files.
Args:
Expand All @@ -121,7 +115,7 @@ def purge_table(self, identifier: Union[str, Identifier]) -> None:
"""

@abstractmethod
def rename_table(self, from_identifier: Union[str, Identifier], to_identifier: Union[str, Identifier]) -> Table:
def rename_table(self, from_identifier: str | Identifier, to_identifier: str | Identifier) -> Table:
"""Rename a fully classified table name
Args:
Expand All @@ -136,7 +130,7 @@ def rename_table(self, from_identifier: Union[str, Identifier], to_identifier: U
"""

@abstractmethod
def create_namespace(self, namespace: Union[str, Identifier], properties: Optional[Properties] = None) -> None:
def create_namespace(self, namespace: str | Identifier, properties: Properties | None = None) -> None:
"""Create a namespace in the catalog.
Args:
Expand All @@ -148,7 +142,7 @@ def create_namespace(self, namespace: Union[str, Identifier], properties: Option
"""

@abstractmethod
def drop_namespace(self, namespace: Union[str, Identifier]) -> None:
def drop_namespace(self, namespace: str | Identifier) -> None:
"""Drop a namespace.
Args:
Expand All @@ -160,7 +154,7 @@ def drop_namespace(self, namespace: Union[str, Identifier]) -> None:
"""

@abstractmethod
def list_tables(self, namespace: Optional[Union[str, Identifier]] = None) -> List[Identifier]:
def list_tables(self, namespace: str | Identifier | None = None) -> list[Identifier]:
"""List tables under the given namespace in the catalog.
If namespace not provided, will list all tables in the catalog.
Expand All @@ -176,15 +170,15 @@ def list_tables(self, namespace: Optional[Union[str, Identifier]] = None) -> Lis
"""

@abstractmethod
def list_namespaces(self) -> List[Identifier]:
def list_namespaces(self) -> list[Identifier]:
"""List namespaces from the given namespace. If not given, list top-level namespaces from the catalog.
Returns:
List[Identifier]: a List of namespace identifiers
"""

@abstractmethod
def load_namespace_properties(self, namespace: Union[str, Identifier]) -> Properties:
def load_namespace_properties(self, namespace: str | Identifier) -> Properties:
"""Get properties for a namespace.
Args:
Expand All @@ -199,7 +193,7 @@ def load_namespace_properties(self, namespace: Union[str, Identifier]) -> Proper

@abstractmethod
def update_namespace_properties(
self, namespace: Union[str, Identifier], removals: Optional[Set[str]] = None, updates: Optional[Properties] = None
self, namespace: str | Identifier, removals: set[str] | None = None, updates: Properties | None = None
) -> None:
"""Removes provided property keys and updates properties for a namespace.
Expand All @@ -214,7 +208,7 @@ def update_namespace_properties(
"""

@staticmethod
def identifier_to_tuple(identifier: Union[str, Identifier]) -> Identifier:
def identifier_to_tuple(identifier: str | Identifier) -> Identifier:
"""Parses an identifier to a tuple.
If the identifier is a string, it is split into a tuple on '.'. If it is a tuple, it is used as-is.
Expand All @@ -228,7 +222,7 @@ def identifier_to_tuple(identifier: Union[str, Identifier]) -> Identifier:
return identifier if isinstance(identifier, tuple) else tuple(str.split(identifier, "."))

@staticmethod
def table_name_from(identifier: Union[str, Identifier]) -> str:
def table_name_from(identifier: str | Identifier) -> str:
"""Extracts table name from a table identifier
Args:
Expand All @@ -240,7 +234,7 @@ def table_name_from(identifier: Union[str, Identifier]) -> str:
return Catalog.identifier_to_tuple(identifier)[-1]

@staticmethod
def namespace_from(identifier: Union[str, Identifier]) -> Identifier:
def namespace_from(identifier: str | Identifier) -> Identifier:
"""Extracts table namespace from a table identifier
Args:
Expand Down
Loading

0 comments on commit cee5f75

Please sign in to comment.