Skip to content

Commit 34c6e33

Browse files
committed
actually get linting passing and bring up to date with new catalog
1 parent 2e28a10 commit 34c6e33

File tree

10 files changed

+23
-24
lines changed

10 files changed

+23
-24
lines changed

pyiceberg/catalog/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@
2222
import re
2323
import uuid
2424
from abc import ABC, abstractmethod
25-
from collections.abc import Callable
25+
from collections.abc import Callable, Iterator
2626
from dataclasses import dataclass
2727
from enum import Enum
2828
from typing import (
2929
TYPE_CHECKING,
3030
Any,
31-
Iterator,
3231
cast,
3332
)
3433

pyiceberg/catalog/bigquery_metastore.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717
import json
18+
from collections.abc import Iterator
1819
from typing import TYPE_CHECKING, Any, Union
1920

2021
from google.api_core.exceptions import NotFound
@@ -244,7 +245,7 @@ def drop_namespace(self, namespace: str | Identifier) -> None:
244245
except NotFound as e:
245246
raise NoSuchNamespaceError(f"Namespace {namespace} does not exist.") from e
246247

247-
def list_tables(self, namespace: str | Identifier) -> list[Identifier]:
248+
def list_tables(self, namespace: str | Identifier) -> Iterator[Identifier]:
248249
database_name = self.identifier_to_database(namespace)
249250
iceberg_tables: list[Identifier] = []
250251
try:
@@ -256,17 +257,17 @@ def list_tables(self, namespace: str | Identifier) -> list[Identifier]:
256257
iceberg_tables.append((database_name, bq_table_list_item.table_id))
257258
except NotFound:
258259
raise NoSuchNamespaceError(f"Namespace (dataset) '{database_name}' not found.") from None
259-
return iceberg_tables
260+
yield from iceberg_tables
260261

261-
def list_namespaces(self, namespace: str | Identifier = ()) -> list[Identifier]:
262+
def list_namespaces(self, namespace: str | Identifier = ()) -> Iterator[Identifier]:
262263
# Since this catalog only supports one-level namespaces, it always returns an empty list unless
263264
# passed an empty namespace to list all namespaces within the catalog.
264265
if namespace:
265266
raise NoSuchNamespaceError(f"Namespace (dataset) '{namespace}' not found.") from None
266267

267268
# List top-level datasets
268269
datasets_iterator = self.client.list_datasets()
269-
return [(dataset.dataset_id,) for dataset in datasets_iterator]
270+
yield from ((dataset.dataset_id,) for dataset in datasets_iterator)
270271

271272
def register_table(self, identifier: str | Identifier, metadata_location: str) -> Table:
272273
"""Register a new table using existing metadata.
@@ -299,7 +300,7 @@ def register_table(self, identifier: str | Identifier, metadata_location: str) -
299300

300301
return self.load_table(identifier=identifier)
301302

302-
def list_views(self, namespace: str | Identifier) -> list[Identifier]:
303+
def list_views(self, namespace: str | Identifier) -> Iterator[Identifier]:
303304
raise NotImplementedError
304305

305306
def drop_view(self, identifier: str | Identifier) -> None:

pyiceberg/catalog/dynamodb.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717
import uuid
18+
from collections.abc import Iterator
1819
from time import time
1920
from typing import (
2021
TYPE_CHECKING,
2122
Any,
22-
Iterator,
2323
Optional,
2424
Union,
2525
)
@@ -438,8 +438,6 @@ def list_tables(self, namespace: str | Identifier) -> Iterator[Identifier]:
438438

439439
yield self.identifier_to_tuple(identifier_col)
440440

441-
return table_identifiers
442-
443441
def list_namespaces(self, namespace: str | Identifier = ()) -> Iterator[Identifier]:
444442
"""List top-level namespaces from the catalog.
445443

pyiceberg/catalog/glue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
# under the License.
1717

1818

19+
from collections.abc import Iterator
1920
from typing import (
2021
TYPE_CHECKING,
2122
Any,
22-
Iterator,
2323
Optional,
2424
Union,
2525
cast,

pyiceberg/catalog/hive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
import logging
1919
import socket
2020
import time
21+
from collections.abc import Iterator
2122
from types import TracebackType
2223
from typing import (
2324
TYPE_CHECKING,
2425
Any,
25-
Iterator,
2626
Union,
2727
)
2828
from urllib.parse import urlparse

pyiceberg/catalog/noop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17+
from collections.abc import Iterator
1718
from typing import (
1819
TYPE_CHECKING,
19-
Iterator,
2020
Union,
2121
)
2222

pyiceberg/catalog/rest/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17+
from collections.abc import Iterator
1718
from enum import Enum
1819
from typing import (
1920
TYPE_CHECKING,
2021
Any,
21-
Iterator,
2222
Union,
2323
)
2424

@@ -599,7 +599,7 @@ def register_table(self, identifier: str | Identifier, metadata_location: str) -
599599
return self._response_to_table(self.identifier_to_tuple(identifier), table_response)
600600

601601
@retry(**_RETRY_ARGS)
602-
def list_tables(self, namespace: str | Identifier) -> list[Identifier]:
602+
def _fetch_tables(self, namespace: str | Identifier) -> list[Identifier]:
603603
namespace_tuple = self._check_valid_namespace_identifier(namespace)
604604
namespace_concat = NAMESPACE_SEPARATOR.join(namespace_tuple)
605605
response = self._session.get(self.url(Endpoints.list_tables, namespace=namespace_concat))
@@ -609,7 +609,7 @@ def list_tables(self, namespace: str | Identifier) -> list[Identifier]:
609609
_handle_non_200_response(exc, {404: NoSuchNamespaceError})
610610
return [(*table.namespace, table.name) for table in ListTablesResponse.model_validate_json(response.text).identifiers]
611611

612-
def list_tables(self, namespace: Union[str, Identifier]) -> Iterator[Identifier]:
612+
def list_tables(self, namespace: str | Identifier) -> Iterator[Identifier]:
613613
"""List tables, returning an iterator to handle retry logic properly."""
614614
tables = self._fetch_tables(namespace)
615615
yield from tables
@@ -685,7 +685,7 @@ def _remove_catalog_name_from_table_request_identifier(self, table_request: Comm
685685
return table_request
686686

687687
@retry(**_RETRY_ARGS)
688-
def list_views(self, namespace: str | Identifier) -> list[Identifier]:
688+
def _fetch_views(self, namespace: str | Identifier) -> list[Identifier]:
689689
namespace_tuple = self._check_valid_namespace_identifier(namespace)
690690
namespace_concat = NAMESPACE_SEPARATOR.join(namespace_tuple)
691691
response = self._session.get(self.url(Endpoints.list_views, namespace=namespace_concat))
@@ -695,7 +695,7 @@ def list_views(self, namespace: str | Identifier) -> list[Identifier]:
695695
_handle_non_200_response(exc, {404: NoSuchNamespaceError})
696696
return [(*view.namespace, view.name) for view in ListViewsResponse.model_validate_json(response.text).identifiers]
697697

698-
def list_views(self, namespace: Union[str, Identifier]) -> Iterator[Identifier]:
698+
def list_views(self, namespace: str | Identifier) -> Iterator[Identifier]:
699699
"""List views, returning an iterator to handle retry logic properly."""
700700
yield from self._fetch_views(namespace)
701701

@@ -766,7 +766,7 @@ def drop_namespace(self, namespace: str | Identifier) -> None:
766766
_handle_non_200_response(exc, {404: NoSuchNamespaceError, 409: NamespaceNotEmptyError})
767767

768768
@retry(**_RETRY_ARGS)
769-
def list_namespaces(self, namespace: str | Identifier = ()) -> list[Identifier]:
769+
def _fetch_namespaces(self, namespace: str | Identifier) -> list[Identifier]:
770770
namespace_tuple = self.identifier_to_tuple(namespace)
771771
response = self._session.get(
772772
self.url(
@@ -782,7 +782,7 @@ def list_namespaces(self, namespace: str | Identifier = ()) -> list[Identifier]:
782782

783783
return ListNamespaceResponse.model_validate_json(response.text).namespaces
784784

785-
def list_namespaces(self, namespace: Union[str, Identifier] = ()) -> Iterator[Identifier]:
785+
def list_namespaces(self, namespace: str | Identifier = ()) -> Iterator[Identifier]:
786786
"""List namespaces, returning an iterator to handle retry logic properly."""
787787
yield from self._fetch_namespaces(namespace)
788788

pyiceberg/catalog/sql.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
from collections.abc import Iterator
1819
from typing import (
1920
TYPE_CHECKING,
20-
Iterator,
2121
Union,
2222
)
2323

@@ -601,6 +601,7 @@ def list_tables(self, namespace: str | Identifier) -> Iterator[Identifier]:
601601
with Session(self.engine) as session:
602602
result = session.scalars(stmt)
603603
identifiers = [(Catalog.identifier_to_tuple(table.table_namespace) + (table.table_name,)) for table in result]
604+
yield from identifiers
604605

605606
def list_namespaces(self, namespace: str | Identifier = ()) -> Iterator[Identifier]:
606607
"""List namespaces from the given namespace. If not given, list top-level namespaces from the catalog.

pyiceberg/cli/output.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
# under the License.
1717
import json
1818
from abc import ABC, abstractmethod
19+
from collections.abc import Iterator
1920
from typing import (
20-
Iterator,
2121
Any,
2222
)
2323
from uuid import UUID

tests/integration/test_catalog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def test_list_tables(test_catalog: Catalog, table_schema_nested: Schema, databas
176176
for table_name in table_list:
177177
test_catalog.create_table((database_name, table_name), table_schema_nested)
178178
identifier_list = test_catalog.list_tables(database_name)
179-
assert len(identifier_list) == len(table_list)
179+
assert len(list(identifier_list)) == len(table_list)
180180
for table_name in table_list:
181181
assert (database_name, table_name) in identifier_list
182182

@@ -449,7 +449,7 @@ def test_list_namespaces(test_catalog: Catalog, database_list: list[str]) -> Non
449449
db_list = test_catalog.list_namespaces()
450450
for database_name in database_list:
451451
assert (database_name,) in db_list
452-
assert len(test_catalog.list_namespaces(list(database_list)[0])) == 0
452+
assert len(list(test_catalog.list_namespaces(list(database_list)[0]))) == 0
453453

454454

455455
@pytest.mark.integration

0 commit comments

Comments
 (0)