Skip to content

Commit

Permalink
use 'key' in dict rather than dict.get('key') for JS compatibility
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JGreenlee committed Oct 23, 2024
1 parent 0fd4dd0 commit 5cee2d4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/emcommon/metrics/footprint/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5cee2d4

Please sign in to comment.