From 5cee2d4676a63a20a2379a21c88892923747e967 Mon Sep 17 00:00:00 2001 From: Jack Greenlee Date: Wed, 23 Oct 2024 17:46:41 -0400 Subject: [PATCH] use `'key' in dict` rather than dict.get('key') for JS compatibility This fails in JS because `properties` is a JS object, not a dict, and JS objects don't have 'get'. We get around this by using `in`. It's not as elegant but it's foolproof --- src/emcommon/metrics/footprint/util.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/emcommon/metrics/footprint/util.py b/src/emcommon/metrics/footprint/util.py index 049068d..29571e8 100644 --- a/src/emcommon/metrics/footprint/util.py +++ b/src/emcommon/metrics/footprint/util.py @@ -101,10 +101,10 @@ async def get_egrid_region(coords: list[float, float], year: int) -> str | None: return None region_feature = get_feature_containing_point(coords, geojson) if region_feature is not None: - properties = region_feature['properties'] - region_name = properties.get('name') or properties.get('SUBRGN') - if region_name: - return region_name + if 'name' in region_feature['properties']: + return region_feature['properties']['name'] + if 'SUBRGN' in region_feature['properties']: + return region_feature['properties']['SUBRGN'] Log.warn(f"An eGRID region was not found for coords {coords} in year {year}.") return None