Skip to content

Commit 906a0a0

Browse files
authored
fix: object store typing (#143)
1 parent 0656a5f commit 906a0a0

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ ignore_missing_imports = true
4444
asyncio_mode = "auto"
4545
asyncio_default_fixture_loop_scope = "function"
4646
testpaths = ["tests"]
47+
filterwarnings = ["error"]
4748

4849
[tool.ruff]
4950
exclude = [

python/rustac/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,7 @@ class ItemCollection(TypedDict):
252252
__doc__ = rustac.__doc__
253253
if hasattr(rustac, "__all__"):
254254
__all__ = rustac.__all__
255+
else:
256+
__all__ = []
257+
258+
__all__.append("store")

python/rustac/rustac.pyi

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ from pathlib import Path
55
from typing import Any, Literal
66

77
import arro3.core
8+
from obstore.store import ObjectStore as ObstoreObjectStore
89

910
from rustac import Catalog, Collection, Item, ItemCollection
1011
from rustac.store import ObjectStore
1112

13+
AnyObjectStore = ObjectStore | ObstoreObjectStore
14+
1215
class RustacError(Exception):
1316
"""A package-specific exception."""
1417

@@ -212,7 +215,7 @@ async def read(
212215
href: str,
213216
*,
214217
format: str | None = None,
215-
store: ObjectStore | None = None,
218+
store: AnyObjectStore | None = None,
216219
set_self_link: bool = True,
217220
) -> dict[str, Any]:
218221
"""
@@ -347,7 +350,7 @@ async def search_to(
347350
filter: str | dict[str, Any] | None = None,
348351
query: dict[str, Any] | None = None,
349352
format: str | None = None,
350-
store: ObjectStore | None = None,
353+
store: AnyObjectStore | None = None,
351354
use_duckdb: bool | None = None,
352355
) -> int:
353356
"""
@@ -425,7 +428,7 @@ async def write(
425428
value: dict[str, Any] | Sequence[dict[str, Any]],
426429
*,
427430
format: str | None = None,
428-
store: ObjectStore | None = None,
431+
store: AnyObjectStore | None = None,
429432
) -> dict[str, str] | None:
430433
"""
431434
Writes STAC to a href.

tests/test_read.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from pathlib import Path
22
from typing import Any
33

4+
import pytest
45
import rustac
6+
from obstore.store import LocalStore as ObstoreLocalStore
57
from pystac import Item
68
from rustac.store import LocalStore
79

@@ -33,3 +35,12 @@ async def test_read_proj_geometry(
3335
async def test_read_store(examples: Path) -> None:
3436
store = LocalStore(prefix=str(examples))
3537
await rustac.read("simple-item.json", store=store)
38+
39+
40+
async def test_read_external_store(examples: Path) -> None:
41+
store = ObstoreLocalStore(prefix=str(examples))
42+
with pytest.warns(
43+
RuntimeWarning,
44+
match="Successfully reconstructed a store defined in another Python module. Connection pooling will not be shared across store instances.",
45+
):
46+
await rustac.read("simple-item.json", store=store)

0 commit comments

Comments
 (0)