Skip to content

Commit 27616b5

Browse files
PB-2354 Refactor to reduce conditional branches
This avoids pylints warning "too-many-branches"
1 parent 85aa576 commit 27616b5

1 file changed

Lines changed: 14 additions & 18 deletions

File tree

app/stac_api/utils.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -314,26 +314,22 @@ def harmonize_post_get_for_search(request):
314314
if 'intersects' in query_param:
315315
query_param['intersects'] = json.loads(query_param['intersects'])
316316

317-
# Forecast properties can only be filtered with method POST.
317+
# Forecast and CF extension properties can only be filtered with method POST.
318318
# Decision was made as `:` need to be url encoded and (at least for now) we do not need to
319319
# support forecast filtering in the GET request.
320-
if 'forecast:reference_datetime' in query_param:
321-
del query_param['forecast:reference_datetime']
322-
if 'forecast:horizon' in query_param:
323-
del query_param['forecast:horizon']
324-
if 'forecast:duration' in query_param:
325-
del query_param['forecast:duration']
326-
if 'forecast:variable' in query_param:
327-
del query_param['forecast:variable']
328-
if 'forecast:perturbed' in query_param:
329-
del query_param['forecast:perturbed']
330-
# CF extension properties can only be filtered with method POST.
331-
# Decision was made as `:` need to be url encoded and (at least for now) we do not need to
332-
# support CF filtering in the GET request.
333-
if 'cf:standard_name' in query_param:
334-
del query_param['cf:standard_name']
335-
if 'unit' in query_param:
336-
del query_param['unit']
320+
forecast_properties = [
321+
'forecast:reference_datetime',
322+
'forecast:horizon',
323+
'forecast:duration',
324+
'forecast:variable',
325+
'forecast:perturbed'
326+
]
327+
cf_properties = ['cf:standard_name', 'unit']
328+
properties_to_remove = forecast_properties + cf_properties
329+
for p in properties_to_remove:
330+
if p in query_param:
331+
del query_param[p]
332+
337333
return query_param
338334

339335

0 commit comments

Comments
 (0)