From 756150d28ea5fc3d5f64ad1ee5bc63f5ee8e23a8 Mon Sep 17 00:00:00 2001 From: Xavier Olive Date: Wed, 10 Jan 2024 22:02:46 +0100 Subject: [PATCH] fix mypy --- src/traffic/core/mixins.py | 9 +++++---- src/traffic/core/structure.py | 23 +++++++++++------------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/traffic/core/mixins.py b/src/traffic/core/mixins.py index cc923993..275578c6 100644 --- a/src/traffic/core/mixins.py +++ b/src/traffic/core/mixins.py @@ -424,7 +424,9 @@ def geojson(self) -> dict[str, Any] | list[dict[str, Any]]: """ return mapping(self.shape) # type: ignore - def geoencode(self, **kwargs: Any) -> "alt.Chart": # coverage: ignore + def geoencode( + self, **kwargs: Any + ) -> "alt.LayerChart | alt.Chart": # coverage: ignore """Returns an `altair `_ encoding of the shape to be composed in an interactive visualization. Specific plot features, such as line widths, can be passed with the kwargs argument. @@ -433,9 +435,8 @@ def geoencode(self, **kwargs: Any) -> "alt.Chart": # coverage: ignore """ import altair as alt - return alt.Chart( - alt.Data(values=self.geojson()) # type: ignore - ).mark_geoshape(stroke="#aaaaaa", **kwargs) + data = alt.Data(values=self.geojson()) # type: ignore + return alt.Chart(data).mark_geoshape(stroke="#aaaaaa", **kwargs) def project_shape( self, projection: None | pyproj.Proj | "crs.Projection" = None diff --git a/src/traffic/core/structure.py b/src/traffic/core/structure.py index b384a33d..0bbce282 100644 --- a/src/traffic/core/structure.py +++ b/src/traffic/core/structure.py @@ -184,18 +184,19 @@ def runways(self) -> Optional[RunwayAirport]: return runways[self] - def geoencode( # type: ignore + def geoencode( self, - footprint: Union[bool, Dict[str, Any]] = True, - runways: Union[bool, Dict[str, Any]] = True, - labels: Union[bool, Dict[str, Any]] = True, - ) -> "alt.Chart": # coverage: ignore + footprint: Union[bool, Dict[str, Dict[str, Any]]] = True, + runways: Union[bool, Dict[str, Dict[str, Any]]] = True, + labels: Union[bool, Dict[str, Dict[str, Any]]] = True, + **kwargs: Any, + ) -> "alt.LayerChart": # coverage: ignore import altair as alt base = alt.Chart(self).mark_geoshape() cumul = [] if footprint: - params = dict( + params: Dict[str, Dict[str, Any]] = dict( aerodrome=dict(color="gainsboro", opacity=0.5), apron=dict(color="darkgray", opacity=0.5), terminal=dict(color="#888888"), @@ -203,13 +204,11 @@ def geoencode( # type: ignore taxiway=dict(filled=False, color="silver", strokeWidth=1.5), ) if isinstance(footprint, dict): - footprint = {**params, **footprint} - else: - footprint = params + params = {**params, **footprint} - for key, value in footprint.items(): + for key, value in params.items(): cumul.append( - base.transform_filter( # type: ignore + base.transform_filter( f"datum.aeroway == '{key}'" ).mark_geoshape(**value) ) @@ -227,7 +226,7 @@ def geoencode( # type: ignore raise TypeError( "At least one of footprint, runways and labels must be True" ) - return alt.layer(*cumul) # type: ignore + return alt.layer(*cumul) def plot( # type: ignore self,