Created
September 27, 2021 13:55
-
-
Save jakubczaplicki/369f85c34117e5b7e7a8ec40f41fb1d8 to your computer and use it in GitHub Desktop.
Python singledispatch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from functools import singledispatch | |
from utils.data.data_point import DataPoint | |
@singledispatch | |
def extract_data(item, **kwargs): | |
return None # unknown type | |
@extract_data.register(dict) | |
def _(item): | |
return { | |
"lat": float(item["latitude"]), | |
"lng": float(item["longitude"]), | |
} | |
@extract_data.register(DataPoint) | |
def _(item: DataPoint): | |
return { | |
"lat": item.latitude, | |
"lng": item.longitude, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment