From 1e89d1041b55dfd10eeb86ccd6bb1cc4dfc9026d Mon Sep 17 00:00:00 2001 From: Matthias Schaub Date: Sun, 13 Mar 2022 12:25:07 +0100 Subject: [PATCH] Make usage of singledispatch more concise --- .../ohsome_quality_analyst/ohsome/client.py | 7 ++---- workers/ohsome_quality_analyst/oqt.py | 25 +++++-------------- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/workers/ohsome_quality_analyst/ohsome/client.py b/workers/ohsome_quality_analyst/ohsome/client.py index 84a32b95f..f5ebe0ee7 100644 --- a/workers/ohsome_quality_analyst/ohsome/client.py +++ b/workers/ohsome_quality_analyst/ohsome/client.py @@ -23,11 +23,7 @@ @singledispatch -async def query( - layer, - *args, - **kargs, -) -> dict: +async def query(layer) -> dict: raise NotImplementedError( "Cannot query ohsome API for Layer of type: " + str(type(layer)) ) @@ -54,6 +50,7 @@ async def _query( return await query_ohsome_api(url, data) +@query.register async def _query(layer: LayerData, *_args, **_kargs) -> dict: # noqa return layer.data diff --git a/workers/ohsome_quality_analyst/oqt.py b/workers/ohsome_quality_analyst/oqt.py index 8147edb3a..c6981302b 100644 --- a/workers/ohsome_quality_analyst/oqt.py +++ b/workers/ohsome_quality_analyst/oqt.py @@ -122,8 +122,7 @@ async def create_report_as_geojson( @singledispatch -async def create_indicator(parameters, force: bool = False) -> Indicator: - """Create an Indicator.""" +async def create_indicator(parameters) -> Indicator: raise NotImplementedError( "Cannot create Indicator for parameters of type: " + str(type(parameters)) ) @@ -187,10 +186,7 @@ async def _create_indicator( @create_indicator.register -async def _create_indicator( # noqa - parameters: IndicatorBpolys, - force: bool = False, -) -> Indicator: +async def _create_indicator(parameters: IndicatorBpolys, *_args) -> Indicator: # noqa """Create an indicator from scratch.""" name = parameters.name.value layer: Layer = from_dict( @@ -217,10 +213,7 @@ async def _create_indicator( # noqa @create_indicator.register -async def _create_indicator( # noqa - parameters: IndicatorData, - force: bool = False, -) -> Indicator: +async def _create_indicator(parameters: IndicatorData, *_args) -> Indicator: # noqa """Create an indicator from scratch.""" name = parameters.name.value layer = parameters.layer @@ -244,7 +237,7 @@ async def _create_indicator( # noqa @singledispatch -async def create_report(parameters, force: bool = False) -> Report: +async def create_report(parameters) -> Report: """Create a Report.""" raise NotImplementedError( "Cannot create Report for parameters of type: " + str(type(parameters)) @@ -252,10 +245,7 @@ async def create_report(parameters, force: bool = False) -> Report: @create_report.register -async def _create_report( - parameters: ReportDatabase, - force: bool = False, -) -> Report: +async def _create_report(parameters: ReportDatabase, force: bool = False) -> Report: """Create a Report. Fetches indicator results form the database. @@ -298,10 +288,7 @@ async def _create_report( @create_report.register -async def _create_report( # noqa - parameters: ReportBpolys, - force: bool = False, -) -> Report: +async def _create_report(parameters: ReportBpolys, *_args) -> Report: # noqa """Create a Report. Create indicators from scratch.