Skip to content

Commit 1863ea0

Browse files
remove warning to from_extensions method (#776)
1 parent 362741e commit 1863ea0

File tree

3 files changed

+20
-28
lines changed

3 files changed

+20
-28
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
### Removed
6+
7+
* Remove `warnings` in `CollectionSearchExtension.from_extensions()` methods when passing `unknown` extensions
8+
59
## [3.0.4] - 2025-01-08
610

711
### Removed

stac_fastapi/extensions/stac_fastapi/extensions/core/collection_search/collection_search.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Collection-Search extension."""
22

3-
import warnings
43
from enum import Enum
54
from typing import List, Optional, Union
65

@@ -79,7 +78,7 @@ def from_extensions(
7978
schema_href: Optional[str] = None,
8079
) -> "CollectionSearchExtension":
8180
"""Create CollectionSearchExtension object from extensions."""
82-
supported_extensions = {
81+
known_extension_conformances = {
8382
"FreeTextExtension": ConformanceClasses.FREETEXT,
8483
"FreeTextAdvancedExtension": ConformanceClasses.FREETEXT,
8584
"QueryExtension": ConformanceClasses.QUERY,
@@ -92,13 +91,7 @@ def from_extensions(
9291
ConformanceClasses.BASIS,
9392
]
9493
for ext in extensions:
95-
conf = supported_extensions.get(ext.__class__.__name__, None)
96-
if not conf:
97-
warnings.warn(
98-
f"Conformance class for `{ext.__class__.__name__}` extension not found.", # noqa: E501
99-
UserWarning,
100-
)
101-
else:
94+
if conf := known_extension_conformances.get(ext.__class__.__name__, None):
10295
conformance_classes.append(conf)
10396

10497
get_request_model = create_request_model(
@@ -187,7 +180,7 @@ def from_extensions(
187180
router: Optional[APIRouter] = None,
188181
) -> "CollectionSearchPostExtension":
189182
"""Create CollectionSearchPostExtension object from extensions."""
190-
supported_extensions = {
183+
known_extension_conformances = {
191184
"FreeTextExtension": ConformanceClasses.FREETEXT,
192185
"FreeTextAdvancedExtension": ConformanceClasses.FREETEXT,
193186
"QueryExtension": ConformanceClasses.QUERY,
@@ -200,13 +193,7 @@ def from_extensions(
200193
ConformanceClasses.BASIS,
201194
]
202195
for ext in extensions:
203-
conf = supported_extensions.get(ext.__class__.__name__, None)
204-
if not conf:
205-
warnings.warn(
206-
f"Conformance class for `{ext.__class__.__name__}` extension not found.", # noqa: E501
207-
UserWarning,
208-
)
209-
else:
196+
if conf := known_extension_conformances.get(ext.__class__.__name__, None):
210197
conformance_classes.append(conf)
211198

212199
get_request_model = create_request_model(

stac_fastapi/extensions/tests/test_collection_search.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -476,35 +476,36 @@ def test_from_extensions_methods(extensions):
476476

477477

478478
def test_from_extensions_methods_invalid():
479-
"""Should raise warnings for invalid extensions."""
479+
"""Should also work with unknown extensions."""
480480
extensions = [
481481
AggregationExtension(),
482482
]
483-
with pytest.warns((UserWarning)):
484-
ext = CollectionSearchExtension.from_extensions(
485-
extensions,
486-
)
483+
ext = CollectionSearchExtension.from_extensions(
484+
extensions,
485+
)
486+
487487
collection_search = ext.GET()
488488
assert collection_search.__class__.__name__ == "CollectionsGetRequest"
489489
assert hasattr(collection_search, "bbox")
490490
assert hasattr(collection_search, "datetime")
491491
assert hasattr(collection_search, "limit")
492+
assert hasattr(collection_search, "aggregations")
492493
assert ext.conformance_classes == [
493494
ConformanceClasses.COLLECTIONSEARCH,
494495
ConformanceClasses.BASIS,
495496
]
496497

497-
with pytest.warns((UserWarning)):
498-
ext = CollectionSearchPostExtension.from_extensions(
499-
extensions,
500-
client=DummyPostClient(),
501-
settings=ApiSettings(),
502-
)
498+
ext = CollectionSearchPostExtension.from_extensions(
499+
extensions,
500+
client=DummyPostClient(),
501+
settings=ApiSettings(),
502+
)
503503
collection_search = ext.POST()
504504
assert collection_search.__class__.__name__ == "CollectionsPostRequest"
505505
assert hasattr(collection_search, "bbox")
506506
assert hasattr(collection_search, "datetime")
507507
assert hasattr(collection_search, "limit")
508+
assert hasattr(collection_search, "aggregations")
508509
assert ext.conformance_classes == [
509510
ConformanceClasses.COLLECTIONSEARCH,
510511
ConformanceClasses.BASIS,

0 commit comments

Comments
 (0)