Skip to content

Commit

Permalink
Make usage of singledispatch more concise
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasschaub committed Mar 14, 2022
1 parent 5a9c310 commit 1e89d10
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 24 deletions.
7 changes: 2 additions & 5 deletions workers/ohsome_quality_analyst/ohsome/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
)
Expand All @@ -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

Expand Down
25 changes: 6 additions & 19 deletions workers/ohsome_quality_analyst/oqt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
)
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -244,18 +237,15 @@ 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))
)


@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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 1e89d10

Please sign in to comment.